Sign in to follow this  

Problem specifying arrays.

This topic is 4560 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
offset = offsetof(MeshVert, position);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(MeshVert), 0);

offset = offsetof(MeshVert, normal);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, sizeof(MeshVert), (void*)offset);

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

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

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

offset = offsetof(MeshVert, biTangent);
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;
offset = offsetof(MeshVert, position);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(MeshVert), (void*)offset);

offset = offsetof(MeshVert, normal);
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, sizeof(MeshVert), (void*)offset);

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

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

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

offset = offsetof(MeshVert, biTangent);
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.

Share this post


Link to post
Share on other sites

This topic is 4560 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this