PDA

View Full Version : glColorTableExt for gray scale palette



zvivered
06-15-2002, 07:52 AM
Is it possible to define a gray scale plette with glColorTableExt ? How ? What are the parameters ?

I succeeded to define 8 bits palette for green levels. But not gray.

What will be the parameters for glTexImage2D ?

Thanks in advance.

Ozzy
06-16-2002, 08:37 AM
basically grayscale pictures doesn't need palettes bcoz colors are stored as intensity (8bits) so if u need to translate your bitmap as indexes->palette just fill each r,g,b with the same value.
Now if you've planned to use grayscale pics i *strongly* recommend to also use the shared palette extension which will save a little bit of time when binding textures.

switch(pPicInfos->type){
case BITMAP_4B:
pBitmap->infos.format = VR_RGB4;
pBitmap->infos.bpp = 8;

if(glColorTableEXT == NULL)
goto convto15;

picConvert(pPicInfos,CONVERT_TO_8);

glColorTableEXT(GL_TEXTURE_2D,GL_RGB,16,GL_RGB,GL_ UNSIGNED_BYTE,pPicInfos->pPalette);

glTexImage2D(GL_TEXTURE_2D,0,GL_COLOR_INDEX4_EXT,w ,h,0,GL_COLOR_INDEX,GL_UNSIGNED_BYTE,pPicInfos->pData);
break;
case BITMAP_8B:
pBitmap->infos.format = VR_RGB8;
pBitmap->infos.bpp = 8;

if(glColorTableEXT == NULL)
goto convto15;

glDisable(GL_SHARED_TEXTURE_PALETTE_EXT);
glColorTableEXT(GL_TEXTURE_2D,GL_RGB,256,GL_RGB,GL _UNSIGNED_BYTE,pPicInfos->pPalette);
glTexImage2D(GL_TEXTURE_2D,0,GL_COLOR_INDEX8_EXT,w ,h,0,GL_COLOR_INDEX,GL_UNSIGNED_BYTE,pPicInfos->pData);
break;
case BITMAP_GRAYSCALE:
pBitmap->infos.format = VR_GRAYSCALE;
pBitmap->infos.bpp = 8;

if(glColorTableEXT == NULL)
goto convto15;

glEnable(GL_SHARED_TEXTURE_PALETTE_EXT);
if (!sharedPaletteLoaded){
glColorTableEXT(GL_SHARED_TEXTURE_PALETTE_EXT,GL_R GB,256,GL_RGB,GL_UNSIGNED_BYTE,pPicInfos->pPalette);
sharedPaletteLoaded = VR_TRUE;

}
glTexImage2D(GL_TEXTURE_2D,0,GL_COLOR_INDEX8_EXT,w ,h,0,GL_COLOR_INDEX,GL_UNSIGNED_BYTE,pPicInfos->pData);
break;


hth

jwatte
06-16-2002, 01:25 PM
If all you're doing is grayscale, don't use palette at all. Instead, use GL_ALPHA or GL_LUMINANCE texture formats (and, probably, external formats).