AntonKarlsson
asked on
Paletted texture appears in greyscale.
Hi I need some help with my OpenGL texture loading code with SDL.
The image I'm currently loading is in a paletted format(Files below).
Maybe something is missing in the gl setup functions in context.cpp.
The code snippet shows the code for the paletted texture's gl pixel transfer/map commands in LoadGLTexture(...) in textures.cpp.
textures.cpp
context.cpp
test.cpp
The image I'm currently loading is in a paletted format(Files below).
Maybe something is missing in the gl setup functions in context.cpp.
The code snippet shows the code for the paletted texture's gl pixel transfer/map commands in LoadGLTexture(...) in textures.cpp.
if (palette) // If the image is paletted:
{
type = (bipp == 8) ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT;
format = GL_COLOR_INDEX;
internalFormat = bypp;
GLsizei mapSize = palette->ncolors;
GLfloat *Rmap = new GLfloat[mapSize];
GLfloat *Gmap = new GLfloat[mapSize];
GLfloat *Bmap = new GLfloat[mapSize];
GLfloat *Amap = new GLfloat[mapSize];
for (int i = 0; i < mapSize; i++)
{
SDL_Color *pColor = palette->colors + i;
Rmap[i] = (GLfloat)pColor->r / mapSize;
Gmap[i] = (GLfloat)pColor->g / mapSize;
Bmap[i] = (GLfloat)pColor->b / mapSize;
Amap[i] = (GLfloat)pColor->unused / mapSize;
}
glPixelMapfv(GL_PIXEL_MAP_I_TO_R,mapSize,Rmap);
glPixelMapfv(GL_PIXEL_MAP_I_TO_G,mapSize,Gmap);
glPixelMapfv(GL_PIXEL_MAP_I_TO_B,mapSize,Bmap);
glPixelMapfv(GL_PIXEL_MAP_I_TO_A,mapSize,Amap);
glPixelTransferi(GL_MAP_COLOR,GL_TRUE);
delete [] Rmap;
delete [] Gmap;
delete [] Bmap;
delete [] Amap;
}
Grass.pngtextures.cpp
context.cpp
test.cpp
ASKER
It seems it only reads the red color map for black to white.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Result.jpg