OpenGL using color and texture on a quad

I want to use color and texture on a quad as such that the texture will appear darker with a color like brown or black. I wish to use this to light the textured quads much like XNA SpriteBatch.draw(Texture2D texture, Vector2 Position, Color color); (I am porting a game from XNA to LWJGL)

E.g. like this: (XNA)

As you can see the texture has been colored by the game’s colored lighting method. Is there any way to do this in openGL?

Welcome to JGO :slight_smile:

Take a look here:
http://lwjgl.org/wiki/index.php?title=Slick-Util_Library_-Part_1-_Loading_Images_for_LWJGL

You will need to set a colour also before you draw each vertex (or just the first if you want all vertices to be the same colour).
Do this with:

GL11.glColor3f(1,1,1); //RGB

Note that the color of glColor and the color sampled from the texture are multiplied together, meaning that if your color is red (1.0, 0.0, 0.0) and your texture sample is green (0.0, 1.0, 0.0) you’ll end up with black (10, 01, 0*0), but I assume that’s how the XNA function works too. =P

Now I understand what I did wrong. I was using glColor3b(255, 255, 255);, which dosn’t seem to work. The float method works just fine though, so I have to divide the bytes by 255F!

For some strange reason dividing a byte by a float seems to generate numbers like: -0.003921569 ((byte) 255 / 255F). Does anyone know why this is?

(byte) 255 = -1

A byte has range of -128 to 127. If you set it to 255 it ends up as -1 since it subtracts 256 from it… xd