SDL_Color question

I’ve been working with colors lately, and I’m a bit confused by the SDL_Color format. It’s a 4-byte struct made up of R, G, B, and unused bytes. Anything that requires RGBA takes a one-byte A value separately. Why not just define SDL_Color as R, G, B, and A?

I’ve been working with colors lately, and I’m a bit confused by the
SDL_Color format.? It’s a 4-byte struct made up of R, G, B, and unused
bytes.? Anything that requires RGBA takes a one-byte A value separately.
Why not just define SDL_Color as R, G, B, and A?

I think you are confusing color formats with pixel formats. Pixels
can have R,G,B, and Alpha components. (Some people even think of
values stored in the Z, Stencil, and the accumulations buffers, as
being part of a pixel.) But, color when represented using the R,G,B
color space, is a three element vector that selects a single point in
a three dimensional space just the same way that X,Y,Z select in a
single point in our normal dimensional space.

So, alpha is not part of color, even though it is part of a pixel.
Alpha is a coefficient used to scale color values during some
operations that combine color values, but it is not a part of a color.

Bob PendletonOn Wed, Nov 18, 2009 at 1:57 PM, Mason Wheeler wrote:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


±----------------------------------------------------------

If so, it would seem I’m not the only one confused on this point. For
example, see the SDL_SetRenderDrawColor API, which takes four
one-byte parameters. (Why does it take four one-byte parameters
when we have a SDL_Color struct already defined?)________________________________
From: bob@pendleton.com (Bob Pendleton)
Subject: Re: [SDL] SDL_Color question

On Wed, Nov 18, 2009 at 1:57 PM, Mason Wheeler <@Mason_Wheeler> wrote:

I’ve been working with colors lately, and I’m a bit confused by the
SDL_Color format. It’s a 4-byte struct made up of R, G, B, and unused
bytes. Anything that requires RGBA takes a one-byte A value separately.
Why not just define SDL_Color as R, G, B, and A?

I think you are confusing color formats with pixel formats. Pixels
can have R,G,B, and Alpha components. (Some people even think of
values stored in the Z, Stencil, and the accumulations buffers, as
being part of a pixel.) But, color when represented using the R,G,B
color space, is a three element vector that selects a single point in
a three dimensional space just the same way that X,Y,Z select in a
single point in our normal dimensional space.

So, alpha is not part of color, even though it is part of a pixel.
Alpha is a coefficient used to scale color values during some
operations that combine color values, but it is not a part of a color.

Bob Pendleton


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


±----------------------------------------------------------


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

If so, it would seem I’m not the only one confused on this point.

IMHO, most people who know enough to understand the difference between
a color and a pixel are confused on this point. Another one is the
difference between a pixel and a point. Lots of people never make that
distinction. I was debugging a polygon rendering function when that
fact finally clicked for me. I mean, I knew the difference, but I
hadn’t internalized the difference. It explained all those little
gaps… Or, how many people know the coordinates of the center of the
pixel at X,Y (where X and Y are integer pixel coordinates)? Ok, a lot,
but how long was it after they started doing serious graphics that
they really internalized the difference?

For
example, see the SDL_SetRenderDrawColor API, which takes four
one-byte parameters.

Yep, IIRC you are not first, and I don’t think you will be the last,
to notice that little problem, or similar ones in SDL.

(Why does it take four one-byte parameters
when we have a SDL_Color struct already defined?)

I don’t know. I didn’t define it. My best guess is that it reflects
the way Sam thinks about setting rendering values. It works pretty
well for me too. If it ever really bothers me I’ll overload it with a
function that takes an SDL_Color, breaks out the RGB values, and then
calls the original API. I’m a lot more pedantic than Sam… I’m a lot
more pedantic than most people. So, If I had defined it I most likely
would have had a SetRenderRGB, A setRenderRGBA, a SetRenderAlpha, and
so on for way to many variations.

But, it is very common to have to set the alpha value at the same time
you set the RGB values. You need all four for rendering. So, why not
do it that way?

Bob PendletonOn Wed, Nov 18, 2009 at 10:22 PM, Mason Wheeler wrote:


From: Bob Pendleton <@Bob_Pendleton>
Subject: Re: [SDL] SDL_Color question

On Wed, Nov 18, 2009 at 1:57 PM, Mason Wheeler wrote:

I’ve been working with colors lately, and I’m a bit confused by the
SDL_Color format.? It’s a 4-byte struct made up of R, G, B, and unused
bytes.? Anything that requires RGBA takes a one-byte A value separately.
Why not just define SDL_Color as R, G, B, and A?

I think you are confusing color formats with pixel formats. Pixels
can have R,G,B, and Alpha components. (Some people even think of
values stored in the Z, Stencil, and the accumulations buffers, as
being part of a pixel.) But, color when represented using the R,G,B
color space, is a three element vector that selects a single point in
a three dimensional space just the same way that X,Y,Z select in a
single point in our normal dimensional space.

So, alpha is not part of color, even though it is part of a pixel.
Alpha is a coefficient used to scale color values during some
operations that combine color values, but it is not a part of a color.

Bob Pendleton


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


±----------------------------------------------------------


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


±----------------------------------------------------------