SDL_GL_SetAttribute problem

According to the Doc Wiki, SDL_GL_SetAttribute() should be called before
SDL_SetVideoMode().

The attributes I’m trying to set is the color size:
//Set Colors

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_ALPHA_SIZE, 8 );

In windows, it doesn’t seem to care if I set the colors before or after. On
Linux the program will crash if I don’t set the colors -after- calling
SDL_SetVideoMode().

So what’s going on here?

In windows, it doesn’t seem to care if I set the colors before or after. On
Linux the program will crash if I don’t set the colors -after- calling
SDL_SetVideoMode().

So what’s going on here?

It shouldn’t crash before SetVideoMode…the function calls are
meaningless after the video mode is set.

Likely there isn’t a GL library loaded. Try SDL_GL_LoadLibrary() before
the SDL_GL_SetAttribute() calls. SDL_SetVideoMode() with SDL_OPENGL
forces SDL to load a default GL library if one isn’t yet loaded, which
is why it ceases to crash at that point.

So do this, in this order:

  • SDL_Init
  • SDL_GL_LoadLibrary
  • SDL_GL_SetAttribute
  • SDL_SetVideoMode
  • (the rest of your program)
  • SDL_Quit

–ryan.