read 2D texture pixel values

Hi,

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.

cheers
fred

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?

cheers
fred

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
fred

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

glClampColorARB(GL_CLAMP_VERTEX_COLOR_ARB, GL_FALSE);
glClampColorARB(GL_CLAMP_READ_COLOR_ARB, GL_FALSE);
glClampColorARB(GL_CLAMP_FRAGMENT_COLOR_ARB, GL_FALSE);

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.

cheers
fred

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

I’m confused;

This suggests not,
http://lists.apple.com/archives/mac-opengl/2008/Apr/msg00051.html
http://developer.apple.com/graphicsimaging/opengl/extensions.html

This document
http://www.opengl.org/registry/doc/glspec21.20061201.pdf
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:

cheers
fred

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,
http://www.gamedev.net/reference/programming/features/fbo1/

cheers
fred