Esempio n. 1
0
  public static void setupLighting() {
    FloatBuffer lightPosition = BufferUtils.createFloatBuffer(4);
    lightPosition.put(0.0f).put(0.0f).put(0.0f).put(0.0f).flip();

    FloatBuffer whiteLight = BufferUtils.createFloatBuffer(4);
    whiteLight.put(1.0f).put(1.0f).put(1.0f).put(1.0f).flip();

    FloatBuffer lModelAmbient = BufferUtils.createFloatBuffer(4);
    lModelAmbient.put(0.4f).put(0.4f).put(0.4f).put(1.0f).flip();

    glShadeModel(GL_SMOOTH);
    glMaterial(GL_FRONT, GL_SPECULAR, whiteLight);
    glMaterialf(GL_FRONT, GL_SHININESS, 50.0f);

    glLight(GL_LIGHT0, GL_POSITION, lightPosition);
    glLight(GL_LIGHT0, GL_SPECULAR, whiteLight);
    glLight(GL_LIGHT0, GL_DIFFUSE, whiteLight);
    glLightModel(GL_LIGHT_MODEL_AMBIENT, lModelAmbient);

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);

    glEnable(GL_COLOR_MATERIAL);
    glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
  }
Esempio n. 2
0
  public static void floor() {
    glBindTexture(GL_TEXTURE_2D, Main.tex_floor);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    FloatBuffer color = BufferUtils.createFloatBuffer(4);
    color.put(1).put(0.8f).put(0.6f).put(1).flip();
    glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color);
    color = BufferUtils.createFloatBuffer(4);
    color.put(0).put(0).put(0).put(1).flip();
    glMaterial(GL_FRONT, GL_SPECULAR, color);
    glBegin(GL_QUADS);
    glNormal3f(0, 1, 0);
    for (int a = ZA_FLOOR_START; a < ZA_FLOOR_END; a += ZA_FLOOR_RES) {
      for (int b = ZA_FLOOR_START; b < ZA_FLOOR_END; b += ZA_FLOOR_RES) {
        glTexCoord2f(0, 0);
        glVertex3f(a, 0, b);
        glTexCoord2f(0, 1);
        glVertex3f(a, 0, b + ZA_FLOOR_RES);
        glTexCoord2f(1, 1);
        glVertex3f(a + ZA_FLOOR_RES, 0, b + ZA_FLOOR_RES);
        glTexCoord2f(1, 0);
        glVertex3f(a + ZA_FLOOR_RES, 0, b);
      }
    }
    glEnd();

    glBindTexture(GL_TEXTURE_2D, ResourceLoader.white);
    color = BufferUtils.createFloatBuffer(4);
    color.put(1).put(0.8f).put(0.6f).put(1).flip();
    glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, color);
  }
Esempio n. 3
0
  private int createTubeVbo(int tube, Color color) {

    float[] c =
        new float[] {color.getBlue() / 255f, color.getGreen() / 255f, color.getRed() / 255f};

    totalNumVerts[tube] = tubes[tube].indeces.length;

    IntBuffer buf = BufferUtils.createIntBuffer(1);
    GL15.glGenBuffers(buf);
    int vbo = buf.get();

    FloatBuffer data = BufferUtils.createFloatBuffer(tubes[tube].indeces.length * 9);

    for (int i = 0; i < tubes[tube].indeces.length; i++) {
      data.put(c);

      Vector3D vertex = tubes[tube].vertices[tubes[tube].indeces[i]];
      Vector3D normal = tubes[tube].normals[tubes[tube].indeces[i]];

      float[] vertexf = new float[] {vertex.x, vertex.y, vertex.z};
      float[] normalf = new float[] {normal.x, normal.y, normal.z};

      data.put(vertexf);
      data.put(normalf);
    }
    data.rewind();

    int bytesPerFloat = Float.SIZE / Byte.SIZE;
    int numBytes = data.capacity() * bytesPerFloat;
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vbo);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, data, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    return vbo;
  }
