read 2D texture pixel values


would anyone know how I can sample/get the values of a specific pixel in a GL_TEXTURE_2D texture?

I found glGetTexImage but that copies the whole texture and I only want one pixel.


Oh, i figured out I can do like this

glBindTexture (GL_TEXTURE_2D, tList[SAMPLE]);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 1, 1, 0);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_FLOAT, &mouseRGB);

But now I still have the problem that the value returned clamps at 1.0.

Different thread really, I suppose, but do I have to use FBO’s to get unclamped values?


With glCopyTexImage2D, pixels are copied from the color buffer or the color attachment in case of a fbo is bound (Except that I do not know what happens when you have multiple color attachments).
Anyway, AFAIK, color value in the application provided framebuffer are always in the [0 1] range.

Now, you can create a fbo and attach a texture with float point pixel format and read its values.

Hi, and thanks for your reply.
So it seems maybe I have to use FBO’s.
I am trying to set one up in wxWidgets, I hope it’ll work.

thanks again

Someone pointed out that I should be able to do something like:


and then I wouldn’t need to use an FBO.

Problem is that glClampColorARB() does not seem to exist on Mac.
Which is what I am using.


Interesting, did know this one. Check if your hardware supports the ARB_color_buffer_float extension.

I’m confused;

This suggests not,

This document
says that OpenGl 2.1 supports it but only in the combination of

System: Mac OS X v10.5.0 “Leopard” and later
Renderers: Apple’s Software Renderer

and no graphics cards listed.

So I’m probably out of luck. :frowning:


I’m also working on a Mac (8600M) and can confirm
that glClampColorARB doesn’t exist on it. I’m also
having problems with it clamping values when it is
not supposed to, according to the specs.

In my case I could solve it by using an FBO to render to a float texture. Also inside this FBO ‘bind area’ I could do my sampling of un-clamped float values using

glBindTexture (GL_TEXTURE_2D, tList[SAMPLE]);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F_ARB, mouseX, mouseY, 1, 1, 0);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_FLOAT, &mouseRGB);

Good FBO tutorial here,