Color Mapping Question
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 :)
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
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
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 ?
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 ?
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
http://openil.sourceforge.net/
Cheers,
- llvllatrix
I think I know what is wrong.
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.
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.
Try dividing by 255.0. Also if you have any warnings related to type, make sure you address them.
http://www.cs.umass.edu/~verts/cs32/endian.html
Cheers,
- llvllatrix
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
August 06, 2005 05:27 PM
SUCCESS !!!!!
Thanx a lot........
PS. to hell with type conversions :)
Thanx a lot........
PS. to hell with type conversions :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement