• Advertisement
Sign in to follow this  

opengl color question?

This topic is 4175 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

I just have a simple question about opengl color. I want to specify a 24 bit color in opengl. I have found online that this means that each pixel has 2 bytes for each color. Like RR GG BB So, which of the glcolor functions should be used to specify the color. Is it glcolor3s(...) which takes in 3 short integer values? I'm not really sure. I got a bit confused by some documentation online. maybe glcolor3us(...) thanks in advance

Share this post


Link to post
Share on other sites
Advertisement
I'm not sure if I understand why you'd want to do that? I thought color became 32bit with the alpha channel addition, but other then that, the 3f version worked fine.

I'm no expert on opengl, and rather new, but I did some searches and couldn't find any guides or syntax, sorry =(

Share this post


Link to post
Share on other sites
Quote:
Original post by BradSnobar
I want to specify a 24 bit color in opengl.
I have found online that this means that each pixel has 2 bytes for each color.
Like RR GG BB

In principle, if you want to specify 24 bits of RGB color, you mean to have 8 bits for each channel. Furthurmore, with 8 bits you can encode 2^8 = 256 different levels. With 2 bytes per channel you can encode 2^16 = 65536 levels (what obviously encloses the 256 levels) with the costs of 48 bits for RGB in total.

So you can use 2 bytes per channel to specify 24 bit RGB, but 1 byte per channel is already sufficient.

Here an excerpt from the glColor man page. It describes how the various color setters work.
Quote:
glColor man page
Current color values are stored in floating-point , with unspecified mantissa and exponent sizes. Unsigned integer color components, when specified, are linearly mapped to floating-point values such that the largest representable value maps to 1.0 (full intensity), and 0 maps to 0.0 (zero intensity). Signed integer color components, when specified, are linearly mapped to floating-point values such that the most positive representable value maps to 1.0, and the most negative representable value maps to -1.0. (Note that this mapping does not convert 0 precisely to 0.0.) Floating-point values are mapped directly.


EDIT: Normally in computer graphics programs 3*8 bits RGB color is used, each channel in the range 0 to 255. The equivalent OpenGL setter is glColor3ub(GLubyte,GLubyte,GLubyte).

For best abstraction float (in the range 0.0 to 1.0) should be used. But since a single float value consumes 4 bytes of memory, the unsigned bytes variant is preferred at least where many color values are stored, e.g. in textures.

Share this post


Link to post
Share on other sites
Okay, thanks. That was the function I was using. I think I just got confused after reading something online.

Still much appreciated though.

Share this post


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

  • Advertisement