Esempio n. 4
0
  /* Generate a Triangle mesh that represents this Box. */
  private void buildMesh() {
    // Create the OBJMesh
    MeshData box = new MeshData();

    box.vertexCount = 8;
    box.indexCount = 36;

    // Add positions
    box.positions = BufferUtils.createFloatBuffer(box.vertexCount * 3);
    box.positions.put(
        new float[] {
          (float) minPt.x, (float) minPt.y, (float) minPt.z,
          (float) minPt.x, (float) maxPt.y, (float) minPt.z,
          (float) maxPt.x, (float) maxPt.y, (float) minPt.z,
          (float) maxPt.x, (float) minPt.y, (float) minPt.z,
          (float) minPt.x, (float) minPt.y, (float) maxPt.z,
          (float) minPt.x, (float) maxPt.y, (float) maxPt.z,
          (float) maxPt.x, (float) maxPt.y, (float) maxPt.z,
          (float) maxPt.x, (float) minPt.y, (float) maxPt.z
        });

    box.indices = BufferUtils.createIntBuffer(box.indexCount);
    box.indices.put(
        new int[] {
          0, 1, 2, 0, 2, 3, 0, 5, 1, 0, 4, 5, 0, 7, 4, 0, 3, 7, 4, 6, 5, 4, 7, 6, 2, 5, 6, 2, 1, 5,
          2, 6, 7, 2, 7, 3
        });
    this.mesh = new Mesh(box);

    // set transformations and absorptioins
    this.mesh.setTransformation(this.tMat, this.tMatInv, this.tMatTInv);

    this.mesh.shader = this.shader;
  }
Esempio n. 5
0
  public void RebuildMesh(float startX, float startY, float startZ) {

    VBOColorHandle = GL15.glGenBuffers();
    VBOVertexHandle = GL15.glGenBuffers();

    // Using 6 * 4 * 3 because 6 faces * 4 pts per face * 3 coords per point
    FloatBuffer VertexPositionData =
        BufferUtils.createFloatBuffer((CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE) * 6 * 4 * 3);
    FloatBuffer VertexColorData =
        BufferUtils.createFloatBuffer((CHUNK_SIZE * CHUNK_SIZE * CHUNK_SIZE) * 6 * 4 * 3);

    for (float x = 0; x < CHUNK_SIZE; x += 1) {
      for (float y = 0; y < CHUNK_SIZE; y += 1) {
        for (float z = 0; z < CHUNK_SIZE; z += 1) {

          VertexPositionData.put(
              CreateCube(
                  (float) startX + x * CUBE_LENGTH,
                  (float) startY + y * CUBE_LENGTH,
                  (float) startZ + z * CUBE_LENGTH));
          VertexColorData.put(CreateCubeVertexCol(GetCubeColor(Blocks[(int) x][(int) y][(int) z])));
        }
      }
    }

    VertexColorData.flip();
    VertexPositionData.flip();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOVertexHandle);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, VertexPositionData, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBOColorHandle);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, VertexColorData, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
  }
Esempio n. 6
0
  /**
   * Render the GL scene, this isn't efficient and if you know OpenGL I'm assuming you can see why.
   * If not, you probably don't want to use this feature anyway
   */
  public void renderGL() {
    FloatBuffer pos = BufferUtils.createFloatBuffer(4);
    pos.put(new float[] {5.0f, 5.0f, 10.0f, 0.0f}).flip();
    FloatBuffer red = BufferUtils.createFloatBuffer(4);
    red.put(new float[] {0.8f, 0.1f, 0.0f, 1.0f}).flip();

    GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, pos);
    GL11.glEnable(GL11.GL_LIGHT0);

    GL11.glEnable(GL11.GL_CULL_FACE);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glEnable(GL11.GL_LIGHTING);

    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    float h = (float) 600 / (float) 800;
    GL11.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    GL11.glLoadIdentity();
    GL11.glTranslatef(0.0f, 0.0f, -40.0f);
    GL11.glRotatef(rot, 0, 1, 1);

    GL11.glMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT_AND_DIFFUSE, red);
    gear(0.5f, 2.0f, 2.0f, 10, 0.7f);
  }
