Hi i figured out of how to use 8bit surface in opengl but i need some help
to apply the pallet.
the loading of the texture is like this( we load a 8bit pcx file)
SDL_RWops *rwop = SDL_RWFromMem(tex->byImage, tex->nLength );
SDL_Surface *tmp = IMG_LoadTyped_RW(rwop,1,“PCX”);
int w = tex->tex_width;
int h = tex->tex_heigth;
for(int x = 0;x< tmp->w;x++)
{
for(int y = 0;y< tmp->h;y++)
{
//copy the pixel data to an array wich is compatible has a
compatible width and heigth for opengl
tmpImage[x + yw] = pix[x + ypitch] ; // = u8[2048*2048];
}
}
SDL_FreeSurface(tmp);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textures[nCurrTex]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // Set
Texture Max Filter
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
//create a 1byte texture which is black and white
glTexImage2D(GL_TEXTURE_2D, 0, 1, w, h, 0, GL_RED, GL_UNSIGNED_BYTE,
tmpImage);
// now lets create the pallet texture
nCurrTex++;
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, textures[nCurrTex]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // Set
Texture Max Filter
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
for(int i=0;i<256;i++)
{
colorTable[i] = ((pUsedPal[i].r) << 16) | ((pUsedPal[i].g) << 8) |
(pUsedPal[i].b);
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 1, 0, GL_RGB,
GL_UNSIGNED_BYTE,colorTable);
glUniform1i(glGetUniformLocation(FragmentShader, "Texture0"), 0);
glUniform1i(glGetUniformLocation(FragmentShader, "Texture1"), 1);
to applay the pallet to it my idee is to use a 256 x 1 texture in an pxiel
shader
here the fragment shader
uniform sampler2D Texture0; // Texture
uniform sampler2D Texture1; // Pallet
void main()
{
vec4 color = texture2D(Texture0, gl_TexCoord[0].st);
//this should find the right color in the Pallet
float index = color.r * 256.0;
vec4 col = texture2D(Texture1, vec2(index,0) );
if(color.r == 0.0 )
discard;
else
gl_FragColor = color;
}