Color * Texture

Started by
13 comments, last by ufinii 18 years, 4 months ago
I am working on a 2D game with LWJGL and I want to implement a method to change to bright a Sprite (Texture) with a particular color... It would be something like illuminate(float red, float green, float blue) where values are from 0.0 to 2.0 (from 1.0 to 2.0 for overbrighting)... How is, in general, the right way to realize that?
http://fuffi.nj-h.com/
Advertisement
Quote:Original post by ufinii
I am working on a 2D game with LWJGL and I want to implement a method to change to bright a Sprite (Texture) with a particular color...

It would be something like illuminate(float red, float green, float blue) where values are from 0.0 to 2.0 (from 1.0 to 2.0 for overbrighting)...

How is, in general, the right way to realize that?


I don't know about LWJGL, but if you are using OpenGL with lighting & materials, GL_EMISSION with a high value in all the colors will make the material look brighter. If it's simple color (no lighting), then you could bind your textures with GL_MODULATE and make all vertices of color, let's say (0.8, 0.8, 0.8), and the one you want bright (1, 1, 1).

If that doesn't help, try more advanced techniques like real glow.
hmmmm well thanks...

so i set a glColor3f(r,g,b) before the glBegin() right?

and what would you suggest for the overbright thing?
http://fuffi.nj-h.com/
Quote:Original post by ufinii
hmmmm well thanks...

so i set a glColor3f(r,g,b) before the glBegin() right?

and what would you suggest for the overbright thing?


You could. But you usually set the color per vertex, e.g. inside glBegin-glEnd before each glVertex.

Assuming you don't use lighting, and that you put you r sprite on a quad.
Call glColor3d(0.8, 0.8, 0.8) befor glBegin. Enable texturing and bind your texture (don't forget GL_MODULATE). Render the quad (all verices will be bright gray modulated with the texture - the texture will look a bit darker than it should). Then when rendering the bright sprite, call glColor3d(1, 1, 1) and render it. The sprite will look like it should, but because other are darker this one will look brighter.
hmm what i mean is this:

i have a texture and i want to overbright it with white (it becomes white)... which values i have to set in glColor3f() for example to do it?
http://fuffi.nj-h.com/
Quote:Original post by ufinii
hmm what i mean is this:

i have a texture and i want to overbright it with white (it becomes white)... which values i have to set in glColor3f() for example to do it?


Brighter, or completely white? Nevermind, looks like the basic stuff doesn't work.

Render all sprites as usual. Then create a mask of your sprite, bind it as a texture on a white quad, and render it with a certain alpha on top of the sprite you want bright.

By mask, I mean every opaque pixel of your sprite should be (1, 1, 1, 1) and every transparent pixel should be ([any values for RGB], 0).
I think there is a shorter way to do it (luminance texture, maybe even multitexturing) but creating mask should work.

The mask should be bound on quad of same size and position as your sprite. Draw it on the same position, the alpha being from 0 to 1 will make your sprite go from original to completely white. (Depth function less or equal)
sorry I didn't explain good...


what i want is:

texture.bright(r,g,b)

if i do bright(0.0f, 0.0f, 0.0f) the texture becomes black
if i do bright(1.0f, 1.0f, 1.0f) the texture is equal
if i do bright(2.0f, 2.0f, 2.0f) the texture becomes white

other values are interpolations between this 3
http://fuffi.nj-h.com/
Quote:Original post by ufinii
sorry I didn't explain good...


what i want is:

texture.bright(r,g,b)

if i do bright(0.0f, 0.0f, 0.0f) the texture becomes black
if i do bright(1.0f, 1.0f, 1.0f) the texture is equal
if i do bright(2.0f, 2.0f, 2.0f) the texture becomes white

other values are interpolations between this 3


Try out the masking like I said. I don't know how you handle the transparency of sprites, but most likely a second texture (either loaded from file or generated during runtime) will be necessary.

You want bright to be from 0 to 2, right?

K = 0 to 1:
The mask should be in black color, and alpha is 1-K
K = 1 to 2:
The mask should be in white color, and alpha is K-1

I think if you try out different blending functions, you might be able to do it with only one mask texture (maybe even with none).
There might also be an extension which extends GL_MODULATE, and then you won't have to render mask at all.

If you still want more detailed help, you might want to post some code, and also explain how are your sprites stored (RGBA, tranparent color key, mask sprite etc.).
I've never done this myself, but off the top of my head I would think you can use a number of techniques;

One would be to continually manipulate the pixels of the image in main memory and keep reloading that data back to the texture object. ie. when you load your image from a file you can take a copy of the pixel data and multiply the pixel colors of the copy by some factor to lighten or darken the image, then load or reload that data back to the texuture unit. Costly in terms of memory usage and performance.

Multitexturing should also be able to perform something like this relatively easily. Generate a grey texture depending upon how much darkening or lightening you want and set your first texture unit as the base texture, the second as the grey texture, and combine.

I believe there are also some OpenGL extentions are available to perform the darkening/lightening of a texture using a combo of multitexturing and blending calls. I read something like this on gamedev I think. I will see if I can find the post, but it basically mentioned using glTexEnvi GL_COMBINE_EXT, GL_SOURCE1_RGB_EXT, GL_OPERAND_RGB_EXT and I think a blending function. Suffice to say, without finding the message I am guessing. Sorry. Perhaps a little searching will turn up results.

Of course, lastly, this is all probably very easy in a shader - which I have no experience with so we need someone more knowledgeable to comment.

Note: these are ideas completely off the top of my head. I do not know if these would realistically work! I will look for the post I read that mentioned the extentions.

hth
F451
you also have to understand that mine were only examples... it's not only black and white thing... I also want to bright textures with colored "mask" :)
http://fuffi.nj-h.com/

This topic is closed to new replies.

Advertisement