changing texture colors

Started by
2 comments, last by dpadam450 12 years, 10 months ago
I am using SDL/Opengl in a game project, I am using textures with specific colors that I wish change to another ( on user choice, eg, replacing grey section by green color, blue section by red, etc .. )

My first solution was to load a SDL_Surface and changing every pixel from one color to another, but that is not really fast, is it possible to do a dynamic color change in a texture with opengl ?
Advertisement
One way is to use a lookup table which is actually a texture.
http://www.opengl.org/wiki/Common_Mistakes#Paletted_textures
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Ok thanks, I this the best and smipler way is to use a shader..
If your doing something like team color markings, you can make a 2nd texture that overlays your actual texture with all white and alpha (or just an intensity from 0 to 1). Where 1 or white is where you want team color markings to show up. Then you can just send a color to the shader and it will be something like:

glFragColor = baseTexture.rgba + colorOutlineTexture.a*glColor;

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

This topic is closed to new replies.

Advertisement