What are the usual troubleshooting steps for OpenGL textures not showing? [closed]
Asked Answered
W

5

15

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?

Willawillabella answered 11/4, 2009 at 14:9 Comment(4)
Do you not see just textures, or also objects when they are textured?Tempered
Hmm, well I know the objects are there as I said, but I can't be certain that they aren't disappearing somehow (although thats unlikely, as introducing colour is just 1 code change)...Willawillabella
So you do see objects though they are not textured? E.g. in some coloring but without textures?Tempered
Yes, "I can see the vectors (when colored instead of textured)." by simply introducing glColor3f(0, 0, 1.0); before the vector I see a blue square.Willawillabella
T
12

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

Tempered answered 11/4, 2009 at 14:26 Comment(3)
Even though I had both these, the issue still wasn't resolved. After doing some heavy refactoring, it started working again. I suspect it was perhaps a translation issue, but thanks for the suggestions anyway; I have accepted this answer as it has the highest upvotes! :)Willawillabella
I did have a problem with my textures, and calling glEnable(GL_TEXTURE_2D); fixed my problem. Thank you.Gant
In my case, glUseProgram(0) resolved the issue, because on another place of my code I forgot to reset that.Pachisi
L
7

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);
Lizarraga answered 21/3, 2013 at 22:50 Comment(1)
thank you for this, it saved my bacon with OpenGL 4.1+Opaque
R
3

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.
Rigid answered 12/4, 2009 at 1:18 Comment(0)
P
1

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

Pacifically answered 28/8, 2012 at 3:55 Comment(0)
S
-1

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.

Sallie answered 25/11, 2016 at 10:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.