Hey, I’m trying to put a texture on my vbo, anybody happen to help me out because I can’t get it working. I’ve been looking at many examples, googled. But I can’t seem to find why it wont work.
private void rebuildVBO(int preX, int preY, int preZ) {
FloatBuffer vCoords = BufferUtils.createFloatBuffer(12 * 6 * size * size * size);
FloatBuffer cCoords = BufferUtils.createFloatBuffer(16 * 6 * size * size * size);
FloatBuffer tCoords = BufferUtils.createFloatBuffer(02 * 6 * size * size * size);
faceCount = 0;
for(int x = 0; x < size; x++) {
for(int y = 0; y < size; y++) {
for(int z = 0; z < size; z++) {
Block block = blockMap[x][y][z];
if(block.isVisible()) {
boolean[] faces = {
true, true, true, true, true, true
};
int fNum = Block.countFaces(faces);
if(fNum > 0) {
vCoords.put(block.getVerticies(preX + x, preY + y, preZ + z, faces));
cCoords.put(block.getColors(faces));
tCoords.put(new float[] { 0f, 1f, });
tCoords.put(new float[] { 1f, 1f, });
tCoords.put(new float[] { 0f, 0f, });
tCoords.put(new float[] { 1f, 0f, });
tCoords.put(new float[] { 0f, 0f, });
tCoords.put(new float[] { 1f, 1f, });
faceCount += fNum;
}
}
}
}
}
vCoords.flip();
cCoords.flip();
tCoords.flip();
glBindBuffer(GL_ARRAY_BUFFER, vId);
glBufferData(GL_ARRAY_BUFFER, vCoords, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, cId);
glBufferData(GL_ARRAY_BUFFER, cCoords, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, tId);
glBufferData(GL_ARRAY_BUFFER, tCoords, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
public void render() {
glBindBuffer(GL_ARRAY_BUFFER, vId);
glVertexPointer(3, GL_FLOAT, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, cId);
glColorPointer(4, GL_FLOAT, 0, 0L);
glBindBuffer(GL_ARRAY_BUFFER, tId);
glTexCoordPointer(2, GL_FLOAT, 0, 0);
// Not sure if this is neccesariy?
//glBindBuffer(GL_ARRAY_BUFFER, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindTexture(GL_TEXTURE_2D, tex.id);
glDrawArrays(GL_QUADS, 0, 4 * faceCount);
glBindTexture(GL_TEXTURE_2D, 0);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}
Any help appreciated