Пример #1
0
  void setup_camera(float fov, float ratio, float view_distance) {
    GL11.glMatrixMode(GL11.GL_PROJECTION);
    GL11.glLoadIdentity();
    GLU.gluPerspective(fov, ratio, 0.01f, view_distance);
    GL11.glMatrixMode(GL11.GL_MODELVIEW);

    camera.set_attribs(fov, ratio, 0.01f, view_distance);
  }
Пример #2
0
  private void render_batch(ChunkNode.Batch batch) {
    if (!camera.collides(batch.box)) return;

    Renderer.draw_calls++;

    // Use the shader the batch needs
    GL20.glUseProgram(batch.shader);

    // Bind VBO to vertex pointer
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, batch.vert_buf);
    GL11.glVertexPointer(3, GL11.GL_FLOAT, 0, 0);

    // Bind the texture coord VBO to texture pointer
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, batch.tex_buf);
    GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);

    // Bind the texture for this batch
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, batch.tex);

    // Bind index array
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, batch.indices);

    // Draw the block
    GL12.glDrawRangeElements(
        GL11.GL_QUADS,
        0,
        Constants.Chunk.block_number * 24 - 1,
        batch.num_elements,
        GL11.GL_UNSIGNED_INT,
        0);

    Renderer.batch_draw_calls++;
    Renderer.quads += batch.num_elements;

    // Unbind the texture
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);

    // Unbind all buffers
    GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);
    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);

    GL20.glUseProgram(0);
  }