8
votes

I have got a very, very strange problem in my C++ OpenGL application.

I simply load a texture and apply it to a quadric:

glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

Then

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, tex);
gluQuadricDrawStyle(quad,GLU_FILL);
gluQuadricTexture(quad,GL_TRUE);
gluCylinder(quad,1,0,2,20,1);
glDisable(GL_TEXTURE_2D);

Now: it works perfectly 9 times out of ten, but sometimes the texture isn't shown (the quadric stays white).

The image is correctly loaded, so the problem should be with OpenGL. I have tried with several different images too. Always GL_NO_ERROR.

Any idea ? It is driving me crazy...

2
Kinda silly but on the times where it doesn't load, if you minimize then maximize the window, does it appear? - Robb
No, it doesn't load, even if I minimize/maximize. - TheDude
Can you test it on a different PC or with different drivers? - Maurice Gilden
By "texture isn't shown" do you mean when you restart the application? - Xavier Ho

2 Answers

2
votes

Found :) It was the GLint texture member that wasn't correctly reallocated in the copy constructor.

However, i still don't understand why it worked sometimes...

1
votes

The code you are using seems valid. Have you ...

  • tried to use a simple quad instead of the quadric
  • assured that image is filled correctly
  • verified that tex is not altered somewhere else
  • assured that no other programs are using opengl at the same time
  • restarted your computer ;)