Mapping a lookup table to a image using shaders

hi ,
i m trying to map a lookup table of 256 entries to a image.

i ve created a 1D texture for this lookup table

glGenTextures(1, &texId1);
glBindTexture(GL_TEXTURE_1D, texId1);
glTexImage1D(GL_TEXTURE_1D, 0, GL_LUMINANCE8, 256, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, palette);

also i ve created a 2D texture for a image

glGenTextures(1, &texId2);
glBindTexture(GL_TEXTURE_2D, texId2);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image_ip->width, image_ip->height, 0, GL_RGB, GL_UNSIGNED_BYTE, image_ip->pixels);

now i want to map this 1d texture lookup table to this 2d texture image using shaders.
how to a get these textures in fragment as well as in vertex shaders and map it .

I’m not sure I understand what you are intending to do here.

Since you call the 1D image a “palette”, that sounds like you want the pixel data for the 2D texture to refer to colors stored in the 1D texture. If that’s the case, then the 2D texture needs to be a single-channel texture (consider GL_R8 if your implementation supports it), and your 1D palette should be an RGB texture.

Just turn off filtering for both textures, and you should be fine.

thanks for ur immediate reply. i’ve just started learning about shaders.my actual work is to do image windowing with mouse control.
i ve did this using normal opengl using textures

glGenTextures(1, &texId2);
glBindTexture(GL_TEXTURE_2D, texId2);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image_ip->width, image_ip->height, 0, GL_RGB, GL_UNSIGNED_BYTE, image_ip->pixels);

i m having a 1D array of 256 values as palette.
so every time i move my mouse the palette values changes and i replace (image_ip->pixels) image pixel data with the changed new palette.so now i’m creating a new texture for every single move in my mouse.this appears to be very slow. the performance gets very slow when i do it with very big medical images.

so i read in the forums, the same work can be replaced with shaders which inturn will increase the perfomance much better.is that true ?

just only once the texture will be created and the palette values has to be mapped to this texture data.every time the palette changes, the texture data mapping with the palette has to be updated.
i tried in shaders like this. but it dint work. do correct me wher i went wrong.

vertex shaders

void main(void)
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}

fragment shaders

uniform sampler2D myTexture;
uniform sampler1D lut;
void main (void)
{

float color = texture2D(myTexture, gl_TexCoord[0]);
vec4 col = texture1D(lut, gl_TexCoord[1]);
gl_FragColor = texture1D(lut, color);

}

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.