Results 1 to 8 of 8

Thread: Mapping pixel colors without hardware

  1. #1
    Junior Member Newbie
    Join Date
    May 2011
    Posts
    8

    Mapping pixel colors without hardware

    I'm new to OGL. The project I'm working on needs to support graphic cards that do not support shaders so I have to be able to detect this old hardware and render images accordingly - in particular the ability to modify the image's color. For ex, I need to convert all red pixels of the image to a color chosen from a color chart. I believe I have the hardware detection worked out but I'm having trouble with rendering the color(s) of the image. I have tried color index mode with a color table without too much success. We are calling glDrawArrays() and I am wondering if that will need to be changed to glDrawPixels in this case. Any help or suggestions will be greatly appreciated.

  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: Mapping pixel colors without hardware

    You are on a up hill struggle right off the bat.
    You need to determine exactly what is the base hardware to help you code up a solution. For example although glsl shaders are out what about support for ASM shaders?
    Also arb_imaging may be an option depending upon the hardware.
    Do you know the vendors at least? Eg Intel , AMD, nVidia?

  3. #3
    Junior Member Newbie
    Join Date
    May 2011
    Posts
    8

    Re: Mapping pixel colors without hardware

    I am new to this company and unfortunately, I do not know vendor specifics. Client hardware can vary. To detect whether hardware supports shader I basically query glGetString for GL_SHADING_LANGUAGE_VERSION if it returns null then assuming no shaders:

    ver_str[0] = '/0';
    ver_str = (char*)glGetString(GL_SHADING_LANGUAGE_VERSION);
    if(!ver_str)
    m_bUseShader = false;

    Also: What is ASM shaders and arb_imaging?

    Thanks

  4. #4
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: Mapping pixel colors without hardware

    ASM shaders was the previous generation of flexible programming for GPUs aimed at a much older generation of hardware.
    Arb_imaging supports convolutions and histograms but is not usually supported in hardware.
    In your case you need to think of a solution which would work with the fixed function pipeline.
    The only thing I can think of is encoding a unique colour in a 3d texture storing Red along s axis, Green along t axis and Blue along r or depth
    If the texture was 256 * 256 * 256 then using standard 3D texture coords you could lookup the indexed colour from this texture.

  5. #5
    Junior Member Newbie
    Join Date
    May 2011
    Posts
    8

    Re: Mapping pixel colors without hardware

    Being new to OGL I don't know too much about textures. Would you be able to give me some basic pseudo code to get me started?

    Thanks

  6. #6
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: Mapping pixel colors without hardware

    Can you give some more details on how the colour mapping is to be done. When you say map red to colour x just what is the definition of red? Do you mean RGB (1,0,0) or does it also include all variations of eg RGB (0.0 .... 1.0, 0,0) ie the red component can vary between 0 to 255 ( or 0 to 1.0 in floating point)?
    Do you only have a limited number to lookup/ transpose ?
    And finally how during the rendering is this supposed to happen?

  7. #7
    Junior Member Newbie
    Join Date
    May 2011
    Posts
    8

    Re: Mapping pixel colors without hardware

    basically I've been trying to duplicate our shader logic:
    //where
    //color_map1 represents our "red" map
    //color_map2 represents our "green" map
    //color_map3 represents our "blue" map

    uniform vec3 color_map1;//components in the range of 0.0 - 1.0
    uniform vec3 color_map2;//components in the range of 0.0 - 1.0
    uniform vec3 color_map3;;//components in the range of 0.0 - 1.0


    void main()
    {
    if (gl_Color.a == 0.0)
    discard;

    vec3 rgbVec1 = vec3((gl_Color.r*color_map1.r), (gl_Color.r*color_map1.g), (gl_Color.r*color_map1.b));
    vec3 rgbVec2 = vec3((gl_Color.g*color_map2.r), (gl_Color.g*color_map2.g),(gl_Color.g*color_map2.b ));
    vec3 rgbVec3 = vec3((gl_Color.b*color_map3.r), (gl_Color.b*color_map3.g), (gl_Color.b*color_map3.b));

    gl_FragColor.r = rgbVec1.r;
    gl_FragColor.g = rgbVec1.g;
    gl_FragColor.b = rgbVec1.b;

    if (rgbVec2.r < rgbVec3.r)
    rgbVec2.r = rgbVec3.r;
    if (rgbVec2.g < rgbVec3.g)
    rgbVec2.g = rgbVec3.g;
    if (rgbVec2.b < rgbVec3.b)
    rgbVec2.b = rgbVec3.b;

    if (rgbVec1.r < rgbVec2.r)
    gl_FragColor.r = rgbVec2.r;
    if (rgbVec1.g < rgbVec2.g)
    gl_FragColor.g = rgbVec2.g;
    if (rgbVec1.b < rgbVec2.b)
    gl_FragColor.b = rgbVec2.b;

    gl_FragColor.a = gl_Color.a;
    }

    There are only a finite number of colors I need to map from - red,green,blue,yellow,cyan,and magenta. So for ex, if the user would like to replace the red color space (in RGB) to cyan then thru code I need to somehow map this via color table or via per pixel. Hope this helps if you need more info I try to give more details

    Thanks

  8. #8
    Junior Member Newbie
    Join Date
    May 2011
    Posts
    8

    Re: Mapping pixel colors without hardware

    I thought of a work around for this but simply mapping the buffer and the modifyng the pixels. Thanks to all for their help.

Similar Threads

  1. My UV-mapping gets wrong colors?
    By ninjas in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 06-04-2018, 02:41 AM
  2. Reading Clicked Pixel Colors
    By ekosha in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-15-2007, 04:30 PM
  3. Hardware pixel analysis
    By MojoMagic in forum OpenGL: Advanced Coding
    Replies: 8
    Last Post: 04-18-2003, 11:48 AM
  4. Per-pixel shading without using hardware
    By Keermalec in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 11-09-2001, 07:45 AM
  5. Weird colors when texture mapping
    By Ace_Man in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-30-2000, 11:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean