# SDL_GL_SetAttribute and rgb framebuffer component sizes

This topic is 4992 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

According to the documentation of SDL, you can set the size of the red/green/blue framebuffer component in bits with SDL_GL_SetAttribute and passing SDL_GL_RED_SIZE or such. My question is, how exactly does this differ than screen bpp? I see code that passes 5 for all rgb components: SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 ); First of all, shouldn't the green size be 6 if its 16 bpp? And if you set these values, but then set the screen to 24 or 32 bpp, isn't it still clamped by the 16-bit framebuffer? Because I also see code that passes 8 for all the components. I haven't seen any code that really checks for the bpp, such as:
	switch(bpp) {
case 16:
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 6 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
break;
case 24:
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
break;
default: break;
}


Also, can someone clarify the difference between 24 and 32 bpp? I know that 32 would include an alpha component, but a screen doesn't exactly display alpha itself.

##### Share on other sites
Don't use SDL enough to answer the rest of your question, but
Quote:
 Original post by okonomiyakiAlso, can someone clarify the difference between 24 and 32 bpp? I know that 32 would include an alpha component, but a screen doesn't exactly display alpha itself.
Alpha in the framebuffer is needed if you want to use destination blending.

##### Share on other sites
You can do:
SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );

and use the extra bit for alpha. Of course you video card has to support this mode, but many do.

##### Share on other sites
Right, but for the actual screen bpp, what does 32 bits matter?

You pass in a bpp value when calling SDL_SetVideoMode as well, and I'm assuming that's the screen bpp. I usually see 16 or 32 passed in.

But I can understand the need for the alpha component in the framebuffer for blending. Am I getting this confused? To clarify what I'm thinking: there is a bpp for the framebuffer, and a bpp for the screen?

Edit: thanks codemunkie (replied while I was). Ok that explains that bit.

Thinking about it over, I'm confused and tired. I get it now. You set the individual bits for rgb values, and also pass in the total bpp to SetVideoMode. got it.

##### Share on other sites
Quote:
 Original post by okonomiyakiTo clarify what I'm thinking: there is a bpp for the framebuffer, and a bpp for the screen?
No, they are the same thing, at least in this context.

##### Share on other sites
The way I see it, it's more of a request for the minimal bpp for that color.
Quote:
 /* * Now, we want to setup our requested * window attributes for our OpenGL window. * We want *at least* 5 bits of red, green * and blue.

To be sure though, try this: after you set the video mode, make a call to SDL_GL_GetAttribute to see really what happened. Try that for both when you set 16/32 bpps.

##### Share on other sites
Quote:
Original post by Drew_Benton
The way I see it, it's more of a request for the minimal bpp for that color.
Quote:
 /* * Now, we want to setup our requested * window attributes for our OpenGL window. * We want *at least* 5 bits of red, green * and blue.

To be sure though, try this: after you set the video mode, make a call to SDL_GL_GetAttribute to see really what happened. Try that for both when you set 16/32 bpps.

Yep, you're right. I request 16 bit mode but it gave me 32 bit (each component was 8 bits).

Cool. Thanks guys.

##### Share on other sites
Thanks guys. This was most helpful. I am moving to OpenGL for all my 2d graphics needs and stuff like this that is usually just copy/pasted without knowing why is a real help when it is explained.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 13
• 9
• 9
• 15
• ### Forum Statistics

• Total Topics
634078
• Total Posts
3015370
×