summaryrefslogtreecommitdiffstats
path: root/src/de/gamezock/metacraft/ui/Renderer.java
blob: 8d4b8d20528918fad246970b08376784f27f33c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package de.gamezock.metacraft.ui;

import java.nio.IntBuffer;

import javax.media.opengl.GL;
import javax.media.opengl.GL2;

import de.gamezock.metacraft.data.Map;
import de.gamezock.metacraft.data.VertexBuffer;

public class Renderer {
  private Main main;
  
  public Renderer(Main main) {
    this.main = main;
  }
  
  public void render(GL2 gl) {
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    
    Map currentMap = main.getCurrentMap();
    
    gl.glEnable(GL2.GL_VERTEX_ARRAY);
    gl.glEnable(GL2.GL_NORMAL_ARRAY);
    
    gl.glPushMatrix();
    gl.glRotatef((System.currentTimeMillis()%9000)/25.0f, 0, 0, 1);
    gl.glTranslatef(-20, -20, 0);
    
    gl.glColor3f(1, 1, 1);
    
    VertexBuffer buffer = currentMap.getVertexBuffer();
    
    gl.glInterleavedArrays(GL2.GL_N3F_V3F, 0, buffer.getBuffer().clear());
    
    IntBuffer indexBuffer = currentMap.getIndexBuffer();
    indexBuffer.clear();
    
    gl.glDrawElements(GL.GL_TRIANGLES, indexBuffer.capacity(), GL2.GL_UNSIGNED_INT, indexBuffer);
    
    gl.glPopMatrix();
  }
}