Link to home
Start Free TrialLog in
Avatar of AntonKarlsson
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.
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;
	}

Open in new window

Grass.png
textures.cpp
context.cpp
test.cpp
Avatar of AntonKarlsson
AntonKarlsson

ASKER

It looks like this:
Result.jpg
It seems it only reads the red color map for black to white.
ASKER CERTIFIED SOLUTION
Avatar of AntonKarlsson
AntonKarlsson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial