• Advertisement
Sign in to follow this  

Serious Problem with TexCoords

This topic is 4727 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

Hey Guys, I have been having this problem for about a week and I think that I narrowed down the problem to this. I have a simple box model, the box has 8 verts, 20 norms, 20 texcoords(the box has no bottom thats why there is 20). Now I am trying to draw this box through glDrawElements. Now when it draws, the model draws fine but when the texture is applied to this box, only the front, top, and back are textured right. the sides are completely streched and warped. I don't think its my draw but here is my draw: // Enable the Client State of VBO glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); // Bind the Buffers to the Data to Render glBindBufferARB( GL_ARRAY_BUFFER_ARB, temp->data->mesh.Hierarchy.m_uiVertBufferID); glVertexPointer(3,GL_FLOAT,0,(char*)NULL); glBindBufferARB( GL_ARRAY_BUFFER_ARB, temp->data->mesh.Hierarchy.m_uiNormalBufferID); glNormalPointer(GL_FLOAT,0,(char*)NULL); glBindBufferARB( GL_ARRAY_BUFFER_ARB, temp->data->mesh.Hierarchy.m_uiTexCoordBufferID); glTexCoordPointer(2,GL_FLOAT,0,(char*)NULL); // Draw the Array of Triangles for the Mesh glDrawElements(GL_TRIANGLES,temp->data->mesh.Hierarchy.iNumPolys*3,GL_UNSIGNED_INT,temp->data->mesh.Hierarchy.mVertInd); //glDrawArrays(GL_TRIANGLE_STRIP, 0, temp->data->mesh.Hierarchy.iNumVerts); // Disable the ClientState glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); Now all the people that I have talked to say the draw is fine. And I think the root of the problem is how I am storing the data from the RTG file from Maya. Here is my .h on how I am reading and storing things in. Like this: struct Poly { unsigned int uX; unsigned int uY; unsigned int uZ; }; struct Object { unsigned int m_uiVertBufferID, m_uiNormalBufferID, m_uiTexCoordBufferID; // v# n# t# p# int iNumVerts; int iNumNorms; int iNumTexCs; int iNumPolys; //Arrays for Values float *m_fVerts, *m_fTexCoords, *m_fNormals; Poly *mVertInd, *mNormInd, *mTexInd; }; class CLoader { public: int iNumObjects; Object *Hierarchy; public: CLoader(void); ~CLoader(void); bool LoadModelFile(const char *cFilename); }; Now when I load the VBO's I use this: //Generate the Vertex Information Into the card glGenBuffersARB( 1, &ptemp->mesh.Hierarchy.m_uiVertBufferID); glBindBufferARB( GL_ARRAY_BUFFER_ARB, ptemp->mesh.Hierarchy.m_uiVertBufferID ); glBufferDataARB( GL_ARRAY_BUFFER_ARB,ptemp->mesh.Hierarchy.iNumVerts*3*sizeof(float), ptemp->mesh.Hierarchy.m_fVerts , GL_STATIC_DRAW_ARB); glGenBuffersARB( 1, &ptemp->mesh.Hierarchy.m_uiNormalBufferID ); glBindBufferARB( GL_ARRAY_BUFFER_ARB, ptemp->mesh.Hierarchy.m_uiNormalBufferID ); glBufferDataARB( GL_ARRAY_BUFFER_ARB, ptemp->mesh.Hierarchy.iNumNorms*3*sizeof(float), ptemp->mesh.Hierarchy.m_fNormals, GL_STATIC_DRAW_ARB); glGenBuffersARB( 1, &ptemp->mesh.Hierarchy.m_uiTexCoordBufferID ); glBindBufferARB( GL_ARRAY_BUFFER_ARB, ptemp->mesh.Hierarchy.m_uiTexCoordBufferID ); glBufferDataARB( GL_ARRAY_BUFFER_ARB, ptemp->mesh.Hierarchy.iNumTexCs*1*sizeof(float), ptemp->mesh.Hierarchy.m_fTexCoords, GL_STATIC_DRAW_ARB); Now People were saying that the Vert array, Norm array, and the Texcoord array all have to be the same size in order to draw with glDrawElements. The numbers in my arrays are not the same, so I'm not sure not to get them the same or convince glDrawElements that they are fine with the numbers I am recieving from the RTG. If there is a fix PLEASE help.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Sythlin
If there is a fix PLEASE help.


The fix is to duplicate all vertices that have multiple normals/tex coords. For a box, that will probably be all of them because you would have three normals for each vertex (one for each face of the box it belongs to).

Share this post


Link to post
Share on other sites
Quote:
Original post by Sythlin
Now will that effect my performance if I make more Verts to Draw?


Yes it will. BUT (a very big but) it won't affect it in any noticable way unless you are duplicating A LOT of vertices (ie: every vertex in a high-polygon mesh to render with hard edges for a faceted look).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement