Answer the question
In order to leave comments, you need to log in
Get RGB pixel information?
Good afternoon! I am studying OpenGL and it became necessary to get information about a pixel from an image, namely the value R * G * B.
The image is loaded using stbi:
int width, height, numComponents;
unsigned char * data = stbi_load("./resources/models/terrain/heightmap.png", &width, &height, &numComponents, STBI_rgb);
if(data == NULL)
std::cerr << "Unable to load texture: hightmap.png" << std::endl;
int Terrain::GetRGB(int x, int y, unsigned char * image, int width, int height)
{
int rgb;
rgb = image[3 * x * width + 3 * y * height] +
image[3 * x * width + 3 * y * height + 1] +
image[3 * x * width + 3 * y * height + 2];
return rgb;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question