Esempio n. 7
0
  @SuppressWarnings("OverridableMethodCallInConstructor")
  public LWJGLRenderer() throws LWJGLException {
    this.ib16 = BufferUtils.createIntBuffer(16);
    this.textureAreas = new ArrayList<TextureArea>();
    this.rotatedTextureAreas = new ArrayList<TextureAreaRotated>();
    this.dynamicImages = new ArrayList<LWJGLDynamicImage>();
    this.tintStateRoot = new TintStack();
    this.tintStack = tintStateRoot;
    this.clipStack = new ClipStack();
    this.clipRectTemp = new Rect();
    syncViewportSize();

    GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE, ib16);
    maxTextureSize = ib16.get(0);

    if (Mouse.isCreated()) {
      int minCursorSize = Cursor.getMinCursorSize();
      IntBuffer tmp = BufferUtils.createIntBuffer(minCursorSize * minCursorSize);
      emptyCursor =
          new Cursor(
              minCursorSize, minCursorSize, minCursorSize / 2, minCursorSize / 2, 1, tmp, null);
    } else {
      emptyCursor = null;
    }

    swCursorAnimState = new SWCursorAnimState();
  }
Esempio n. 8
0
  public Mesh(float[] vertices, int[] indices) {

    this.vertices = vertices;
    this.indices = indices;

    vbo = glGenBuffers();
    ibo = glGenBuffers();

    FloatBuffer fb = BufferUtils.createFloatBuffer(vertices.length);
    fb.put(vertices);
    fb.flip();

    IntBuffer ib = BufferUtils.createIntBuffer(indices.length);
    ib.put(indices);
    ib.flip();

    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, fb, GL_STATIC_DRAW);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, ib, GL_STATIC_DRAW);

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  }
  public void setupQuad() {
    // We'll define our quad using 4 vertices of the custom 'Vertex' class
    Vertex v0 = new Vertex();
    v0.setXYZ(-0.5f, 0.5f, 0f);
    v0.setRGB(1, 0, 0);
    Vertex v1 = new Vertex();
    v1.setXYZ(-0.5f, -0.5f, 0f);
    v1.setRGB(0, 1, 0);
    Vertex v2 = new Vertex();
    v2.setXYZ(0.5f, -0.5f, 0f);
    v2.setRGB(0, 0, 1);
    Vertex v3 = new Vertex();
    v3.setXYZ(0.5f, 0.5f, 0f);
    v3.setRGB(1, 1, 1);

    Vertex[] vertices = new Vertex[] {v0, v1, v2, v3};
    // Put each 'Vertex' in one FloatBuffer
    FloatBuffer verticesBuffer =
        BufferUtils.createFloatBuffer(vertices.length * Vertex.elementCount);
    for (int i = 0; i < vertices.length; i++) {
      verticesBuffer.put(vertices[i].getXYZW());
      verticesBuffer.put(vertices[i].getRGBA());
    }
    verticesBuffer.flip();

    // OpenGL expects to draw vertices in counter clockwise order by default
    byte[] indices = {
      0, 1, 2,
      2, 3, 0
    };
    indicesCount = indices.length;
    ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount);
    indicesBuffer.put(indices);
    indicesBuffer.flip();

    // Create a new Vertex Array Object in memory and select it (bind)
    vaoId = GL30.glGenVertexArrays();
    GL30.glBindVertexArray(vaoId);

    // Create a new Vertex Buffer Object in memory and select it (bind)
    vboId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, verticesBuffer, GL15.GL_STATIC_DRAW);
    // Put the positions in attribute list 0
    GL20.glVertexAttribPointer(0, 4, GL11.GL_FLOAT, false, Vertex.sizeInBytes, 0);
    // Put the colors in attribute list 1
    GL20.glVertexAttribPointer(
        1, 4, GL11.GL_FLOAT, false, Vertex.sizeInBytes, Vertex.elementBytes * 4);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    // Deselect (bind to 0) the VAO
    GL30.glBindVertexArray(0);

    // Create a new VBO for the indices and select it (bind) - INDICES
    vboiId = GL15.glGenBuffers();
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
    GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW);
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
  }
Esempio n. 10
0
 public void UpdateListener(float x, float y, float z, float vx, float vy, float vz) {
   FloatBuffer listenerVel = BufferUtils.createFloatBuffer(3).put(new float[] {vx, vy, vz});
   FloatBuffer listenerPos = BufferUtils.createFloatBuffer(3).put(new float[] {x, y, z});
   listenerPos.flip();
   listenerVel.flip();
   AL10.alListener(AL10.AL_POSITION, listenerPos);
   AL10.alListener(AL10.AL_VELOCITY, listenerVel);
   listenerPosX = x;
   listenerPosY = y;
 }
 @Override
 public void createBuffers() throws Exception {
   vertexBuffer = BufferUtils.createFloatBuffer(vertices.length);
   vertexBuffer.put(vertices);
   vertexBuffer.rewind();
   indexBuffer = BufferUtils.createIntBuffer(numVertices);
   indexBuffer.put(vertex_indices);
   indexBuffer.rewind();
   fetchPNGTexture();
 }
