Skip to main content
gamedev.net
🔒 Locked

Pixel data from texture?

Started by MGB Mar 4, 2007 at 3:01 PM 7 replies 1.5k views
Original Post
MGB
MGB
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..?
dpadam450
dpadam450
Well if its a texutre, just strap it to a quad and render that.
NBA2K, Madden, Maneater, Killing Floor, Sims 
daniel_i_l
daniel_i_l
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
MGB
MGB
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...
MGB
MGB
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]
daniel_i_l
daniel_i_l
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
MGB
MGB
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.