views:

107

answers:

2

Hello,

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

A: 

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 ;)
Danvil
A: 

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

TheDude