Jump to content


SDL/OpenGL Help?


3 replies to this topic

#1 monjardin

    Senior Member

  • Members
  • PipPipPipPip
  • 1033 posts

Posted 24 February 2009 - 10: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:

Posted Image

Am I doing something stupidly obvious that I can't happen to find at the moment?
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 4782 posts
  • LocationBellevue, WA

Posted 24 February 2009 - 11: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?
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 monjardin

    Senior Member

  • Members
  • PipPipPipPip
  • 1033 posts

Posted 25 February 2009 - 12:01 AM

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...
monjardin's JwN Meter (1,2,3,4,5,6):
|----|----|----|----|----|----|----|----|----|----|
*

#4 SmokingRope

    Valued Member

  • Members
  • PipPipPip
  • 210 posts

Posted 25 February 2009 - 04:22 AM

Some googling revealed this thread: http://lists.libsdl....ber/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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users