I am trying to get palettes working with my opengl program, so I wrote a simple shader to take in a 256x1 texture for the color lookup table and the image itself.
#version 330 core
in vec2 TexCoords;
uniform sampler2D image;
uniform sampler2D Palette; // A palette of 256 colors(256 x 1)
void main()
{
// Pick up a color index
vec4 index = texture2D(image, TexCoords);
// Retrieve the actual color from the palette
vec4 texel = texture2D(Palette, index.xy);
gl_FragColor = texel; //Output the color
}
How would I generate an indexed image that simply contains the index of the color that its supposed to represent on the palette instead of rgb color data?
My current working example:
On the left is the original image that i am plugging into the shader as “image”. In the middle is the 256 x 1 texture or “Palette” that I want to use. On the right is the monstrosity that is spit out. I know that it shouldn’t work because the image is in RGB_A format instead of indexed but how do I go about authoring an indexed texture? How do I control which pixel corresponds to which color on the palette?