How to load image with color index array

Hi all,

I want to display an image which may have an index of color codes, and then each pixel may have one byte to represent the colour (i know there will be only 255 possible colors this way).

So is there a way to load such an image using OpenGL.

Regards

If you’re able to use shaders, then this should be trivial. Otherwise, no.

If you don’t have shaders, you can either:

  • use a paletted internal format (EXT_paletted_texture, not supported on modern hardware) or
  • have GL depalettize the image on upload. See documentation on GL_COLOR_INDEX, glPixelMap, and glPixelTransfer.

I’m posting this message in 'begginers’as i’m new to openGL so i expect some straight answers:

Basically i’ve data about RGBA values of each pixel that means each pixel takes 4bytes and if i have 4096x4096 pixels then it comes out to be 64MB. I know that i’ve no more than 60 color values in the image. so want to make an index of 60 color values. then use this index as one byte value of each pixel.

I really need to reduce the memory requirement.

What is your maximum texture size ? 4096*4096 is quite a lot.
Check it on your hardware with :


 int value;
 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);   //Returns 1 value
 MaxTexture2DWidth=MaxTexture2DHeight=value;

Then if your aim is to save texture memory on modern hardware, indeed you will have to roll out you own fragment shader, as the above posters suggested.
This is a bit involved, but we can help.
I suggest reading first this tutorial, so that you have enough background :
http://www.lighthouse3d.com/opengl/glsl/