Esempio n. 12
0
  /**
   * Creates a RenderTexture object for enabling render-to-texture on a P-buffer.
   *
   * <p>NOTE: Only one of useRGB and useRGBA can be true at the same time.
   *
   * <p>NOTE: useRGB(A) and useDepth can be true at the same time, thus allowing two different
   * render textures.
   *
   * <p>NOTE: The target parameter can be one of the following:
   *
   * <p>RENDER_TEXTURE_1D RENDER_TEXTURE_2D RENDER_TEXTURE_RECTANGLE RENDER_TEXTURE_CUBE_MAP
   *
   * @param useRGB - When true the P-buffer can be used as an RGB render texture.
   * @param useRGBA - When true the P-buffer can be used as an RGBA render texture.
   * @param useDepth - When true the P-buffer can be used as a depth render texture.
   * @param isRectangle - When true rectangle textures will be allowed on the P-buffer.
   * @param target - The texture target of the render texture.
   * @param mipmaps - How many mipmap levels to allocate on the P-buffer.
   */
  public RenderTexture(
      boolean useRGB,
      boolean useRGBA,
      boolean useDepth,
      boolean isRectangle,
      int target,
      int mipmaps) {
    if (useRGB && useRGBA)
      throw new IllegalArgumentException("A RenderTexture can't be both RGB and RGBA.");

    if (mipmaps < 0) throw new IllegalArgumentException("The mipmap levels can't be negative.");

    if (isRectangle && target != RENDER_TEXTURE_RECTANGLE)
      throw new IllegalArgumentException(
          "When the RenderTexture is rectangle the target must be RENDER_TEXTURE_RECTANGLE.");

    pixelFormatCaps = BufferUtils.createIntBuffer(4);
    pBufferAttribs = BufferUtils.createIntBuffer(8);

    if (useRGB) {
      pixelFormatCaps.put(
          isRectangle ? WGL_BIND_TO_TEXTURE_RECTANGLE_RGB_NV : WGL_BIND_TO_TEXTURE_RGB_ARB);
      pixelFormatCaps.put(GL_TRUE);

      pBufferAttribs.put(WGL_TEXTURE_FORMAT_ARB);
      pBufferAttribs.put(WGL_TEXTURE_RGB_ARB);
    } else if (useRGBA) {
      pixelFormatCaps.put(
          isRectangle ? WGL_BIND_TO_TEXTURE_RECTANGLE_RGBA_NV : WGL_BIND_TO_TEXTURE_RGBA_ARB);
      pixelFormatCaps.put(GL_TRUE);

      pBufferAttribs.put(WGL_TEXTURE_FORMAT_ARB);
      pBufferAttribs.put(WGL_TEXTURE_RGBA_ARB);
    }

    if (useDepth) {
      pixelFormatCaps.put(
          isRectangle ? WGL_BIND_TO_TEXTURE_RECTANGLE_DEPTH_NV : WGL_BIND_TO_TEXTURE_DEPTH_NV);
      pixelFormatCaps.put(GL_TRUE);

      pBufferAttribs.put(WGL_DEPTH_TEXTURE_FORMAT_NV);
      pBufferAttribs.put(WGL_TEXTURE_DEPTH_COMPONENT_NV);
    }

    pBufferAttribs.put(WGL_TEXTURE_TARGET_ARB);
    pBufferAttribs.put(target);

    if (mipmaps != 0) {
      pBufferAttribs.put(WGL_MIPMAP_TEXTURE_ARB);
      pBufferAttribs.put(mipmaps);
    }

    pixelFormatCaps.flip();
    pBufferAttribs.flip();
  }
Esempio n. 13
0
  public void processMouse() {

    DoubleBuffer x = BufferUtils.createDoubleBuffer(1), y = BufferUtils.createDoubleBuffer(1);

    glfwGetCursorPos(window, x, y);
    x.rewind();
    y.rewind();
    float mouseX = (float) x.get(), mouseY = (float) y.get();

    pitch = MOUSE_SENSITIVITY * mouseY;
    yaw = MOUSE_SENSITIVITY * mouseX;
  }
Esempio n. 14
0
  public Window(int width, int height, String title, long monitor, long share) {
    this.width = width;
    this.height = height;
    this.title = title;
    this.monitor = monitor;
    this.share = share;

    widthBuffer = BufferUtils.createIntBuffer(1);
    heightBuffer = BufferUtils.createIntBuffer(1);

    windowHandle = glfwCreateWindow(width, height, title, monitor, share);
  }
Esempio n. 15
0
 private void resize() {
   IntBuffer b1 = BufferUtils.createIntBuffer(1);
   IntBuffer b2 = BufferUtils.createIntBuffer(1);
   GLFW.glfwGetFramebufferSize(window, b1, b2);
   GL11.glViewport(0, 0, b1.get(), b2.get());
   persp = GLHelper.initPerspectiveProjectionMatrix(FOV, width, height, zNear, zFar);
   ortho =
       GLHelper.initOrthographicProjectionMatrix(
           -width / 2, width / 2, -height / 2, height / 2, zNear, zFar);
   ortho2D = GLHelper.initOrthographicProjectionMatrix(0, width, 0, height, 0, 1);
   transform = new Matrix4f();
 }
Esempio n. 16
0
  // ------- Added for Lighting Test----------//
  private void initLightArrays() {
    matSpecular = BufferUtils.createFloatBuffer(4);
    matSpecular.put(1.0f).put(1.0f).put(1.0f).put(1.0f).flip();

    lightPosition = BufferUtils.createFloatBuffer(4);
    lightPosition.put(1.0f).put(1.0f).put(1.0f).put(0.0f).flip();

    whiteLight = BufferUtils.createFloatBuffer(4);
    whiteLight.put(1.0f).put(1.0f).put(1.0f).put(1.0f).flip();

    lModelAmbient = BufferUtils.createFloatBuffer(4);
    lModelAmbient.put(0.5f).put(0.5f).put(0.5f).put(1.0f).flip();
  }
Esempio n. 17
0
  /**
   * Stops and releases all sources, clears each of the specified Audio buffers, destroys the OpenAL
   * context, and resets SoundStore for future use.
   *
   * <p>Calling SoundStore.get().init() will re-initialize the OpenAL context after a call to
   * destroyOpenAL (Note: AudioLoader.getXXX calls init for you).
   *
   * @author davedes (http://slick.ninjacave.com/forum/viewtopic.php?t=3920)
   */
  private static void destroyOpenAL() {
    if (!trackExists()) return;
    stop();

    try {
      // get Music object's (private) Audio object reference
      Field sound = player.getClass().getDeclaredField("sound");
      sound.setAccessible(true);
      Audio audio = (Audio) (sound.get(player));

      // first clear the sources allocated by SoundStore
      int max = SoundStore.get().getSourceCount();
      IntBuffer buf = BufferUtils.createIntBuffer(max);
      for (int i = 0; i < max; i++) {
        int source = SoundStore.get().getSource(i);
        buf.put(source);

        // stop and detach any buffers at this source
        AL10.alSourceStop(source);
        AL10.alSourcei(source, AL10.AL_BUFFER, 0);
      }
      buf.flip();
      AL10.alDeleteSources(buf);
      int exc = AL10.alGetError();
      if (exc != AL10.AL_NO_ERROR) {
        throw new SlickException("Could not clear SoundStore sources, err: " + exc);
      }

      // delete any buffer data stored in memory, too...
      if (audio != null && audio.getBufferID() != 0) {
        buf = BufferUtils.createIntBuffer(1).put(audio.getBufferID());
        buf.flip();
        AL10.alDeleteBuffers(buf);
        exc = AL10.alGetError();
        if (exc != AL10.AL_NO_ERROR) {
          throw new SlickException(
              "Could not clear buffer " + audio.getBufferID() + ", err: " + exc);
        }
      }

      // clear OpenAL
      AL.destroy();

      // reset SoundStore so that next time we create a Sound/Music, it will reinit
      SoundStore.get().clear();

      player = null;
    } catch (Exception e) {
      ErrorHandler.error("Failed to destroy OpenAL.", e, true);
    }
  }
