Advertisement

Texture binding and toggling screen mode

Started by December 27, 2004 07:25 PM
6 comments, last by Ruudje 19 years, 8 months ago
Hi. Apparently I'm relatively new to OpenGL programming. Right now I have to use the code below each frame. When I toggle between fullscreen/windowed mode and use the code below only once ... ( and glBindTexture(GL_TEXTURE_2D, m_TexId); each frame ) ... the texture disappears. I guess there is something seriously wrong with the design I chose? How is this usually done? Or does a program generally have to go through all the textures whenever the window has been killed and recreated?

        // create new texture
        glGenTextures(0, &m_TexId);
        // bind the texture
        glBindTexture(GL_TEXTURE_2D, m_TexId);
        // set texture stuff
        glTexParameteri(
            GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR );
        glTexParameteri(
            GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,
            GL_LINEAR_MIPMAP_NEAREST );
        gluBuild2DMipmaps(
            GL_TEXTURE_2D, m_Bpp, m_Width, m_Height, m_Type,
            GL_UNSIGNED_BYTE, m_pImageData );

Writing errors since 10/25/2003 2:25:56 AM
Unless it's just a typo, the line 'glGenTextures(0, &m_TexId);' should be 'glGenTextures(1, &m_TexId);'. If it is just a typo then you should check that your pixel data 'm_pImageData' is valid before the call to it.

In answer to your question, yes you do have to re-create your textures when you toggle from windowed to fullscreen. The reason is a little out of my knowledge but I suspect it has to do with the rendering context for OpenGL changing, therefore meaning you have to re-create your textures.

Hope this helped.
--
Cheers,
Darren Clark
Advertisement
I'm sure he may have this question too but what about resolution switching seems to me with the way the window is setup, to switch the resolution you'd hve to destroy the context and recreate it.
Yes, that's correct. To change resolution (NOT dimensions) you must destroy and re-create the window.
--
Cheers,
Darren Clark
Ehm, why is that?

I usually set up a window of X x Y pixels and then change the resolution through the win32 api. I don not have to create a new window for that... I do have to resize it and pass that new size to opengl though. I have never run into this problem.

Look up

ChangeDisplaySettings(...)

on MSDN and see if you have use for it.
Thank you very much for the replies.

It was not a typo btw. I did create 0 texture names.

I think ChangeDisplaySettings is used in the newer version of the basecode.
I'll just kill/recreate the window and tell the resource manager to recreate the textures.
Later I'll take a closer look at the Win32 specific rendering stuff.

Thanks again.
Writing errors since 10/25/2003 2:25:56 AM
Advertisement
Interesting. You live and learn eh? I shall look into that function when I have more time on my hands, cheers for that one mate.
--
Cheers,
Darren Clark
If you need help just shout.

This topic is closed to new replies.

Advertisement