PDA

View Full Version : Passing texcoords problem... again.



Baggio
06-22-2005, 10:30 AM
So, here is the structure I upload with VBO:

struct MeshVert {
vec3 position; /**< Vertex position. */
vec3 normal; /**< Vertex normal. */
vec2 UV; /**< UV coordinates. */
vec2 lightmapUV; /**< UV coordinates for the lightmaps. */
vec3 tangent; /**< Tangent of the vertex. */
vec3 biTangent; /**< bitangent of the vertex. */
};And when I try to pass everything and draw I use:

glBindBufferARB(GL_ARRAY_BUFFER_ARB, 1);

size_t offset = 0;
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(MeshVert), 0);

offset += sizeof(vec3);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, sizeof(MeshVert), (void*)offset);

offset += sizeof(vec3);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE0);
glTexCoordPointer(2, GL_FLOAT, sizeof(MeshVert), (void*)offset);

offset += sizeof(vec2);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE1);
glTexCoordPointer(2, GL_FLOAT, sizeof(MeshVert), (void*)(offset));

offset += sizeof(vec2);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE2);
glTexCoordPointer(3, GL_FLOAT, sizeof(MeshVert), (void*)(offset));

offset += sizeof(vec3);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE3);
glTexCoordPointer(3, GL_FLOAT, sizeof(MeshVert), (void*)(offset));

int *indices = meshes[meshnumber]->meshTextureIndices[group]->indices;

glDrawElements(GL_TRIANGLES, (GLsizei)meshes[meshnumber]->meshTextureIndices[group]->numIndices, GL_UNSIGNED_INT, indices);

glClientActiveTextureARB(GL_TEXTURE3);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE2);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE1);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE0);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);

glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);But after drawing with my shader everything looks wrong, the diffuse component is wrong so my guess is that the tangents or bitangents are passed wrong (they are fine in MeshVert, I checked already), but if I replace the last code with the following the diffuse component looks right but the lightmaps UVs are wrong.

glBindBufferARB(GL_ARRAY_BUFFER_ARB, 1);

size_t offset = 0;
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(MeshVert), 0);

offset += sizeof(vec3);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, sizeof(MeshVert), (void*)offset);

offset += sizeof(vec3);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE0);
glTexCoordPointer(2, GL_FLOAT, sizeof(MeshVert), (void*)offset);

offset += sizeof(vec2);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE1);
glTexCoordPointer(2, GL_FLOAT, sizeof(MeshVert), (void*)(offset));

offset += sizeof(vec2);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE2);
glTexCoordPointer(3, GL_FLOAT, sizeof(MeshVert), (void*)(offset));

offset += sizeof(vec3);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE3);
glTexCoordPointer(3, GL_FLOAT, sizeof(MeshVert), (void*)(sizeof(vec3) * 3));

int *indices = meshes[meshnumber]->meshTextureIndices[group]->indices;

glDrawElements(GL_TRIANGLES, (GLsizei)meshes[meshnumber]->meshTextureIndices[group]->numIndices, GL_UNSIGNED_INT, indices);

glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);Nothing makes any sense to me so maybe someone can help me.

Thanks in advance.

mikef
06-22-2005, 11:43 AM
Try using offsetof() to calculate your struct member offsets - the compiler may be padding (or even reordering) your struct members.

Baggio
06-22-2005, 12:06 PM
Thanks for that tip mikef. I did compared the offset of both methods (offsetof() vs adding sizeof()) and both had same results so everything is broken still. Anyway I will continue to use offsetof() since its easier to use.

Thanks.

Baggio
06-23-2005, 01:16 PM
Nobody? :(

zeckensack
06-24-2005, 06:57 AM
Swap around your glEnableClientState(GL_TEXTURE_COORD_ARRAY) calls so that they occur after glClientActiveTexture.

I.e. instead of
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glClientActiveTextureARB(GL_TEXTURE0);
glTexCoordPointer(2, GL_FLOAT, sizeof(MeshVert), (void*)offset);use
glClientActiveTextureARB(GL_TEXTURE0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(MeshVert), (void*)offset);Do that for all texcoords.

Your disabling sequence is correct btw.

Baggio
06-24-2005, 10:19 PM
I did what you tell me but it's still wrong. How could this be? I can't believe I can't this stuff working even with all the helpful input.