Palette loading

Could anyone please help me how to load palettes and use it for texture mapping.

Originally posted by Sajjad:
Could anyone please help me how to load palettes and use it for texture mapping.

Hi Sajjad. You should look at EXT_Paletted _texture extension specification. It has full information on your question. You can get the specification at http://oss.sgi.com/projects/ogl-sample/registry/
Alexei.

Originally posted by Alexei_Z:
Hi Sajjad. You should look at EXT_Paletted _texture extension specification. It has full information on your question. You can get the specification at http://oss.sgi.com/projects/ogl-sample/registry/
Alexei.

Thanks Alexei. Now I could load a palette but the problem is I am not getting the original color of the image. The blue color is replaced with black, the black with blue and the white is replace with green. Do you have any idea why is it behaving like this ??

Originally posted by Sajjad:
Now I could load a palette but the problem is I am not getting the original color of the image. The blue color is replaced with black, the black with blue and the white is replace with green. Do you have any idea why is it behaving like this ??

Hi Sajjad. I have no idea about this right now. There may be something wrong with indexation or format. It would be better if you post your code here.
Alexei.

Hi Alexei,

Here is the code. Please find out what is the problem in it.

static PFNGLCOLORTABLEEXTPROC myfunc;
unsigned char pal[256 * 3];

void LoadImageCP8(char * Filename)
{
int size = 256 * 256, bread;
FILE *File=NULL;
unsigned char * p;
if ( ! TextureMap4)
{
File = fopen(“keno.pal”,“r+bt”);
fseek(File,-769,SEEK_END);
fread(pal,1,768,File);
fclose(File);

File=fopen(Filename,“r+bt”);
p = (unsigned char *) malloc
(size * 1);
bread = fread (p, sizeof (unsigned char), size * 1, File);
fclose(File);
myfunc=(PFNGLCOLORTABLEEXTPROC) wglGetProcAddress(“glColorTableEXT”);

glBindTexture(GL_TEXTURE_2D, 1);
glTexParameteri(GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
myfunc(GL_TEXTURE_2D, GL_RGB8, 256, GL_BGR_EXT, GL_UNSIGNED_BYTE, pal);
glTexImage2D(GL_TEXTURE_2D, 0, GL_COLOR_INDEX8_EXT, 256, 256, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE,p);
}

void DispFunction()
{

glEnable (GL_TEXTURE_2D);
glClear (GL_COLOR_BUFFER_BIT);

while(1)
{
   LoadImageCP8("hken004.rp8");

glBindTexture(GL_TEXTURE_2D, 1);//Texture);
glColor4f (1.0f, 1.0f, 1.0f, 1.0f);

glBegin (GL_POLYGON);
glTexCoord2f (1,1);
glVertex2f (100, 100);
glTexCoord2f (0,1);
glVertex2f (200, 100);
glTexCoord2f (0,0);
glVertex2f (200, 200);
glTexCoord2f (1,0);
glVertex2f (100, 200);
glEnd ();
glPopMatrix();
glFlush();
glutSwapBuffers ();
}
}

void main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE );
glutInitWindowPosition(0,0);
glutInitWindowSize(640, 480);
glutCreateWindow (“square”);
glClearColor(0.0,0.0, 0.0, 0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glEnable(GL_ALPHA);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_ALWAYS,1);
glOrtho(0.0, 640.0, 480.0, 0.0, -1.0, 1.0);
glutDisplayFunc(DispFunction);
glutMainLoop();
}

Originally posted by Sajjad:

fseek(File,-769,SEEK_END);
fread(pal,1,768,File);
fclose(File);

myfunc(GL_TEXTURE_2D, GL_RGB8, 256, GL_BGR_EXT, GL_UNSIGNED_BYTE, pal);

Hi Sajjad. MS palette format has four bytes per element. So you should read 1024 bytes and then use GL_RGBA format. Also a palette is stored in order R-G-B, not B-G-R. Good luck.
Alexei.