Jump to content
  • Advertisement
Sign in to follow this  
okonomiyaki

SDL_GL_SetAttribute and rgb framebuffer component sizes

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
Don't use SDL enough to answer the rest of your question, but
Quote:
Original post by okonomiyaki
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.
Alpha in the framebuffer is needed if you want to use destination blending.

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by okonomiyaki
To 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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!