So I have a very simple renderer that uses a display list. I am trying to convert it to use a VBO. The step before a VBO is doing a vertex array (upload every frame). I can not get that to work. I’ve been trying everything I can think of for like an hour and got nowhere.
Here’s the old displaylist code:
public final class RenderReticle<Void> extends Renderer<Void> {
public static final RenderReticle INSTANCE = new RenderReticle();
private static final float size = 25f;
private static final float halfSize = size / 2;
private DisplayList displayList;
private Texture texture;
private RenderReticle() {
}
@Override
public void init() {
this.displayList = new DisplayList();
this.displayList.startDrawing();
glBegin(GL_QUADS);
glTexCoord2f(0f, 0f); glVertex2f(0.0f, 0.0f);
glTexCoord2f(0f, 1f); glVertex2f(0.0f, size);
glTexCoord2f(1f, 1f); glVertex2f(size, size);
glTexCoord2f(1f, 0f); glVertex2f(size, 0.0f);
glEnd();
this.displayList.stopDrawing();
this.texture = Texture.get("reticle");
}
@Override
public void render(final Void object) {
gluSet2D();
glTranslatef(Window.instance().getWidth() / 2 - halfSize, Window.instance().getHeight() / 2 - halfSize, 0);
this.texture.bind();
this.displayList.call();
gluSet3D();
}
}
And here’s the new vertex array code:
public final class RenderReticle<Void> extends Renderer<Void> {
public static final RenderReticle INSTANCE = new RenderReticle();
private static final float size = 1f;
private static final float halfSize = size / 2;
private Texture texture;
private FloatBuffer vBuffer;
private FloatBuffer tBuffer;
private RenderReticle() {
}
@Override
public void init() {
this.vBuffer = BufferUtils.createFloatBuffer(8);
this.vBuffer.put(0).put(0);
this.vBuffer.put(0).put(size);
this.vBuffer.put(size).put(size);
this.vBuffer.put(size).put(0);
this.vBuffer.flip();
this.tBuffer = BufferUtils.createFloatBuffer(8);
this.tBuffer.put(0).put(0);
this.tBuffer.put(0).put(1);
this.tBuffer.put(1).put(1);
this.tBuffer.put(1).put(0);
this.tBuffer.flip();
this.texture = Texture.get("reticle");
}
@Override
public void render(final Void object) {
gluSet2D();
glTranslatef(Window.instance().getWidth() / 2 - halfSize, Window.instance().getHeight() / 2 - halfSize, 0);
this.texture.bind();
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(4, GL_FLOAT, 2 << 2, this.vBuffer);
glTexCoordPointer(4, GL_FLOAT, 2 << 2, this.tBuffer);
glDrawArrays(GL_QUADS, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
gluSet3D();
}
}
“gluSet2D” and “gluSet3D” are functions I wrote. They basically just do glOrtho and the perspective matrix respectively.
So, how come the first one works but the second one doesn’t? (It just displays nothing on the screen).