|
I was using this code to render my textures (2d texture, rendered as a rectangle, ortho2D projection):
public void render(GL2 gl) {
gl.glBindTexture(GL2.GL_TEXTURE_2D, idTexture);
gl.glBegin(GL2.GL_TRIANGLE_FAN);
gl.glTexCoord2d(0, 1);
gl.glVertex2d(0, 0);
gl.glTexCoord2d(1, 1);
gl.glVertex2d(width, 0);
gl.glTexCoord2d(1, 0);
gl.glVertex2d(width, height);
gl.glTexCoord2d(0, 0);
gl.glVertex2d(0, height);
gl.glEnd();
}
It works fine, but I read this kind of implementation is outdated, so I tried to use it using VBOs
// Creating VBO
public void createVBO(GL2 gl) {
// Rectangle
int numVex = 4;
FloatBuffer vex = Buffers.newDirectFloatBuffer(new float[]{
0.0f, 0.0f, 0.0f,
width, 0.0f, 0.0f,
width, height, 0.0f,
0.0f, height, 0.0f
});
FloatBuffer tex = Buffers.newDirectFloatBuffer(new float[]{
0.0f, 1.0f,
1.0f, 1.0f,
1.0f, 0.0f,
0.0f, 0.0f
});
gl2.glGenBuffers(1, vexVBO, 0);
gl2.glBindBuffer(GL2.GL_ARRAY_BUFFER, vexVBO[0]);
gl2.glBufferData(GL2.GL_ARRAY_BUFFER, numVex * 3 * Buffers.SIZEOF_FLOAT, vex, GL2.GL_STATIC_DRAW);
gl2.glGenBuffers(1, texVBO, 0);
gl2.glBindBuffer(GL2.GL_ARRAY_BUFFER, tex[0]);
gl2.glBufferData(GL2.GL_ARRAY_BUFFER, numVex * 2 * Buffers.SIZEOF_FLOAT, tex, GL2.GL_STATIC_DRAW);
}
// Rendering
public void render(GL2 gl, int numVex) {
gl.glBindTexture(GL2.GL_TEXTURE_2D, idTexture);
gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, vexVBO[0]);
gl.glVertexPointer(4, GL2.GL_FLOAT, 0, 0l);
gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY);
gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, texVBO[0]);
gl.glTexCoordPointer(3, GL2.GL_FLOAT, 0, 0l);
gl.glDrawArrays(GL2.GL_TRIANGLE_FAN, 0, numVex);
}
And nothing is showed =\. Any help will be appreciated :)
|