SDL_GL_SetAttribute and rgb framebuffer component sizes

Started by
6 comments, last by evillive2 18 years, 11 months ago
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.
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.
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.
"When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy."
How to Ask Questions the Smart Way.
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.
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.

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.
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.
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.

Evillive2

This topic is closed to new replies.

Advertisement