Hi, I’m new to LWJGL and OpenGL. I know the basics like intermediate mode and shaders. I have an out-of-focus idea on GL_PROJECTION, GL_MODELVIEW and glLoadIdentity() (I haven’t completely nailed these ones yet). I recently started using VBOs as I’m aware that the intermediate mode is deprecated. I managed to get it working in a simple program, but now I have hit a wall as to what the problem may be. I’m hoping that somebody will tell me where I’m going wrong(because I definitely do).
Here’s the main code:
public static void main(String[] args) {
Program app = new Program(800, 600, "VBO 3D Test", false); //creates a window
Camera cam = new Camera(60, 800 / 600); //fov, aspect
cam.setPosition(5, 5, 5);
cam.look(0, 0, 0); //this calls gluLookAt(), the parameters are the position where the camera looks
Tile t = new Tile();
while(!Display.isCloseRequested()) {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
t.draw(); //draws a white, horizontal rectangle at 0,0,0 (it should show up, but doesn't)
//any intermediate mode here -will- show up on the screen
Display.update();
Display.sync(60);
}
app.destroy();
}
Methods from class Tile:
private void generateVBO() {
vboFloor = glGenBuffers();
floorVertexData = BufferUtils.createFloatBuffer(4 * 3);
floorVertexData.put(new float[]{-0.5f, 0, -0.5f,
0.5f, 0, -0.5f,
0.5f, 0, 0.5f,
-0.5f, 0, 0.5f});
floorVertexData.flip();
glBindBuffer(GL_ARRAY_BUFFER, vboFloor);
glBufferData(vboFloor, floorVertexData, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
public void draw() {
glBindBuffer(GL_ARRAY_BUFFER, vboFloor);
glVertexPointer(3, GL_FLOAT, 0, 0L);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
When creating the display I use:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
I don’t know why the VBO doesn’t show up on the screen, the exact same code works in the other project, the only difference is that previously I have used glOrtho because it was a 2D project, now it’s in 3D (my first attempt at 3D in OpenGL btw). If you need any other snippets just say it. Any help is really appreciated!