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: Representing a float w/ 3 color channels

  1. #1
    Junior Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Michigan, USA
    Posts
    188

    Representing a float w/ 3 color channels

    I need to represent a float value, that ranges from some alpha to beta, w/ 4 bytes of precision using opengl coloring, that only allows for 3, 8 bit channel colors. Any ideas,

    Naive approach:
    I originally though about breaking up [alpha,beta], into 3 segments,delta = (alpha-beta)/3.
    (alpha, alpha+delta), (alpha+delta, alpha+2*delta), and finally, (alpha+2*delta, beta).

    Then assigning each range a color channel. But there are nasty discontinuities at the breaks. I could overlap ranges, but that would reduce precision.

    Any ideas. I am sure someone has encoutered a problem similar to this before.

    The hardware I have available is a bit old, so no 128 bit, color support.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    May 2001
    Location
    Kristianstad,Skåne,Sweden
    Posts
    1,651

    Re: Representing a float w/ 3 color channels

    If you can live with software rendering you could use Mesa, Mesa supports >8 bit color channels

  3. #3
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: Representing a float w/ 3 color channels

    From you post it is not clear whether by "represent" you mean for the human eye (2) or for hardware operations (1).
    The latter case should be doable with plain rgba 8 bit opengl.

    (1)
    The way I would do that :
    Lets assume we have an opengl pixel :
    --RRGGBBAA--

    and an unsigned integer value v, ranging from
    0x00000000
    0xFFFFFFFF

    so whith C simple masking and bit shifting is should not be too hard :
    r= (v >> 24) & 0x000000FF;
    g= (v >> 16) & 0x000000FF;
    b= (v >> 8) & 0x000000FF;
    a= (v >> 24) & 0x000000FF;

    then use these color values with glColor4ub(r,g,b,a); and read with readpixels and such. You need to request an RGBA framebuffer though.

    (2) Color space is inherently 3D, it will be hard to make it look 1D to the eye without discontinuities and without loosing precision.
    Have a look at 3D scientific packages, they mainly use the single rainbow color range :
    google image cfd 3D
    That sort of rainbow can done like this :
    Code :
       alpha-------beta
    r: 0--1--0
    g: 0  0--1--0
    b: 0     0--1--0
    The 0--1 mean interpolate between min and max color value. Maybe the black at both start and end is not a good idea, anyway I hope you get the idea.

  4. #4
    Junior Member Regular Contributor
    Join Date
    Nov 2003
    Location
    Michigan, USA
    Posts
    188

    Re: Representing a float w/ 3 color channels

    I did not know Mesa could do that. Maybe, as a last resort I might consider it. Performance, however is awful, not that I blame the developer.

    As for splitting, that would only work for integer 32 bit. You cannot split a float that way and still retain the meaning of the parameter.

    Thanks for your responses.

Posting Permissions

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