Page 1 of 1

OpenGL texture disappearing when window is resized

Posted: Wed Sep 14, 2011 12:35 am
by xx6heartless6xx
I have a small tile rendered on the top left corner of my window and whenever I try to make the window longer vertically, the texture starts to disappear. This only occurs when I stretch the screen vertically and stretching the screen horizontally works fine. I used the search feature here in the forums and others have had similar problems but none where the texture was disappearing. Btw this is in Qt with rendering in OGL. How can I keep the texture from disappearing when I resize the window vertically?

Here is my resize window function:

Code: Select all

void GLWidget::resizeGL(int width, int height) {
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();

    glViewport( 0, 0, width, height );
    glOrtho( 0.0, width, height, 0.0, -1.0, 1.0 );

    //Initialize modelview matrix
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
}
And my rendering function is as follows:

Code: Select all

void GLWidget::paintGL() {
    glClear(GL_COLOR_BUFFER_BIT);

    glBindTexture( GL_TEXTURE_2D, imageID );
    
    glBegin( GL_QUADS );
        glTexCoord2f( 0.0, 1.0 );                           glVertex3f( 0.0,  0.0, 0.0 );
        glTexCoord2f( 32.0 / 128.0, 1.0 );              glVertex3f( 32.0, 0.0, 0.0 );
        glTexCoord2f( 0.0, 32.0 / 64.0 );                glVertex3f( 32.0, 32.0, 0.0 );
        glTexCoord2f( 32.0 / 128.0, 32.0 / 64.0  );  glVertex3f( 0.0, 32.0, 0.0 );
    glEnd();
}

Re: OpenGL texture disappearing when window is resized

Posted: Wed Sep 14, 2011 2:48 am
by szdarkhack
I'm not sure about your disappearing texture, your resize seems to be ok. Your texturing is wrong, however. The last 2 texCoords should be in the reverse order (according to the vertices you have defined). Does the texture disappear instantly or gradually?

Re: OpenGL texture disappearing when window is resized

Posted: Wed Sep 14, 2011 3:04 am
by xx6heartless6xx
szdarkhack wrote:I'm not sure about your disappearing texture, your resize seems to be ok. Your texturing is wrong, however. The last 2 texCoords should be in the reverse order (according to the vertices you have defined). Does the texture disappear instantly or gradually?
Thanks for catching that for me. And the texture disappears gradually.

Re: OpenGL texture disappearing when window is resized

Posted: Wed Sep 14, 2011 6:20 pm
by xx6heartless6xx
Has anyone else gotten this problem before?

Re: OpenGL texture disappearing when window is resized

Posted: Thu Sep 15, 2011 10:13 am
by Falco Girgis
I know with SDL, the OpenGL context is destroyed completely when you resize the window... you're literally supposed to reload all textures in this event... I'm guessing this is a QT widget? I can't say for sure that it works the same way, but the symptoms are oddly similar...

Re: OpenGL texture disappearing when window is resized

Posted: Fri Sep 16, 2011 2:54 am
by xx6heartless6xx
GyroVorbis wrote:I know with SDL, the OpenGL context is destroyed completely when you resize the window... you're literally supposed to reload all textures in this event... I'm guessing this is a QT widget? I can't say for sure that it works the same way, but the symptoms are oddly similar...
If that is the case, then shouldn't my texture disappear when I shrink the window or stretch the window horizontally?

I'll report back if I fix the problem.