Pixel data from texture?

Started by
7 comments, last by MGB 17 years, 1 month ago
Does anyone know how/if I can read the pixel data of a texture in OpenGL? I want to check my render-to-texture stuff is working, but all the commands I can see are for putting data *into* textures..?
Advertisement
Attach the texture to FBO, make it current, and use glReadPixels.
Well if its a texutre, just strap it to a quad and render that.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

If you want the pixel data without passing the texture to the graphics card and wasting space you can take the data pointer (from whatever you use to load the texture) and then iterate through it and delete it before passing it on.
"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
Ah, the FBO stuff did it... ta!

glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);char readBuff[texSize*texSize*3];glReadPixels(0,0,texSize,texSize,GL_RGB,GL_UNSIGNED_BYTE,readBuff);


umm not too sure what you meant there, daniel...
You can also use glGetTexImage
Quote:Original post by Nathan Baum
You can also use glGetTexImage


Tsk - I actually looked through the Red Book for something like this and never saw it :o
Must prioritise sleep over gamedev some time :-/

[Edited by - Aph3x on March 5, 2007 5:10:56 AM]
Quote:Original post by Aph3x
umm not too sure what you meant there, daniel...

When you load a texture you call the following commands:
GLuint texture;Texture = LoadPicture("pic.bmp"); //whatever you load the pic withglGenTextures(1, &texture);					glBindTexture(GL_TEXTURE_2D, texture);glTexImage2D(GL_TEXTURE_2D, 0, 3, Texture->sizeX, Texture->sizeY, 0, GL_RGB,GL_UNSIGNED_BYTE, Texture->data);free(Texture->data);	

Now if you only want the data without actually generating a texture you can skip everything except the first line and use TextureData->data and the free it.


"We've all heard that a million monkeys banging on a million typewriters will eventually reproduce the entire works of Shakespeare. Now, thanks to the internet, we know this is not true." -- Professor Robert Silensky
Ah I see what you mean, but I was wanting to check that the right image was getting *into* my texture which was being rendered at runtime.

This topic is closed to new replies.

Advertisement