开发者

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

开发者 https://www.devze.com 2023-03-25 14:12 出处:网络
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 bo

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开发者_如何学C of OpenGL to render and SDL for events.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消