View Full Version : Query Pixel data from texture

10-01-2003, 12:03 AM
Hi all,

I am developing an algorithm for 3d modelling from 2d images. One of the approaches I thought would be to load textures into texture memory and subsequently query appropriate pixel data from the texture.

However, I do not know of a way to do so... and would be glad if somebody could help me on how to get pixel data from textures?

I am aiming to make my application fast and hence want to limit my use of glReadPixels(). Is there any quick alternative whereby I could get the color information of the pixel in question from texture itself...?

I know I am repeating myself, but its just that iam stuck...!

10-01-2003, 07:36 AM
If I understood correctly, you want to fetch a texel (not pixel) from a texture to use in your app?

You don`t need to involved GL in this. Just do


for your texture that is in RAM.

10-02-2003, 05:06 AM
i understand tht texels can be easily referenced in RAM, but i wish to mkae use of GPUs only..

trying to determine what is possible on the latest nVidia cards.. and use it in my research.

I was also wonering, would pixel shaders or vertex shaders allow me to make such a query.. what about Cg.. would that help?...

Thanks for ur reply.

10-02-2003, 07:28 AM
It's in a fragment program (pixel shader) that you can fetch texels. You should read about it in the documents at ati and nvidia and read the registry

You can learn Cg if you wish. It's possible there too.

10-02-2003, 07:55 AM
Thanks V-Man..

You've been a great help. Hopefully this should solve the problem... I have the Cg book with me and may start it soon.. in the mean time would go through the docs at nVidia..

Cheers.. http://www.opengl.org/discussion_boards/ubb/smile.gif

10-05-2003, 08:34 PM
another approach would be to render a square with the texture applied, then do a glReadPixels to extract the value.

10-06-2003, 08:03 AM
He wants to avoid glReadPixels (and also that's really stupid if all you want to do is get some texels)

I can add that the next programmable hw will be able to access textures in VP. I saw that in some document about the next generation of D3D.

I'm wondering what's the next step for GL.
Either ASM style is dead and HLSL all the way or their will be ARB_vertex_program2 ARB_fragment_program2.

10-06-2003, 09:27 AM
I can add that the next programmable hw will be able to access textures in VP. I saw that in some document about the next generation of D3D.

Because texture accesses are exactly the kind of thing you want to do in a vertex program. http://www.opengl.org/discussion_boards/ubb/rolleyes.gif

They should be working on getting us memory buffer that can be accessed (in a strictly non-texture-like fashion) from the vertex programs. The memory buffer API could actually be fast to upload new data to, rather than the texture API which is very slow. I want to be able to upload a sequence of matrices to the graphics hardware every frame for multiple characters. A VBO-esque buffer is more what is needed than a texture.

10-07-2003, 09:45 AM
I think their choice for a texture buffer instead of a general one is that it somehow involves the need for the texture hw for doing filtering for LOD.

Don't take my word for it. I can't be certain.