Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Raduprv

Problems with textures after changing res.

This topic is 5654 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have this problem: Recently, I decided to allow people to change the resolution, color depth, and toggle between full screen and windowed mode. I am using SDL/OpenGL, and the only way I know to do that is to destroy the current context (shut down the video), then restart it with the new settings. Of course, as expected, the textures get lost in the process. Now, the trouble is, I tried many ways to restore them, but none seems to work, which is frustrating... I have this functions:
  
void set_new_video_mode(int mode)
{
	int i;
	//first of all, destroy the current context

	SDL_QuitSubSystem(SDL_INIT_VIDEO);

	//now, reload all the textures...

	for(i=0;i<1000;i++)
		{
			if(texture_cache[i].file_name[0])
				{
					glDeleteTextures(1,&texture_cache[i].texture_id);
					texture_cache[i].texture_id=0;//force a reload

				}
		}

	//experimental

	setup_video_mode(1,4);
	init_video();
	resize_window();

}
  
And this:
  
//get a texture id out of the texture cache

//if null, then reload it (means it was previosly freed)

int get_texture_id(int i)
{
    int new_texture_id;
    unsigned char alpha;

    texture_cache[i].last_access_time=cur_time;
    if(!texture_cache[i].texture_id)
        {
            alpha=texture_cache[i].alpha;
            //our texture was freed, we have to reload it

        	if(alpha==0)new_texture_id=load_bmp8_color_key(texture_cache[i].file_name);
            else
        	new_texture_id=load_bmp8_fixed_alpha(texture_cache[i].file_name, alpha);
        	texture_cache[i].texture_id=new_texture_id;
        }
    return texture_cache[i].texture_id;
}
  
The get texture id function is called whenever drawing an object, so the textures should be reloaded... Do you spot any mistakes here? This is killing me, BTW... Height Map Editor | Eternal Lands | Fast User Directory

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!