?
Solved

Paletted texture appears in greyscale.

Posted on 2009-12-31
4
Medium Priority
?
1,320 Views
Last Modified: 2013-12-21
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
0
Comment
Question by:AntonKarlsson
  • 3
3 Comments
 

Author Comment

by:AntonKarlsson
ID: 26157569
It looks like this:
Result.jpg
0
 

Author Comment

by:AntonKarlsson
ID: 26157744
It seems it only reads the red color map for black to white.
0
 

Accepted Solution

by:
AntonKarlsson earned 0 total points
ID: 26159102
I had no patience waiting so I solved it myself now.

It seemed two faults:

1. I realized that internalFormat should be 4 instead of bypp(1).
And:
2. That it should be 256 instead of mapSize(128).
if (palette)	// If the image is paletted:
{
	type = (bipp == 8) ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT;
	format = GL_COLOR_INDEX;
	internalFormat = 4;//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 / 256;//mapSize;
		Gmap[i] = (GLfloat)pColor->g / 256;//mapSize;
		Bmap[i] = (GLfloat)pColor->b / 256;//mapSize;
		Amap[i] = (GLfloat)pColor->unused / 256;//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

Correct.jpg
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question