How would I generate a two-dimensional texture of indexed colors to go with an exported palette?

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?

If I’m understanding this right you’ll want to click on the 3 line button above the palette section and select new palette from image? On second thought it looks like you already did that. If you mean so it’s condencedd into a png. You can do that by going to save palette again under those 3 lines save it as a png that way. Here it is that way if that helps
image

I FINALLY FIGURED IT OUT.

By changing the R G and B value of each pixel to the corresponding index in the palette, the color gets indexed to the proper one. I don’t know if this is the right way to do palettes but it works so I’m not complaining.