OpenGL texture disappearing when window is resized

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
xx6heartless6xx
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 80
Joined: Wed Feb 02, 2011 9:42 pm

OpenGL texture disappearing when window is resized

Post 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();
}
User avatar
szdarkhack
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 61
Joined: Fri May 08, 2009 2:31 am

Re: OpenGL texture disappearing when window is resized

Post 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?
User avatar
xx6heartless6xx
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 80
Joined: Wed Feb 02, 2011 9:42 pm

Re: OpenGL texture disappearing when window is resized

Post 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.
User avatar
xx6heartless6xx
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 80
Joined: Wed Feb 02, 2011 9:42 pm

Re: OpenGL texture disappearing when window is resized

Post by xx6heartless6xx »

Has anyone else gotten this problem before?
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: OpenGL texture disappearing when window is resized

Post 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...
User avatar
xx6heartless6xx
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 80
Joined: Wed Feb 02, 2011 9:42 pm

Re: OpenGL texture disappearing when window is resized

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