PDA

View Full Version : Texture disappears!



nrst87
03-13-2012, 05:47 AM
I load a HDR image as a texture and I wrote shaders to map the 2 texture to a sphere but texture disappears when I click on it or when I resize the window! Here is my code for display function:
<code>
void Draw()
{
qobj = gluNewQuadric();
gluQuadricTexture(qobj,GL_TRUE);

model->GetFaces();

glEnable(GL_CULL_FACE);

glFrontFace(GL_CW /* or GL_CCW */); //default is GL_CCW
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);



glLoadIdentity();

glPushMatrix();
glTranslatef(tx,ty,0);
glRotatef(rotx,1,0,0);
glRotatef(roty,0,1,0);

LShader.bind();
glEnable(GL_TEXTURE_2D );
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D , texture);
gluSphere(qobj,1,30,30);
int texture_location = glGetUniformLocation(LShader.GetID(), "color_texture");
glUniform1i(texture_location, texture);



gluDeleteQuadric(qobj);

glDisable(GL_TEXTURE_2D);


LShader.unbind();
glPopMatrix();
glutSwapBuffers();
};
</code>

Thanks in advance

Bruce Wheaton
03-13-2012, 01:46 PM
Your code for the texture setup and clean-up and also mouse actions would be more relevant.

Bruce

(and this probably isn't an 'advanced' topic, btw)

V-man
03-13-2012, 04:20 PM
That kind of problem is documented in "GLSL : common mistakes"

http://www.opengl.org/wiki/GLSL_:_common_mistakes#Binding_A_Texture