Is there a way to do a simple palette swap on an OpenGL texture, and how? All I want to do is take an existing texture and replace colors around. For example turning a red Koopa in mario bros into a green one by replacing all red pixels with green, etc.
Thanks in advance. Sorry for asking such a lame question, but Google doesn’t want to help me on this one.
You have to change yourself the texture and re-upload it with glTexSubImage
Thanks for your reply. Although I could attempt the code to your solution, I would rather not if I don’t have to. I use more than one image loader, and it would be cumbersome if I had to manipulate the string I pass into glTexImage2D, or use glTexSubImage.
Is there a way to achieve a pseudo-“palette swap” effect using GLSL? I don’t really care about the OpenGL texture itself being manipulated, just the output. I am writing a 2D tiling application. Sorry I’ve been away from the forums for way too long, and I’ve never dorked with GLSL.
yes you can do that with glsl.
I would rather not if I don’t have to. I use more than one image loader, and it would be cumbersome if I had to manipulate the string I pass into glTexImage2D, or use glTexSubImage.
uh, what string ?
whatever, it is not a good design IMHO to link image loader directly to opengl, what about loaders that whould return the texture data, then other functions that do the actual uploading ?
If you really don’t want to change your current design, consider using glGetTexImage* calls after loading texture to re-get it, modify it, then re-upload to a different texture name id with glBindTexture.
BTW palette tricks are no more used since quake2 (player color was hardcoded within skin) and GL_EXT_paletted_texture is really deprecated.
You can emulate it with a GLSL shader, but that means a lot of processing for each frame, and modern hardware. Depends on your usage of course. Can you tell more about it ? Are the color swap infinite, or do you have a fixed sets of color combinations ?
By string, I meant the GLvoid *pixels param.
The color swap is infinite. I am making a 2d isometric engine similar to old-school Final Fantasy. In my design, if I had a single image representing a human, I would need to be able to set the skin color, hair color, eye color, etc. However, there is only one color that represents hair color, and so on.
I am attempting to duplicate the texture data and modify the colors on the cloned one. So, in my design I need to have multiple instances of similar texture data, the only difference being the colors. In this point in development, I can change the design if I need to.