OpenGL Wrong Texture Same Shader, Same Mesh

Reply

Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

OpenGL Wrong Texture Same Shader, Same Mesh

 
0
  #1
Jun 22nd, 2009
I have a really wierd problem using OpenGL. I've verified all my code passes the correct mesh, correct texture, to the correct shader.

When I use the same texture with multiple instances of the same mesh and the same shader located at different locations on the screen it shows up properly. When using other shaders and other meshes and other textures the scene appears correct.

However when I use same mesh, same shader, but bind alternate textures for rendering my textures get shuffled. There is an object at the position it is suppose to be, but the texture displayed at that location is different. It appears to be mis-binded exactly the same way.

My guess I'm missing something to tell the render to wait before processing the next instance and somehow the texture binding gets affected!

// Note: I've trimmed the code but
//    nSrcBlend = GL_ONE    and nDstBlend = GL_ZERO

void DrawStageMesh( iMESH eMesh, iTEXTURE eTexture, uint nSrcBlend, uint nDstBlend )
{
   MeshObject *pObj;
   GLuint iTex;

   pObj = &pStageMesh[ eMesh ];
   if (pObj->nCount)
   {
      glEnable( GL_TEXTURE_2D );
      iTex = GetPixMap( eTexture )->getName();
              // I've verified that iTex is the correct texture name!!!

      glBindTexture(GL_TEXTURE_2D, iTex);
      glEnableClientState( GL_VERTEX_ARRAY );
      glEnableClientState( GL_TEXTURE_COORD_ARRAY );

      if (pObj->pNormAry)
      {
         glEnableClientState( GL_NORMAL_ARRAY );
         glNormalPointer( GL_FLOAT, 0, pObj->pNormAry );
      }

      glVertexPointer( 3, GL_FLOAT, 0, pObj->pVertAry );	
      glTexCoordPointer( 2, GL_FLOAT, 0, pObj->pUVAry );

      glDrawArrays( GL_TRIANGLES, 0, pObj->nCount * 3 );

      glDisableClientState( GL_VERTEX_ARRAY );
      glDisableClientState( GL_TEXTURE_COORD_ARRAY );

      if (pObj->pNormAry)
      {
         glDisableClientState( GL_NORMAL_ARRAY );
      }

// I've tried the followng but didn't help!
//      glBindTexture(GL_TEXTURE_2D, 0);

      glDisable( GL_TEXTURE_2D );
   }
}




  // the following code snippet is included within other code and
  // called for each instance of the object. The Shader constants
  // are set with the object matrix, position and world matrix for the
  // shader to use!

cgGLBindProgram( OdometerCgVertexProgram);

   // Shader constants are setup then the following is called!

cgGLEnableProfile( TheCgVertexProfile );
DrawStageMesh( iMESH_CYLINDER01, eTex, GL_ONE, GL_ZERO );
cgGLDisableProfile( TheCgVertexProfile );
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: OpenGL Wrong Texture Same Shader, Same Mesh

 
0
  #2
Jun 23rd, 2009
Upon further research I've found it is definitely a persistent binding problem. If I assign a second copy of the same shader and bind the alternate texture to it, there is no problem. So there appears to be a problem when the texture bind function being called a second time for a different texture. Anybody know how to get around this problem.

My work around fixed two objects where I used two different textures each, but I have a third object that has 75 selectable textures, and I'm not keen about creating 75 identical shaders even if in a loop!
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: OpenGL Wrong Texture Same Shader, Same Mesh

 
0
  #3
Jun 23rd, 2009
What happens when you use the same mesh, different textures and no shader?

What you're doing looks right to me, assuming that all of your variables and functions are 'correct' with respect to what it is you're doing.
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: OpenGL Wrong Texture Same Shader, Same Mesh

 
0
  #4
Jun 26th, 2009
Exactly the same thing. The textures get shuffled!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC