PDA

View Full Version : read 2D texture pixel values



fredrum
04-28-2009, 07:20 AM
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

fredrum
04-28-2009, 07:35 AM
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

dletozeun
04-28-2009, 09:13 AM
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.

fredrum
04-28-2009, 09:55 AM
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

fredrum
04-28-2009, 12:18 PM
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

dletozeun
04-28-2009, 12:32 PM
Interesting, did know this one. Check if your hardware supports the ARB_color_buffer_float (http://www.opengl.org/registry/specs/ARB/color_buffer_float.txt) extension.

fredrum
04-28-2009, 01:03 PM
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. :(



cheers
fred

rexguo
04-29-2009, 05:52 AM
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.

fredrum
04-29-2009, 07:21 AM
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