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.

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?

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);
m_bUseShader = false;

Also: What is ASM shaders and arb_imaging?


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.

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?


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?

basically I’ve been trying to duplicate our shader logic:
//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)

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


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