Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Problem with texture binding while drawing multiple objects

Hybrid View

  1. #1
    Newbie Newbie
    Join Date
    Feb 2013
    Posts
    2

    Problem with texture binding while drawing multiple objects

    Dear all, I'm a beginer to OpenGL, this problem confused me for a whole afternoon.
    Problem is that, all objects with various textures are drawn with only one texture, even if I call glBindTexture to bind different textures to different objects each frame, it seems like only one glBindTexture call works. This is code of unwrapped draw call:


    Code :
            m_pProgram->Use();
    	SetUpMatrix();
     
            // This is the diffuse texture
            // m_pMat->GetTexDif() return different texture names with different objects
    	glActiveTexture(GL_TEXTURE0);                                   
    	glBindTexture(GL_TEXTURE_2D, m_pMat->GetTexDif());
    	glUniform1i(LOCATION_TEX_DIFF, 0);
     
             // This is the normal texture
    	glActiveTexture(GL_TEXTURE1);                                   
    	glBindTexture(GL_TEXTURE_2D, m_pMat->GetTexNormal());
    	glUniform1i(LOCATION_TEX_NORM, 1);
     
            glBindVertexArray(m_uVAO);
    	glDrawElements(GL_TRIANGLES, m_uFaceNum * 3, GL_UNSIGNED_INT, (void*)0);
     
            // query current binding texture, result is different among different draw calls
            // but the shader still get same one, so strange.
    	int currentTex;
    	glGetIntegerv(GL_TEXTURE_BINDING_2D, &currentTex);
    	printf("current binding texture: %d\n", currentTex);

    The shader does get both diffuse texture and normal texture, however, all objects get same ones.

    Can anyone find how does this error happen? Appreciate.
    By the way, I'm using Win7 64bit, Nvidia Geforce GTX560, OpenGL/GLSL 4.3 with newest driver, GLEW 1.9.0 and GLFW 2.7.6

  2. #2
    Newbie Newbie
    Join Date
    Feb 2013
    Posts
    2
    Solved, nothing wrong with glBindTexture, I used nvidia nsight check the texture passed into the shader, I found textures are all correct, however, the mesh is so wrong that it contains all objects' mesh before it, due to a stupid bug. Thanks to Nsight, amazing tools!

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    Did you use 3.0? Is the GL frame debugging stuff any good? Last I checked, the only thing worth analyzing was the timeline.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •