LunchMarble
LunchMarble

Reputation: 5141

How do I render with OpenGL but still use SDL for events?

I want to make sure I am using OpenGL for 2d rendering, but SDL for events. From what I have heard SDL uses software rendering, and OpenGL is hardware accelerated. I am in the middle of reading one book on SDL, but it has not yet mentioned the use of OpenGL to render and SDL for events.

Upvotes: 1

Views: 579

Answers (1)

ssell
ssell

Reputation: 6597

You can start by reading: http://www.gpwiki.org/index.php/SDL:Tutorials:Using_SDL_with_OpenGL

You will use SDL to create an OpenGL context within which you will do all of your OpenGL based rendering.

By events do you mean user input? If so, then simply at the end of each frame/loop make use of SDL to check for input like so:

int main( )
{
    ...

    while( running )
    {
        ...

        update( );
        draw( );

        ...

        handleKeys( );
    }

    return 0;
}

void handleKeys( )
{
    SDL_Event event;

    while( SDL_PollEvent( &event ) )
    {
        switch( event.type )
        {
        case SDL_KEYDOWN:
            //Check for event and act accordingly
            break;

        case SDL_KEYUP:
            //Check for event and act accordingly
            break;

        case SDL_MOUSEBUTTONDOWN:
            //Check for event and act accordingly
            break;

        default:
            break;
        } 
    }
}

Obviously there are much more elegant and effective means of getting input but just wanted to show a simple example.

Upvotes: 5

Related Questions