SDL/OpenGL color depth question

Started by
1 comment, last by Brother Erryn 21 years, 1 month ago
I''m creating an OGL window through SDL with this command: SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, 32, flags ) But all the sample code I''ve seen precedes this with this code: 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_DEPTH_SIZE, 32 ); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); It doesn''t make any noticeable difference whether I do the SetAttributes or not. There''s no obvious visual difference, and the framerate is identical (windowed or fullscreen). So my question is, what''s the point of the SetAttribute? The documentation I''ve seen on it isn''t clear in that regard.
Advertisement
It''s for several reasons.
1. So you can set depth-buffer depth.
2. Passing "SDL_DOUBLEBUF" to SDL_SetVideoMode sets up 2D double buffering, not 3d.
So to get double-buffered OpenGL, you need
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
3. All the attributes you pass to SDL_GL_SetAttribute have to be known before SDL set the video mode.
Sure, they could have added more arguments to SDL_SetVideoMode, but since SDL doesn''t always use OpenGL, that would be useless for most programs.

BTW, SDL_GL_*_SIZE are minimums, if you don''t set them, it''s possible to get a 111 surface (1 red bit , 1 green bit, 1 blue bit).
(You probably wouldn''t see that outside of a SGI machine though.)

And if you don''t set SDL_GL_DEPTH_SIZE, you might not get a depth-buffer.

So you should set them before you call SDL_SetVideoMode.
Something like this should be fine:
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 ); 

Remember that they are minimums, setting the RGB bits to 555 means you should still be able to get a surface on a 16-bpp screen. At 24/32, you''ll probably get 888.
All minimums? Ah, something understandable.

This topic is closed to new replies.

Advertisement