auto-scaling grayscale image possible?

Dear all,

How can I display a grayscale floating point image without clamping it myself to the [0,1] region? So for example, when the maximum pixel value is 135.6f, this value should be displayed as full white and when the minimum pixel is 5.1f this value will be displayed as full black, whilst everything in between will be scaled as a grayscale value linearly with respect to [5.1, 135.6].
(similarly to the “imagesc” function in Matlab).

Can this be done in OpenGL?

Currently I work with PBO’s and I create a texture as follows:

glTexImage2D(GL_TEXTURE_2D, 0, 1, width, height, 0, GL_LUMINANCE, GL_FLOAT, NULL);

and update the texture in my display() function with:

glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height,GL_DEPTH_COMPONENT, GL_FLOAT,0);

If it can be done with these lines, how should I modify the internalformat, type,… parameters?

Thanks in advance!

With legacy OpenGL, you can use glPixelMap to specify a mapping which is applied when data is uploaded to a texture. With modern OpenGL, you can use a floating-point internal format such as GL_R16F then perform the conversion in the fragment shader.

There is no way to do this in modern OpenGL without using fragment shaders? I’m not too familiar with them yet…

The general philosophy behind “modern” OpenGL is that, if you can do it yourself (i.e. in a shader), then OpenGL won’t do it for you.