Okay, so I’m learning OpenGL through LWJGL, and I am starting to learn to program in a more procedural manner because of it. (I consider this to be a step back, but what can you do?) I have some experience with Slick2D, and know a few concepts from LibGDX, but now I’m trying to make my own library that functions like these two. I feel that by making my own library, I’ll be able to know exactly what is going on under the hood and won’t rely on these wrappers to talk to OpenGL for me.
BUT I DIGRESS! Right now, I am trying to program Quad class that will allow shading to occur. More specifically, I want to apply a tint to textures that I have binded. Currently, my rendering code looks like this…
// Renders quad
public void render()
{
texture.bind();
// Mins and maxes for which parts of the image to select
float minX = srcX / (float)texture.getImageWidth();
float minY = srcY / (float)texture.getImageHeight();
float maxX = srcX2 / (float)texture.getImageWidth();
float maxY = srcY2 / (float)texture.getImageHeight();
// Begins drawing a quad
GL11.glBegin(GL11.GL_QUADS);
GL11.glColor3f(v2Shade, v2Shade, v2Shade);
GL11.glTexCoord2f(maxX, minY);
GL11.glVertex2f(srcX2 - srcX, 0);
GL11.glColor3f(1, 1, 1);
//
GL11.glColor3f(v3Shade, v3Shade, v3Shade);
GL11.glTexCoord2f(maxX, maxY); //
GL11.glVertex2f(srcX2 - srcX, srcY2 - srcY);
//
GL11.glColor3f(v4Shade, v4Shade, v4Shade);
GL11.glTexCoord2f(minX, maxY); //
GL11.glVertex2f(0, srcY2 - srcY);
//
GL11.glColor3f(v1Shade, v1Shade, v1Shade);
GL11.glTexCoord2f(minX, minY);
GL11.glVertex2f(0, 0);
GL11.glEnd();
}
This is all fine and dandy, but glColor3f only really darkens the colors. That’s good enough for me in most cases, but what if I want to apply a tint? The tint, of course, could be for lighting. Maybe the light is particularly yellow, and the texture would be more yellow than usual. It would be useful if there was a method like…
glTint4f(float red, float green, float blue, float intensity);
As far as I know, though, OpenGL has no such function. Is their a painless way to do this? Shading is already painless.