• Advertisement
Sign in to follow this  

[SDL] Resizing A Fullscreen Window Problem

This topic is 4166 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

Hey, I'm using C++ + OpenGL + SDL and I'm having a problem with resizing a fullscreen window. The problem is that the application freezes (?) or just doesn't take input anymore. This is called after a user writes down a "resize" command in console (the application is already running):
	if(command.substr(0, 6) == "resize") // use only at your own risk
	{
		cfg->WIDTH = atoi(command.substr(7, command.find_last_of(" ")).c_str());
		cfg->HEIGHT = atoi(command.substr(command.find_last_of(" "), command.length()).c_str());
		tools->writeLog("New Width: %d", cfg->WIDTH);
		tools->writeLog("New Height: %d", cfg->HEIGHT);
		screen = SDL_SetVideoMode(cfg->WIDTH, cfg->HEIGHT, cfg->BPP, SDL_OPENGL | SDL_FULLSCREEN);
		int r, g, b, a;
		getPalette(r, g, b, a);
		SDL_GL_SetAttribute(SDL_GL_RED_SIZE, r);
		SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, g);
		SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, b);
		SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, a);
		SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
		SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
		SDL_WM_SetCaption(STR_APPNAME, NULL);
		resize(cfg->WIDTH, cfg->HEIGHT);
		init();
		initFont("Arial", 12);
		initFPSMeter();
		initConsole();
		initTextures();
	}
The SDL, OGL init and resize functions:
Core::Core(int depth)
{    

	// load the config
	cfg = new Config(STR_CFG_FILE);

	// set the tools
	tools = new Tools();

	// player
	player = new Player(0);

	// start the game(?)
	game = new Game(tools);

	// set the texloader
	loader = new Texloader(tools, cfg);

	tools->writeLog("Start");
	// SDL
	done = false;
	moves = 0.0;
	int r, g, b, a;
	SDL_Event event;

	if(SDL_Init(SDL_INIT_VIDEO) < 0)
	{
		tools->writeLog(STR_ERR_SDLINIT);
		exit(1);
	}
	atexit(SDL_Quit);

	// load r,g,b,a and default bpp (if invalid)
	getPalette(r, g, b, a);

	// screen stuff
	screen = SDL_SetVideoMode(cfg->WIDTH, cfg->HEIGHT, cfg->BPP, SDL_OPENGL | SDL_FULLSCREEN);
	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, r);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, g);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, b);
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, a);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, depth);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_WM_SetCaption(STR_APPNAME, NULL);

	resize(cfg->WIDTH, cfg->HEIGHT);
	SDL_ShowCursor(SDL_DISABLE);
	init();
	initFont("Arial", 12);
	initFPSMeter();
	initConsole();
	initTextures();
/*
...some code...
*/
	SDL_FreeSurface(screen);
}

void Core::init()
{
	glShadeModel(GL_SMOOTH);
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
	glClearDepth(1.0f);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glEnable(GL_TEXTURE_2D);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	glEnable(GL_ALPHA_TEST);
	glAlphaFunc(GL_GREATER, 0);
}

void Core::resize(int width, int height)
{
	if(height == 0)
		height = 1;
	glViewport(0, 0, width, height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f, (GLfloat)width / (GLfloat)height, 0.05f, 100.0f);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	mouseCenter.x = width / 2;
	mouseCenter.y = height / 2;
}
Any ideas? Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement