PDA

View Full Version : glPixelMap and color index mapping



steve_j
08-21-2006, 11:14 AM
Hi!

I have the following situation: I have 8 bit (GL_UNSIGNED_BYTE) pixel data. The value of the pixel represents a color index. Actually there are only 4 distinct colors. The pixel data should now be used as texture. I've tried without any success to get the texture correctly working. It seems that my color map are not interpreted correctly. Here is my code:

glPixelTransferi(GL_MAP_COLOR,GL_TRUE);

GLushort redMap[4] = {0,255,255,0,255};
GLushort greenMap[4] = {255,0,255,255,0};
GLuschort blueMap[4] = {255,255,0,0,255};

glPixelMapusv(GL_PIXEL_MAP_I_TO_R,4,&redMap[0]);
glPixelMapusv(GL_PIXEL_MAP_I_TO_G,4,&greenMap[0]);
glPixelMapusv(GL_PIXEL_MAP_I_TO_B,4,&blueMap[0]);

glCreateTextures(1,&m_texture);
glBindTexture(GL_TEXTURE_2D,m_texture);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,width,height,0 ,GL_COLOR_INDEX,GL_UNSIGNED_BYTE,pixels);

Thanks for any help!

regards,
Stephan

Brian Paul
08-21-2006, 02:11 PM
If you're using glPixelMapusv() your map values need to be GLushort values. Try replacing 255 with 65535 instead.

steve_j
08-22-2006, 01:57 AM
Thanks for your help! Now it works as it should!