Esempio n. 18
0
  protected void initGLState() {
    System.err.println("GL_VENDOR: " + glGetString(GL_VENDOR));
    System.err.println("GL_RENDERER: " + glGetString(GL_RENDERER));
    System.err.println("GL_VERSION: " + glGetString(GL_VERSION));

    // setup ogl
    FloatBuffer pos = BufferUtils.createFloatBuffer(4).put(new float[] {5.0f, 5.0f, 10.0f, 0.0f});
    FloatBuffer red = BufferUtils.createFloatBuffer(4).put(new float[] {0.8f, 0.1f, 0.0f, 1.0f});
    FloatBuffer green = BufferUtils.createFloatBuffer(4).put(new float[] {0.0f, 0.8f, 0.2f, 1.0f});
    FloatBuffer blue = BufferUtils.createFloatBuffer(4).put(new float[] {0.2f, 0.2f, 1.0f, 1.0f});

    pos.flip();
    red.flip();
    green.flip();
    blue.flip();

    glLightfv(GL_LIGHT0, GL_POSITION, pos);
    glEnable(GL_CULL_FACE);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_DEPTH_TEST);

    /* make the gears */
    gear1 = glGenLists(1);
    glNewList(gear1, GL_COMPILE);
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
    gear(1.0f, 4.0f, 1.0f, 20, 0.7f);
    glEndList();

    gear2 = glGenLists(1);
    glNewList(gear2, GL_COMPILE);
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
    gear(0.5f, 2.0f, 2.0f, 10, 0.7f);
    glEndList();

    gear3 = glGenLists(1);
    glNewList(gear3, GL_COMPILE);
    glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
    gear(1.3f, 2.0f, 0.5f, 10, 0.7f);
    glEndList();

    glEnable(GL_NORMALIZE);

    glMatrixMode(GL_PROJECTION);

    float h = (float) 300 / (float) 300;
    glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.0f, 0.0f, -40.0f);
  }
Esempio n. 19
0
    /** Regenerates any dirty mimaps. */
    public void regenerateMipmaps() {
      if (mipmapDirty) {
        ByteBuffer data1 =
            BufferUtils.createByteBuffer(size.getWidth() * size.getHeight() * format.bytes);
        ByteBuffer data = data1;

        GL11.glBindTexture(GL11.GL_TEXTURE_2D, id);

        // read the texture out
        GL11.glGetTexImage(GL11.GL_TEXTURE_2D, 0, format.glFormat, GL11.GL_UNSIGNED_BYTE, data);

        data.rewind();

        // regenerate the mipmaps
        GLU.gluBuild2DMipmaps(
            GL11.GL_TEXTURE_2D,
            format.glInternalFormat,
            size.getWidth(),
            size.getHeight(),
            format.glFormat,
            GL11.GL_UNSIGNED_BYTE,
            data);

        mipmapDirty = false;
      }
    }
Esempio n. 20
0
  /** x, y, z, fov, aspectRatio, zNear, zFar */
  public Camera(long window, Vec3 position, float fov, float aspectRatio, float zNear, float zFar) {

    this.window = window;
    this.position = position;
    this.fov = fov;
    this.zNear = zNear;
    this.zFar = zFar;

    float sine, cotangent, deltaZ;
    float radians = fov / 2 * (float) Math.PI / 180;

    deltaZ = zFar - zNear;
    sine = (float) Math.sin(radians);

    if ((deltaZ == 0) || (sine == 0) || (aspectRatio == 0)) {
      return;
    }

    cotangent = (float) Math.cos(radians) / sine;

    matrix = BufferUtils.createFloatBuffer(16);
    int oldPos = matrix.position();
    matrix.put(IDENTITY_MATRIX);
    matrix.position(oldPos);

    matrix.put(0 * 4 + 0, cotangent / aspectRatio);
    matrix.put(1 * 4 + 1, cotangent);
    matrix.put(2 * 4 + 2, -(zFar + zNear) / deltaZ);
    matrix.put(2 * 4 + 3, -1);
    matrix.put(3 * 4 + 2, -2 * zNear * zFar / deltaZ);
    matrix.put(3 * 4 + 3, 0);
  }
