Yo!
A while ago I made a start on converting the Dr Lunatic code to use SDL/OpenGL for rendering. I didn't get that far, it literally just fades the Hamumu logo in and out again, but I did write a shader that draws images using a palette, which I thought might be useful. (It surprised me how simple it is to do that.)
Vertex shader:
#version 150
in vec3 aPosition;
in vec4 aColor;
in vec2 aUV;
out vec4 vColor;
out vec2 vUV;
uniform mat4 uProjectionMatrix;
void main() {
gl_Position = uProjectionMatrix * vec4( aPosition.xyz, 1 );
vColor = aColor;
vUV = aUV;
}
Fragment shader:
#version 150
uniform sampler2D uTexture;
uniform sampler1D uPalette;
in vec4 vColor;
in vec2 vUV;
out vec4 fragColor;
void main() {
int colorIndex = int(255.0 * texture(uTexture, vUV).r);
vec4 texel = texelFetch(uPalette, colorIndex, 0);
fragColor = vColor;
fragColor *= texel;
}
The palette is sent by just telling opengl to load its memory as a 1D texture. Images are sent as-is to the GPU, as 2D, single-channel textures. It means you can still use the original palette-switching code, and 256-colour bitmaps, without changing them.
Theoretically using opengl would be faster than software-rendering, but I never got far enough to test that assumption, and rendering the game itself is obviously a lot more complicated than a flat image, and might require a decent amount of restructuring.
So yeah, I don't know how helpful this is, or whether that's even a direction you'd want to go in, but I thought it's better to actually share this than just leaving it rotting on my HDD. (Maybe you already know graphicsy stuff, so I really hope this doesn't seem patronising!) The whole repo is at https://bitbucket.org/AtkinsSJ/glunatic (Not github because it was private until just now and github doesn't have free private repos and I am cheap. Sorry.) Feel free to yell at me if you have any questions.
Yo!
A while ago I made a start on converting the Dr Lunatic code to use SDL/OpenGL for rendering. I didn't get that far, it literally just fades the Hamumu logo in and out again, but I did write a shader that draws images using a palette, which I thought might be useful. (It surprised me how simple it is to do that.)
Vertex shader:
Fragment shader:
The palette is sent by just telling opengl to load its memory as a 1D texture. Images are sent as-is to the GPU, as 2D, single-channel textures. It means you can still use the original palette-switching code, and 256-colour bitmaps, without changing them.
Theoretically using opengl would be faster than software-rendering, but I never got far enough to test that assumption, and rendering the game itself is obviously a lot more complicated than a flat image, and might require a decent amount of restructuring.
So yeah, I don't know how helpful this is, or whether that's even a direction you'd want to go in, but I thought it's better to actually share this than just leaving it rotting on my HDD. (Maybe you already know graphicsy stuff, so I really hope this doesn't seem patronising!) The whole repo is at https://bitbucket.org/AtkinsSJ/glunatic (Not github because it was private until just now and github doesn't have free private repos and I am cheap. Sorry.) Feel free to yell at me if you have any questions.