I use a vbo to render some textured quads.
Everything works fine, but the quads are strangely illuminated. Alltough i do NOT have lighting enabled.
The result looks like this:
(http://www.trick7.de/lightingproblem.png)
The first 2 quads where drawn with direct-mode, just to show the difference and that direct-mode has no lighting problem.
This is the create-code for the vbo:
buffer = BufferUtils.createIntBuffer(1);
GL15.glGenBuffers(buffer);
vboId = buffer.get(0);
blocksize = 48;
vArray = new float[objects.size() * blocksize];
int i = 0;
for(Block b:objects){
System.arraycopy(b.getDataT(),0,vArray,i, blocksize);
i += blocksize;
}
vData = BufferUtils.createFloatBuffer(vArray.length);
vData.put(vArray);
vData.rewind();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vData, GL15.GL_STATIC_DRAW);
This is the rendercode for the vbo:
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
glVertexPointer(3, GL_FLOAT, blocksize, 0);
glColorPointer(4, GL_FLOAT, blocksize, 16);
glTexCoordPointer(2, GL_FLOAT, blocksize, 28);
glNormalPointer(GL_FLOAT, blocksize, 36);
glDrawArrays(GL_QUADS, 0, vArray.length / 4);
Do i miss something. I changed so many parameters and shifted data, but nothing changes the outcome.
I dont know where to search.
Does anybody have a clue to where to begin with?
Many thanks to you.
This looks wrong to me:
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
glVertexPointer(3, GL_FLOAT, blocksize, 0);
glColorPointer(4, GL_FLOAT, blocksize, 16);
glTexCoordPointer(2, GL_FLOAT, blocksize, 28);
glNormalPointer(GL_FLOAT, blocksize, 36);
The size of a float is 4 bytes, so I think the color should start at 12, not at 16.
I think the code should be:
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
glVertexPointer(3, GL_FLOAT, blocksize, 0);
glColorPointer(4, GL_FLOAT, blocksize, 12);
glTexCoordPointer(2, GL_FLOAT, blocksize, 28);
glNormalPointer(GL_FLOAT, blocksize, 36);
:o
O.M.G
I can not believe i haven´t seen that.
I have a copy of the project, only difference is that the buffer has no normals added. Certainly the value there is 12.
Oh man. Why did i put the 16 there.
Thanks a lot.
I personally would stick with 4 elements for position, texcoords and color. My own tests have shown me that the performance does actually improve when all components have 4 elements instead of trying to use the minimal number. Sure this might not be the case on all hardware, but it makes programming easier as well.