PDA

View Full Version : How to use glColorTable ?(attach code)



LLM
05-25-2006, 11:10 PM
this is my code:


GLubyte table[256][4];
int i;

for (i=0;i<256;i++) {
table[i][0] = 255;
table[i][1] = 0;
table[i][2] = 0;
table[i][3] = 255;
}


glColorTable(GL_COLOR_TABLE,
GL_RGBA8,
256,
GL_RGBA, GL_UNSIGNED_BYTE,
table);

BYTE texture[8*8];
for(i=0; i<8*8; i++)
{
texture[i] = i;
}

glBindTexture(GL_TEXTURE_2D, TextureIndex);

glTexParameteri(GL_TEXTURE_3D,
GL_TEXTURE_WRAP_S, GL_REPEAT);

glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);

glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);

glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glTexImage2D(GL_TEXTURE_2D,
0,
GL_COLOR_INDEX8_EXT,
8, 8,
0,
GL_COLOR_INDEX,
GL_UNSIGNED_BYTE,
texture);Is anyting Wrong? If it was correct, the texture
color should be red. But it's not red. why?

Trahern
05-26-2006, 04:48 AM
Well, In fact I dont know anything about glColorTable as I have never used it however can I ask you why do you post this question in OpenGL Shading language forum? Maybe you would receive better answers in some other forum.

Relic
05-29-2006, 03:54 AM
GL_COLOR_INDEX8_EXT requires the extension GL_EXT_paletted_texture.
http://oss.sgi.com/projects/ogl-sample/registry/EXT/paletted_texture.txt
Read the "Support" paragraph carefully.

mabraham
05-29-2006, 05:55 AM
Support for GL_EXT_paletted_texture is very limited; it is supported on many NVIDIA chipsets EXCEPT the more recent NV4x. Thus, whether the author of the original post intended or not, the topic is somewhat relevant to this forum because a very simple fragment shader can achieve the same effect as GL_EXT_paletted_texture.

Compile and bind the following program, and set the values of 'tex' and 'palette' to the numbers of the texture units that hold your indexed texture (2-D) and colour table (1-D), respectively.

uniform sampler2D tex;
uniform sampler1D palette;

void main()
{
gl_FragColor = gl_Color * texture1D( palette, texture2D( tex, gl_TexCoord[ 0 ].st ).r );
}

Komat
05-29-2006, 11:05 AM
Originally posted by mabraham:

gl_FragColor = gl_Color * texture1D( palette, texture2D( tex, gl_TexCoord[ 0 ].st ).r );
This will only work if point filtering is enabled for both textures. Unless I am mistaken the paletized textures have the lookup done before any filtering is applied.

mabraham
05-29-2006, 12:18 PM
Komat, I'm sure you're right (incidentally, I only ever used that shader with nearest neighbour filtering enabled for both units).

I guess one would have to do linear interpolation in the shader if that is desired?

Komat
05-29-2006, 01:38 PM
I guess one would have to do linear interpolation in the shader if that is desired? Yes

LLM
05-29-2006, 11:29 PM
Thanks all. I'm confusing with the fast volume rendering. I thought using glColorTable should
be more effective.