#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:

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












