Sign in to follow this  
billconan

question about how to setup gl with sdl

Recommended Posts

billconan    200
hi guys, i found some tutorials about how to setup gl with sdl, but i still do not understand. i do not know why those tutorials set the color bit to 5, like this: SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 ); i think they should use 8 instead of 5, if the color is 32-bit-long like 255,255,255,255 and i also do not understand the bpp value in the function: /* Color depth in bits of our window. */ int bpp = 0; SDL_SetVideoMode( width, height, bpp, flags ) what is the difference between bpp and those color attributes? if the bpp has already indicated the color depth, why should i set the color attributes again? one more thing is, i want my app to use the current resolution, but i do not know how to get it. i checked the official sdl site, it says that sdl do not have the function of getting current resolution, and users have to implement it by themselves. but i do not know how to do it, say under windows xp. thank you.

Share this post


Link to post
Share on other sites
Kalidor    1087
I don't have much experience with SDL so I can't answer anything specifically on that. Perhaps whoever wrote those tutorials wanted a 16-bit color depth instead of 32-bit (R5_G5_B5_A1 is a pretty common 16-bit depth). On Windows you can get the current resolution with EnumDisplaySettings.

Share this post


Link to post
Share on other sites
Dragon88    246
The reason why they set the color bits to 5 is because they're using 15 bit color. As for why they send a bpp of 0, I don't know.
You have to set the GL color attributes, because the SDL_SetVideoMode only effects the screen attributes, to put it briefly.
If you want to use conventional 32 bit color, you need to pass 32 to SDL_SetVideoMode, and set the GL color sizes to 8 (including SDL_GL_ALPHA_SIZE).

To get the current resolution under windows, you can use code like:

RECT desktopRect;

GetWindowRect(GetDesktopWindow(), &desktoprect);

Then the width of the current display will be desktopRect.right - desktopRect.left and the height will be desktopRect.bottom - desktopRect.top.

Share this post


Link to post
Share on other sites
Grudzio    122
When OpenGL is used with SDL, the bpp parameter in SDL_SetVideoMode is ignored.
The color sizes passed to SDL_GL_SetAttribute are only hints, so you may or may not get what you asked for. From my experience it only depends on desktop color mode. If it is set to 32bpp you will get 8 bits per color, if set to 16bpp you will get 5 bits per color. In theory calling SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, your_bpp_value) should set the bits per pixel for OpenGL context. But, at least for me, it is not working.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this