Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: auto-scaling grayscale image possible?

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2013
    Posts
    25

    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:

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

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

    Code :
    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!

  2. #2
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    498
    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.

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2013
    Posts
    25
    Quote Originally Posted by GClements View Post
    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...

  4. #4
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    498
    Quote Originally Posted by samvdj View Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •