Does usage of color indexed texture, which is 1 byte per texel (instead RGB texture, which is 3 bytes) saves video card memory? Or texture is translated to RGB by OpenGL and there’s no difference?
I couldn’t make color indexed texture to work properly (RGB texture works fine). Here’s the code:
Initialization:
unsigned char tex_ind[4] =
{ 0, 1, 2, 3 };
float mr[4]= { 0.5, 0.3, 0.0, 1.0 };
float mg[4]= { 1.0, 1.0, 0.0, 1.0 };
float mb[4]= { 1.0, 0.0, 1.0, 1.0 };
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelMapfv (GL_PIXEL_MAP_I_TO_R, 4, mr);
glPixelMapfv (GL_PIXEL_MAP_I_TO_B, 4, mb);
glPixelMapfv (GL_PIXEL_MAP_I_TO_G, 4, mg);
glTexImage2D(GL_TEXTURE_2D, 0, 1,
2, 2, 0,
GL_COLOR_INDEX,
GL_UNSIGNED_BYTE, tex_ind);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glEnable(GL_TEXTURE_2D);
Drawing:
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glClear (GL_COLOR_BUFFER_BIT);
glLoadIdentity ();
glColor3f (1.0, 1.0, 1.0);
glBegin (GL_QUADS);
glTexCoord2f (0.0, 0.0); glVertex2f (-1.0, -1.0);
glTexCoord2f (1.0, 0.0); glVertex2f (1.0, -1.0);
glTexCoord2f (1.0, 1.0); glVertex2f (1.0, 1.0);
glTexCoord2f (0.0, 1.0); glVertex2f (-1.0, 1.0);
glEnd ();
This code produces gray-scaled image, using values from I_TO_R map only, (I_TO_G, I_TO_B do not influence final image in any way), treating red as white.
What am I doing wrong?
Thanks.