So I’m fairly new to VBO’s, but since everyone knows it’s wayy faster than immediate mode or display lists, I thought I’d gave it a try. It renders the screen completely white…
My VBO code
public abstract class VBO {
public static TexVBO create(double vertices[], double texCoords[], Texture tex)
{
int vertexId, textureId;
DoubleBuffer Bvertex, Btexture;
vertexId = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vertexId);
glBufferData(GL_ARRAY_BUFFER, Bvertex = dBuf(vertices), GL_STATIC_DRAW);
textureId = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, textureId);
glBufferData(GL_ARRAY_BUFFER, Btexture = dBuf(texCoords), GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
return new TexVBO(
vertexId, textureId,
vertices.length / 3, texCoords.length / 2,
Bvertex, Btexture,
tex.getTextureId(),
7);
}
public abstract void draw();
public abstract void delete();
private static DoubleBuffer dBuf(double d[])
{
DoubleBuffer buf = BufferUtils.createDoubleBuffer(d.length);
buf.put(d);
buf.flip();
return buf;
}
}
and my TexVBO code
public class TexVBO extends VBO {
private int vertexArrayId, textureArrayId, texId;
private int vexCount, texCount;
private int drawMode;
private DoubleBuffer vertexArray, textureArray;
public TexVBO(int vertexArrayId, int textureArrayId, int vertexCount, int texCount, DoubleBuffer vertexArray, DoubleBuffer textureArray, int texId, int drawMode)
{
this.vexCount = vertexCount;
this.texCount = texCount;
this.vertexArrayId = vertexArrayId;
this.textureArrayId = textureArrayId;
this.texId = texId;
this.drawMode = drawMode;
this.vertexArray = vertexArray;
this.textureArray = textureArray;
}
public void draw()
{
// Bind the texture
glEnable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texId);
glEnableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, vertexArrayId);
glVertexPointer(3, GL_DOUBLE, 0, 0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, textureArrayId);
glTexCoordPointer(2, GL_DOUBLE, 0, 0);
// Unbind the array buffer.
glBindBuffer(GL_ARRAY_BUFFER, 0);
// Draw the vertices.
glDrawArrays(GL_QUADS, 0, vexCount);
// Disable some client states.
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
// Unbind the texture
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
}
public void delete()
{
glDeleteBuffers(vertexArrayId);
glDeleteBuffers(textureArrayId);
}
}
What’s wrong??