Before any rendering is done, the renderer should detect wheter the OpenGl implementation is running on supports paletted texture. If that feature is not supported, software indexing is to be done insted (OpenGl code example here); else, the hardware indexing will take place (OpenGl code example here).

If paletted texture are supported, the renderer must also check how many palette entries are supported. In fact, some implementation supports only 256 entries. In that case, hardware indexing will be performed only when the rendered object has only that many normal-color indexes in its index map.

At the end of execution of the following code, the integer maxPalette should be:

Moreover, if maxPalette is greater than 0, the two functions *glColorTableEXT and *glGetColorTableParameterivEXT can be safely used in the subsequent code to set and check the texture palette respectively.

int maxPalette;
PFNGLCOLORTABLEEXTPROC* glColorTableEXT;
PFNGLGETCOLORTABLEPARAMETERIVEXTPROC* glGetColorTableParameterivEXT;

// try to gain the pointer to the two functions
glColorTableEXT=(PFNGLCOLORTABLEEXTPROC)wglGetProcAddress("glColorTableEXT");
glGetColorTableParameterivEXT=(PFNGLGETCOLORTABLEPARAMETERIVEXTPROC)wglGetProcAddress("glGetColorTableParameterivEXT");

// were we succesfull?
if (glColorTableEXT==NULL || glGetColorTableParameterivEXT==NULL )

    maxPalette = 0; // no: unluckly, we dont have any paletted texture support
else {
    // yes: we seem to have some hardware support for paletted texture...
    // ...but we'd better double-check
    int res;
    double d[0xFFFF]; // just a temporary buffer

    // as a test, try to set a 16K palette...
    (*glColorTableEXT)( GL_TEXTURE_2D,GL_RGBA8,0x4000, GL_RGBA,GL_FLOAT,d);

    // now, is the palette size really 16K?
    (*glGetColorTableParameterivEXT)(GL_TEXTURE_2D, GL_COLOR_TABLE_WIDTH_EXT , &res);
    if (res==0x4000) maxPalette=0x4000 //yes!
    else {

      // no. something went wrong. The palette size was not found to be 16K.
      // so, as a test, let's try to set at least a 256 palette...
      (*glColorTableEXT)(GL_TEXTURE_2D,GL_RGBA8,0x100,GL_RGBA,GL_FLOAT,d);

      // now, is the palette size really 256?
      (*glGetColorTableParameterivEXT)(GL_TEXTURE_2D, GL_COLOR_TABLE_WIDTH_EXT , &res);
      if (res==256) maxPalette=256; // yes: hardware support seems to work up to 256 sized palette
      else maxPalette=0; // no: the hardware support was detected, but it does not seem to work!

    }
}