What are the usual troubleshooting steps for OpenGL textures not showing?

时光怂恿深爱的人放手 提交于 2019-12-17 19:34:13

问题


After making a few changes in my application, my textures are no longer showing. So far I've checked the following:

  • The camera direction hasn't changed.
  • I can see the vectors (when colored instead of textured).

Any usual suspects?


回答1:


You may want to check the following:

  • glEnable(GL_TEXTURE_2D); presence

  • glBindTexture(GL_TEXTURE_2D, texture[i]); and glBindTexture(GL_TEXTURE_2D, 0); when you don't need texture anymore




回答2:


A few more things to check:

  • glColorMaterial(...); To make sure colors aren't overwriting the texture
  • glEnable/glDisable(GL_LIGHTING); Sometimes lighting can wash out the texture
  • glDisable(GL_BLEND); Make sure that you're not blending the texture out
  • Make sure the texture coordinates are set properly.



回答3:


One common problem I run into from time to time is

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);

but I forgot to supply mipmaps. Quickfix:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);



回答4:


Does a glColor3ub(255,255,255) before rendering your textured object help? I think the default OpenGL state multiplies the current glColor by the incoming texel; a stray glColor3ub(0,0,0) will make all your textures look black.




回答5:


I assume you had the must have operations implemented like glEnable(GL_TEXTURE_2D) and the texture binding since your textures worked fine before and then suddenly they just won't show.

If you are doing Object Oriented code you might want to have the texture generation happen when the thread that is actually doing the draw is instanced, in other words: avoid doing it in constructors or a call coming from a constructor, this might instance your texture object before the window or the app that is going to use it is on.

What I usually do is that I create a manual Init function of the texture creation that is called in the Init function of the App. Therefore I guarantee that the App exist when the binding occurs.

More info here: http://www.opengl.org/wiki/Common_Mistakes#The_Object_Oriented_Language_Problem




回答6:


Took me some while to figure this out...

glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);
glDisable(GL_TEXTURE_GEN_Q);

Also make sure to unbind your stuff:

glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
glBindVertexArray(0);

If you use a third party engine, which is optimized, it probably has a "direct state access" layer for OpenGL (to not use the slow OpenGL query functions). If so, don't call OpenGL directly, but use the engine wrappers. Otherwise your code doesn't play nice with the rest of the engine code.



来源:https://stackoverflow.com/questions/740151/what-are-the-usual-troubleshooting-steps-for-opengl-textures-not-showing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!