OpenGL and Mesa

SDL Example


    /* Information about the current video settings. */
    const SDL_VideoInfo* info = NULL;
    int width = 0;
    int height = 0;
    int bpp = 0;
    int flags = 0;

    /* First, initialize SDL's video subsystem. */
    if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
        /* Failed, exit. */
    }

    /* Let's get some video information. */
    info = SDL_GetVideoInfo( );

    if( !info ) {
        /* This should probably never happen. */
    }

    /* Set width/height */
    width = 640;
    height = 480;
    bpp = info->vfmt->BitsPerPixel;

    /* Request GL attributes */
    SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
    SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
    SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
    SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

    /* Set SDL to provide a FullScreen OpenGL window */
    flags = SDL_OPENGL | SDL_FULLSCREEN;

    /* Set the video mode */
    if( SDL_SetVideoMode( width, height, bpp, flags ) == 0 ) {
        /* 
         * This could happen for a variety of reasons,
         * including DISPLAY not being set, the specified
         * resolution not bbeing available, etc.
         */
        fprintf( stderr, "Video mode set failed: %s\n",
    }


[Next] [Contents]