[SDL] OpenGL and SDL integration

Alex Barry alex.barry at gmail.com
Fri Jan 6 06:40:28 PST 2006


I'm attempting to integrate OpenGL into SDL by including <GL\gl.h> instead
of doing all this weird dynamic stuff (because I have no idea how to do it)

Anyway, whenever I startup the videa with the SDL_OPENGL flag, the video
doesn't work and it aborts (without going through my error checking)

Any thoughts?

Alex~

Here's some code, too:
class ScreenData
{
    public:

    void set( int xres, int yres, int bbp, Uint32 flags );    /* Set video
(will clear previous page if set) */
    void setgl( int xmin, int ymin, int xmax, int ymax );    /* set opengl
window */

    SDL_Surface *page;                                        /* Screen
Surface */
};

void ScreenData::set( int xres, int yres, int bbp, Uint32 flags )
/*
    sets the video mode appropriately
*/
{
    if( page )
    {
         SDL_FreeSurface( page );                        /* If there is an
existant page, clear it */
    }
    page = SDL_SetVideoMode (xres, yres, bbp, flags );    /* Reset the page
to the current */
    if( page == NULL )
    {
         char* msg;
        sprintf( msg, "Couldn't set %dx%dx%d video mode: %s\n", xres, yres,
bbp, SDL_GetError ( ) );
        MessageBox( 0, msg, "Error", MB_ICONHAND );
        free( msg );
        exit( 2 );
    }
}
void ScreenData::setgl( int xmin, int ymin, int xmax, int ymax )
/*
    Setup OpenGL video
*/
{
    glViewport(xmin, ymin, xmax, ymax);
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClearDepth(1.0);
    glDepthFunc(GL_LESS);
    glEnable(GL_DEPTH_TEST);
    glShadeModel(GL_SMOOTH);
    glMatrixMode(GL_PROJECTION);
    glMatrixMode(GL_MODELVIEW);

}
/* #################################### */

int main (int argc, char *argv[])
{
    char *msg;
    int done;

    /* Initialize SDL */
    if (SDL_Init (SDL_INIT_VIDEO) < 0)
    {
        sprintf (msg, "Couldn't initialize SDL: %s", SDL_GetError ());
        progshutdown( screen.page, true, "SDL Initialization Error", msg, 27
);
    }
    atexit (SDL_Quit);

    if(TTF_Init()==-1) {
        sprintf (msg, "Couldn't initialize SDL_ttf: %s\nError Code: 0x02",
TTF_GetError() );
        MessageBox (0, msg, "Error", MB_ICONHAND);
        free (msg);
        exit(2);
    }
    atexit( TTF_Quit );

    screen.set( 800, 600, 16, SDL_OPENGL | SDL_HWSURFACE | SDL_NOFRAME );
    screen.setgl( 0, 0, 800, 600 ); // this sets up the opengl window view
port and such...

    SDL_WM_SetCaption ("Atosoft++ (c) 2006", NULL);
    // there's more, but it's irrelevant
}

--
Smith: "...Why, Mr Anderson, Why - Do - You - Persist?"
Neo: "Because I choose to."
-Matrix Revolutions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20060106/8358f31e/attachment.htm>


More information about the SDL mailing list