Jump to content
  • Advertisement
Sign in to follow this  
Kincaid

Color Mapping Question

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

Greeting yeh opengl'ers I am loading in a bitmap which i use to extract colors from a certain coordinates. The underlying idea is to use it either as a normal map, or a color map, which should allow me to simply draw a grid of quads, and read the colors in from a bitmap. Now this all goes well...the mapping from bitmap coordinate to grid coordinate is fine, but something goes wrong with the coloring. perfect red blue and yellow are treated perfectly. but 'complex' colors are missed out somehow and all translated to white. green is also not 'seen'... how is this? is this some coloreadoption in o-gl or something ? Thanx to whom takes the effort to read and maybe answers this thread :)

Share this post


Link to post
Share on other sites
Advertisement
It could be a variety of things; gl is sensitive this way because there are many possible ways things can be changed. Could you post your drawing code?

You may also want to check to make sure the values you are reading in are correct. Many things can go wrong depending on the file format you are using. Things like RGB and BGR and little or big endian cause wierd errors. I'd recommend you use something like DevIL to get around these types of errors.

Cheers,
- llvllatrix

Share this post


Link to post
Share on other sites
I use this function to collect te colors
it's not BGR instead of RGB cause, reds blues and yellows are mapped perfectly.
dont know what you mean by 'and little or big endian'......

void ReadRGB(Vector& RGB, float X, float Z)
{
int index = 3*X + Z*3*1024;
RGB.X = (double)NormalMapImage->data[index+0];
RGB.Y = (double)NormalMapImage->data[index+1];
RGB.Z = (double)NormalMapImage->data[index+2];
RGB.A = 0.2;
}

I tried to track the numbers, because I got to thinking they maybe were round-off errors somewhere from switching from floats to ints, but thats not it i guess, since the mapping would go wrong also then.
Another thing though, I remember doing something like this before, but then I divided numbers by 255, which has also no effect.

And also, what's devIL ?

Share this post


Link to post
Share on other sites
DevIL is an open source image library; formerly known as OpenIL. No time to take a look at your source now, but heres the link to DevIL's site:
http://openil.sourceforge.net/

Cheers,
- llvllatrix

Share this post


Link to post
Share on other sites
I think I know what is wrong.

Quote:

perfect red blue and yellow are treated perfectly. but 'complex' colors are missed out somehow and all translated to white


Heres my diagnosis. You are reading the colors in properly; as you said, red, green, blue and I'd also wager black shows up properly. Everything else turns white.

Quote:

I got to thinking they maybe were round-off errors somewhere from switching from floats to ints


Exactly. Opengl defines it's colors between 0 and 1. But if you define red it would look like (255, 0, 0) which means (1.0f, 0, 0) to OpenGL. A similar thing would happen for the remaining colors that work. The colors that dont work would look something like (192, 23, 50) which means (1.0f, 1.0f, 1.0f) or pure white. You have to scale your intgers between 0.0f and 1.0f.

Quote:

Another thing though, I remember doing something like this before, but then I divided numbers by 255, which has also no effect.


Try dividing by 255.0. Also if you have any warnings related to type, make sure you address them.

Quote:

dont know what you mean by 'and little or big endian'


http://www.cs.umass.edu/~verts/cs32/endian.html

Cheers,
- llvllatrix

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
SUCCESS !!!!!
Thanx a lot........

PS. to hell with type conversions :)

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!