PDA

View Full Version : Color reduction problem with textures



Kilam Malik
11-11-2000, 03:00 PM
Hi,

got a problem with textures. On a tnt2 I get the 24-bit texture as I specified it. On a tnt with the same code I get the texture in 16 colors. But the display has 24-bit (I render a cylinder in front of the background-texture and it has smooth transitions).

Here is the source I use to initialize the texture:




glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // low: GL_NEAREST, high: GL_LINEAR.
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); // low: GL_NEAREST, high: GL_LINEAR.

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

glTexImage2D(GL_TEXTURE_2D, 0, 4, imgWidth, imgHeight, 0,
GL_RGBA, GL_UNSIGNED_BYTE, imgRaster);

glEnable(GL_TEXTURE_2D);


Any suggestions?


[This message has been edited by Kilam Malik (edited 11-11-2000).]

Pauly
11-11-2000, 03:39 PM
glTexImage2D(GL_TEXTURE_2D, 0, 4, imgWidth, imgHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, imgRaster);

You've got a number '4' where you should be specifying an internal texture format hint. Try GL_RGB8 if you're not using an alpha channel and see what happens.

<edit>: Oops! I forgot to mention that your driver is allowed to ignore this if it wants too http://www.opengl.org/discussion_boards/ubb/smile.gif

Paul.

[This message has been edited by Pauly (edited 11-11-2000).]

Kilam Malik
11-12-2000, 10:52 PM
The SuperBible, MSDN Help and NeHe's Tutorial tells me to insert the number of values per pixel as third parameter. So I used 4 as I have an alpha value. What define
should I use in your opinion with 4 components for each color as byte, as GL_RGB8 is for RGB only?

Kilam.

mcraighead
11-13-2000, 01:13 AM
Your documentation is out of date. 1, 2, 3, and 4 are defined to be equivalent to GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, and GL_RGBA, respectively.

Try GL_RGBA8.

- Matt

Kilam Malik
11-15-2000, 12:54 AM
Thank you both, that was the solution ;-)