Esempio n. 21
0
  public static String func_74292_a(File par0File, String par1Str, int par2, int par3) {
    try {
      File var4 = new File(par0File, "screenshots");
      var4.mkdir();
      int var5 = par2 * par3;

      if (field_74293_b == null || field_74293_b.capacity() < var5) {
        field_74293_b = BufferUtils.createIntBuffer(var5);
        field_74294_c = new int[var5];
      }

      GL11.glPixelStorei(GL11.GL_PACK_ALIGNMENT, 1);
      GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
      field_74293_b.clear();
      GL11.glReadPixels(
          0, 0, par2, par3, GL12.GL_BGRA, GL12.GL_UNSIGNED_INT_8_8_8_8_REV, field_74293_b);
      field_74293_b.get(field_74294_c);
      func_74289_a(field_74294_c, par2, par3);
      BufferedImage var6 = new BufferedImage(par2, par3, 1);
      var6.setRGB(0, 0, par2, par3, field_74294_c, 0, par2);
      File var7;

      if (par1Str == null) {
        var7 = func_74290_a(var4);
      } else {
        var7 = new File(var4, par1Str);
      }

      ImageIO.write(var6, "png", var7);
      return "Saved screenshot as " + var7.getName();
    } catch (Exception var8) {
      var8.printStackTrace();
      return "Failed to save: " + var8;
    }
  }
Esempio n. 22
0
  public Texture(String path) {

    try {
      BufferedImage image = ImageIO.read(new FileInputStream(path));
      width = image.getWidth();
      height = image.getHeight();
      pixels = new int[width * height];
      image.getRGB(0, 0, width, height, pixels, 0, width);
    } catch (IOException e) {
      e.printStackTrace();
    }
    int[] data = new int[width * height];
    for (int i = 0; i < data.length; i++) {
      int a = (pixels[i] & 0xff000000) >> 24;
      int r = (pixels[i] & 0xff0000) >> 16;
      int g = (pixels[i] & 0xff00) >> 8;
      int b = (pixels[i] & 0xff);
      data[i] = a << 24 | b << 16 | g << 8 | r;
    }
    int id = glGenTextures();
    glBindTexture(GL_TEXTURE_2D, id);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    IntBuffer buffer = (IntBuffer) BufferUtils.createIntBuffer(data.length).put(data).flip();

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
    this.index = id;
    glBindTexture(GL_TEXTURE_2D, 0);
  }
Esempio n. 23
0
  private FloatBuffer storeInFloatBuffer(float[] data) {
    FloatBuffer buffer = BufferUtils.createFloatBuffer(data.length);
    buffer.put(data);
    buffer.flip();

    return buffer;
  }
Esempio n. 24
0
  private IntBuffer storeInIntBuffer(int[] data) {
    IntBuffer buffer = BufferUtils.createIntBuffer(data.length);
    buffer.put(data);
    buffer.flip();

    return buffer;
  }
Esempio n. 25
0
  public void setBufferContainer(BufferContainer bufferContainer) {
    Map<Integer, Buffer> buffers = new HashMap<>();

    for (Entry<Integer, Object> entry : bufferContainer.getBuffers().entrySet()) {
      int layout = entry.getKey();
      Object buffer = entry.getValue();

      if (buffer instanceof TFloatArrayList) {

        if (((TFloatArrayList) buffer).isEmpty()) {
          throw new IllegalStateException("Buffer can't be empty");
        }

        FloatBuffer floatBuffer = BufferUtils.createFloatBuffer(((TFloatArrayList) buffer).size());
        floatBuffer.clear();
        floatBuffer.put(((TFloatArrayList) buffer).toArray());
        floatBuffer.flip();

        buffers.put(layout, floatBuffer);
      } else {
        throw new IllegalStateException("Buffer different of TFloatArrayList not yet supported");
      }
    }

    flushingNumVertices = bufferContainer.element;

    initFlush(buffers);
  }
Esempio n. 26
0
class TimerLinux {

  private final ByteBuffer time =
      BufferUtils.createByteBuffer(Math.max(timespec.SIZEOF, timeval.SIZEOF));

  private final TimeSource timeSource;

  private long base;

  TimerLinux() {
    if (clock_gettime(CLOCK_MONOTONIC, time) == 0) {
      timeSource =
          new TimeSource() {
            @Override
            public double getResolution() {
              return 1e-9;
            }

            @Override
            public long getRawTime() {
              clock_gettime(CLOCK_MONOTONIC, time);
              return timespec.sec(time) * 1000000000L + timespec.nsec(time);
            }
          };
    } else {
      timeSource =
          new TimeSource() {
            @Override
            public double getResolution() {
              return 1e-6;
            }

            @Override
            public long getRawTime() {
              gettimeofday(time, null);
              return timeval.sec(time) * 1000000L + timeval.usec(time);
            }
          };
    }
  }

  public void init() {
    base = timeSource.getRawTime();
  }

  public double getTime() {
    return (double) (timeSource.getRawTime() - base) * timeSource.getResolution();
  }

  public void setTime(double time) {
    base = timeSource.getRawTime() - (long) (time / timeSource.getResolution());
  }

  private interface TimeSource {

    double getResolution();

    long getRawTime();
  }
}
Esempio n. 27
0
  private void drawPlayerIcons(final Player player, double elapsedMillis) {
    quadVao.bind();
    playerTexture.bind(0);
    uiShader.use();

    final FloatBuffer matrixBuffer = BufferUtils.createFloatBuffer(16);
    Matrix4f projectionMatrix = new Matrix4f().setOrtho(0, windowWidth, windowHeight, 0, -1, 1);

    for (int i = 0; i < player.numLives(); i++) {
      final Matrix4f mat = new Matrix4f();
      mat.identity();
      mat.translate((float) windowWidth - 100 - i * 60f, 60, 0);
      mat.translate(25, 25, 0);
      mat.scale(25, 25, 1);

      Matrix4f tmp = new Matrix4f(projectionMatrix).mul(mat);
      tmp.get(matrixBuffer);
      uiShader.setUniformMatrixF("projMatrix", matrixBuffer);

      GL11.glDrawArrays(GL11.GL_TRIANGLES, 0, 6);
    }

    playerTexture.unbind();
    quadVao.unbind();
  }
 public static String func_74292_a(
     File p_74292_0_, String p_74292_1_, int p_74292_2_, int p_74292_3_) {
   try {
     File file = new File(p_74292_0_, "screenshots");
     file.mkdir();
     int i = p_74292_2_ * p_74292_3_;
     if (field_74293_b == null || field_74293_b.capacity() < i) {
       field_74293_b = BufferUtils.createIntBuffer(i);
       field_74294_c = new int[i];
     }
     GL11.glPixelStorei(3333, 1);
     GL11.glPixelStorei(3317, 1);
     field_74293_b.clear();
     GL11.glReadPixels(0, 0, p_74292_2_, p_74292_3_, 32993, 33639, field_74293_b);
     field_74293_b.get(field_74294_c);
     func_74289_a(field_74294_c, p_74292_2_, p_74292_3_);
     BufferedImage bufferedimage = new BufferedImage(p_74292_2_, p_74292_3_, 1);
     bufferedimage.setRGB(0, 0, p_74292_2_, p_74292_3_, field_74294_c, 0, p_74292_2_);
     File file1;
     if (p_74292_1_ == null) {
       file1 = func_74290_a(file);
     } else {
       file1 = new File(file, p_74292_1_);
     }
     ImageIO.write(bufferedimage, "png", file1);
     return (new StringBuilder())
         .append("Saved screenshot as ")
         .append(file1.getName())
         .toString();
   } catch (Exception exception) {
     exception.printStackTrace();
     return (new StringBuilder()).append("Failed to save: ").append(exception).toString();
   }
 }
Esempio n. 29
0
  /** @see org.newdawn.slick.opengl.ImageData#getImageBufferData() */
  public ByteBuffer getImageBufferData() {
    ByteBuffer scratch = BufferUtils.createByteBuffer(rawData.length);
    scratch.put(rawData);
    scratch.flip();

    return scratch;
  }
Esempio n. 30
0
  public void render(ShaderHandler sh, DataUtils util, int brightness) {
    FloatBuffer modelmatrixfb = BufferUtils.createFloatBuffer(16);
    Matrix4f.mul(rotmatrix, modelmatrix, new Matrix4f()).store(modelmatrixfb);
    modelmatrixfb.flip();

    util.setup(datafb, vboID, vaoID, sh, textureid, 2, indices, modelmatrixfb, brightness);
    util.drawRectangle();
  }