• Advertisement
Sign in to follow this  

Grabbing texture pixel values

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

Hi. I've created a texture from the back buffer using glCopyTexImage2D. So, I have a GLuint holding the texture ID (which is 128x128), however I would like to be able to grab out each pixel value from the texture. So, if I was to write the texture out to a textfile, I would be able to do the following:
{
	FILE *outFile;
        unsigned long pixelRGBValue;

	outFile = fopen("Texture.txt", "wt");

	for(int i = 0; i < 128; i++)
	{
		for(int j = 0; j < 128; j++)
		{
			fprintf(outFile, "%08x,", pixelRGBValue);
		}
		fprintf("\n");
	}

	fclose(outFile);
}

This obviously doesn't work since pixelRGBValue doesn't hold anything. Anyone know how to grab each pixel RGB value out of the texture? Any help would be great!

Share this post


Link to post
Share on other sites
Advertisement
Here is your function you need to use:

unsigned char *pixelData;

glBindTexture(GL_TEXTURE_2D, TextureID);
glGetTexImage(GL_TEXTURE_2D, 0, (GL_RGB or GL_RGBA), GL_UNSIGNED_BYTE, (void *)pixelData);


Then pixelData will be filled with the texture's pixels. Set GL_RGB or GL_RGBA according to if your texture has an alpha channel or not.

Share this post


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

  • Advertisement