Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL texture randomly not shown

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...

like image 525
TheDude Avatar asked Apr 27 '10 19:04

TheDude


2 Answers

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...

like image 193
TheDude Avatar answered Oct 22 '22 20:10

TheDude


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 ;)
like image 24
Danvil Avatar answered Oct 22 '22 21:10

Danvil