Archived

This topic is now archived and is closed to further replies.

Finding the RGB values in a bitmap at a specific point

Recommended Posts

Hi, While programming my skydome using a gradient map, I decided to switch to vertex colors. The vertex colors are taken from the gradient map itself. To do that, I need to know how I can find the RGB values in a bitmap at a specific points(a vertex texture coords, for example). I tried several methods, but none worked. The bitmap data is stored as a 1D array. How can I do that? Thanks, Yuval [edited by - Etus on May 4, 2003 3:14:39 PM]

Share on other sites

for coords x and y in the texture

if the texture is tex[size], where size = width * height * 3

tex[x][y][0] = tex[(y * texWidth + x) * 3] ( *3 because RGB is 3 bytes)

Share on other sites
Thanks a lot - I forgot to multiply it in 3

I now have another problem:
When I access an array, I must use an integer(I can't write "terrainVertices[0.5f]" but "terrainVertices[1]"). When I access the bitmap rgb values using a vertex texture coords, I must turn these texture coords into an integer - thus, I miss the "fine tuning" float gives me with textures coords. What happens is that there's a fast switch between 1, to 2, to 3, etc. then using float(1.0f, 1.1f, 1.2f, ...).

Here's my code:

    CVector3 SkyDome :: GetRGB(CVector2 uvCoord) {	uvCoord.x *= gradientMap->sizeX;	uvCoord.y *= gradientMap->sizeY;	int x = (int)uvCoord.x % gradientMap->sizeX;			int y = (int)uvCoord.y % gradientMap->sizeY;			CVector3 rgbColor;	rgbColor.x = (float)(gradientMap->data[(x + (y * gradientMap->sizeX) * 3)]);		rgbColor.y = (float)(gradientMap->data[(x + (y * gradientMap->sizeX) * 3) + 1]);	rgbColor.z = (float)(gradientMap->data[(x + (y * gradientMap->sizeX) * 3) + 2]);	rgbColor = Normalize(rgbColor);	return rgbColor;}

What can I do to fix that problem?
And please, forgive my poor English.

- Yuval

[edited by - Etus on May 4, 2003 4:20:32 PM]

[edited by - Etus on May 4, 2003 4:21:05 PM]

• Forum Statistics

• Total Topics
628306
• Total Posts
2981940

• 9
• 11
• 11
• 11
• 10