PDA

View Full Version : SDL/OpenGL Help?


monjardin
02-24-2009, 02:33 PM
This is a stripped down program that should fill the screen with white:

#include <SDL.h>
#include <SDL_opengl.h>

static void
resize(int width, int height)
{
printf("Resizing window: %d x %d", width, height);

SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, SDL_TRUE);

if (NULL == SDL_SetVideoMode(width, height, 32, SDL_OPENGL | SDL_RESIZABLE)) {
printf("Could not open OpenGL context: %s", SDL_GetError());
exit(EXIT_FAILURE);
}

glViewport(0, 0, width, height);

glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
}

int
main(int argc, char *argv[])
{
SDL_Event event;

if (-1 == SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE)) {
printf("Could not initialize SDL: %s", SDL_GetError());
exit(EXIT_FAILURE);
}
atexit(SDL_Quit);

resize(640, 480);

for (;;) {
while (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_QUIT:
exit(EXIT_SUCCESS);
break;
case SDL_VIDEORESIZE:
resize(event.resize.w, event.resize.h);
break;
default:
break;
}
}

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 1, 0, 1, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glColor4f(1, 1, 1, 1);
glBegin(GL_TRIANGLE_FAN); {
glVertex2i(0, 0);
glVertex2i(1, 0);
glVertex2i(1, 1);
glVertex2i(0, 1);
} glEnd();

SDL_GL_SwapBuffers();
}

exit(EXIT_SUCCESS);
}


However, when I resize the window the quad gets clipped at a certain width and height as shown by the black in following the image:

http://img7.imageshack.us/img7/7204/screenjcf.th.jpg (http://img7.imageshack.us/my.php?image=screenjcf.jpg)

Am I doing something stupidly obvious that I can't happen to find at the moment?

Reedbeta
02-24-2009, 03:23 PM
The OpenGL part looks good to me. I'm not super familiar with SDL, though. Have you verified it's actually sending SDL_VIDEORESIZE events when the window is resized?

monjardin
02-24-2009, 04:01 PM
Well, it's working on my Linux box at home. So, perhaps there is something else going on with the setup I was using on Vista...

SmokingRope
02-24-2009, 08:22 PM
Some googling revealed this thread: http://lists.libsdl.org/pipermail/sdl-libsdl.org/2008-November/067309.html

If you follow the thread down the same guy points out that the entire OpenGL context is destroyed on windows machines. There also are some comments about related problems being corrected in SDL v1.3