Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (492)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  tint a texture with openGL  (Read 4572 times)
0 Members and 1 Guest are viewing this topic.
Offline Thyast

Senior Newbie




I'm not superstitious, it brings bad luck.


« Posted 2003-11-21 13:23:14 »

Hello,

Now that I have managed to make a basic openGL rendering for my 2D tile based strategy game, I'm trying to impove it.

What I would like to do now is tint terrain in red when it's in unit's fire radius. The terrain is oubviously rendered with textures mapped on squares. So I would like to tint these textures with a transparent red color so that it looks like it is seen through a red glass. 'hope this is clear  :-/

So how could I achieve this in an efficient way ? Playing with lights ? Create an already tinted texture beforehand ? Or another mean ?

Just one thing : I do not want to draw a transparent red circle since the fire *radius* does not mean a circle in my case. I really need a tile based processing.

Thanks for your help.  Smiley
Offline kevglass

JGO Kernel


Medals: 159
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #1 - Posted 2003-11-21 13:28:13 »

The polygons that you're using for your sprites and tiles can have colours assigned to each vertex using glColor3f() (just like glVertex2i). If you apply a colour to the verticies it will effect the texture (by tinting it)

Kev

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #2 - Posted 2003-11-21 13:31:43 »

Best way would probably be with vertex colours, then you get to control the exact colours instead of tricky tinkering with lights.

You'll just need to add an extra colour value for each vertex, which means using glColor3f style calls if you're using immediate mode, or glColorPointer for vertex arrays. Then you'll want to glEnable with GL_COLOR_MATERIAL and map the colours to the diffuse colour with glColorMaterial.

A bit of a mouthful, but easy once you see it in code. Then your texture just gets multiplied with the vertex colours at every pixel which should give you the tinting you're after.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 369
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2003-11-21 16:21:37 »

Don't listen to him, he's mad Cheesy

Enable texture modulation with glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
Then tint the vertices of your tiles with whatever colour you choose using glColor3f(). Obviously, glColor3f(1.0f, 1.0f, 1.0f) will keep be "untinted" as you're not filtering any colour out at all by modulating with white.

Don't bugger about with lights Wink Far too complex.

Cas Smiley

Offline Thyast

Senior Newbie




I'm not superstitious, it brings bad luck.


« Reply #4 - Posted 2003-11-23 12:45:28 »

Thanks for your replies.

So I've tried glColor3f and it sort of do the trick.  But now I know that it isn't really the effect that I was looking for as green textures obviously go brown when applying a red filter whereas I wanted to have it in levels of red. So I guess the only thing to do is making a grey level texture from each texture and use it when original texture should be "tinted".

So now my problem is : how do you make grey levels in a simple manner ? Is there some sort of GL functions to do this or will I have to average all the RGBs at loading time ?

And by the way Orangy Tang and Princec could you please explain in a few words what glColorMaterial and glTexEnvi are supposed to do ? I'm not sure to understand.

Thanks again for your help.
Offline princec

JGO Kernel


Medals: 369
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #5 - Posted 2003-11-23 13:03:06 »

glColorMaterial is only used with lighting, which I don't think you're using, so don't worry about it just yet!

glTexEnvi affects the way textures are applied to polygons. There are four modes, two of which are of usually of interest: GL_REPLACE and GL_MODULATE.

When you draw a polygon in GL, each vertex is given the colour last set by a call to glColor*. If it were untextured, it would draw that vertex in that colour.

If you enable texturing on the polygon, you've now got two colours for any pixel to choose from: the first, original colour you're getting with glColor* calls; and the second colour, which is looked up from the texture (ie. it's the texture pixels). These two are combined according to what glTexEnv is set to when the polygon is drawn.

If you use GL_REPLACE, the original glColor colours (known as the "fragment" colour) is simply ignored, and the texture colour is simply drawn.

If you use GL_MODULATE, the texture colour and the fragment colour are multiplied together, to give you a modulated or filtered colour. So setting glColor3f(1.0f, 0f, 0f) will completely filter out all the green and blue from the texture, giving it a blood red appearance.

Cas Smiley

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #6 - Posted 2003-11-23 13:53:47 »

Oops, colour material is indeed only for when you're using lighting as well, you can safely ignore it.

The modulate option is the default I think, but as you've found it can only darken an existing texture. Although if you use the EXT_texture_env_combine extension with glTexEnvi you can set a scale value so you can overbright your textures. With a scale of 2 you can then make a grey of (.5, .5, .5) the normal texture colour, and anything higher will brighten it.

http://www.berkelium.com/OpenGL/EXT/texture_env_combine.txt
Somewhere in the middle it talks about setting the scale value.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Thyast

Senior Newbie




I'm not superstitious, it brings bad luck.


« Reply #7 - Posted 2003-12-10 13:24:25 »

Sadly this extension is not included in GL bindings for SWT. Can someone explain me what is the theory bind additive coloring of textures so that I can make it 'by hand' ?
Could it just be averaging texture RGBs to get a grey value of the texel and then average again with wanted color ?

Thanks
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (16 views)
2014-08-31 22:59:12

TehJavaDev (24 views)
2014-08-28 18:26:30

CopyableCougar4 (33 views)
2014-08-22 19:31:30

atombrot (42 views)
2014-08-19 09:29:53

Tekkerue (41 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (26 views)
2014-08-16 06:20:21

Tekkerue (37 views)
2014-08-16 06:12:11

Rayexar (73 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!