I'm coding a fighting game in which each character has a great number of sprites, and each character has several different palette swaps. I've been trying to use a grayscale texture for each sprite, and a 256x1 texture for each palette.
My shaders look like this:
Vertex:
varying vec2 coord;
void main(void)
{
coord = gl_MultiTexCoord0.xy;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
Fragment:
uniform sampler2D palette;
uniform sampler2D texture;
varying vec2 coord;
void main()
{
gl_FragColor = texture2D(palette, vec2(texture2D(texture, coord).r, 0));
}
"palette" is set to 1 and "texture" is set to 0 with glGetUniformLocation and glUniform1i. They compile fine and link fine. I'm able to use the program object in my draw code.
The problem is, I have no idea how to use multitexturing to get the "palette" and "texture" textures cooperating with each other in the shader. This is my first time using multitexturing, and I can't seem to figure out how to get it to work for this kind of solution. Does anyone know how, with these shaders (if they are correct) to simulate a palette swap?
EDIT: Here's my drawing code right now:
glUseProgram(paletteProgram);
glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, palette);
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_QUADS);
glTexCoord2f(w1, h1);
glVertex3f(x1, y1, 0);
glTexCoord2f(w1, h2);
glVertex3f(x1, y2, 0);
glTexCoord2f(w2, h2);
glVertex3f(x2, y2, 0);
glTexCoord2f(w2, h1);
glVertex3f(x2, y1, 0);
glEnd();
glUseProgram(0);