I'm trying to put together a relatively simple isometric-perspective game, and I'd like the ability to 'ghost out' various portions of the screen as part of UI feedback. Specifically, when the player is trying to place a specific building, I'd like to have the building-preview (and possibly underlying terrain) turn red or green depending on whether it's over a legal or illegal location.

As in, for every pixel corresponding to the elements in question, I'd average the RGB components, and then set either R, G or B to that exact value (with 0 in other components.) How would I go about this?

Well, I mean imagine a standard RTS, where you're placing a new building- the little image of the building will turn different colours depending on where you're trying to put it. I'm almost certain you wouldn't need a vertex shader for something like this, since I saw this effect back 10-15 years ago.

I'd imagine you could use different textures for them,or perhaps blending different textures say(a red texture + original texture)

Shader's aren't as ugly as they sound, I just found that out.

I'm sure you don't NEED a shader, but it is very practical, in my opinion. Just load the shader to change the color balance of the texture, if it is picked/under mouse, or selected, then unload it after.

If there's another way to achieve this effect in JOGL(OpenGL even) I'd be interested as well. However, I've googled for probably 15(collectively) hours to find an alternative to shaders using JOGL for changing the color balance of a textured object, and came up with nothing.

I'm actually about to write a shader for this for practice and possibly for my own personal project, if you'd like I could post the code here?

And just as a little side-note... If you've seen that effect 15 years ago, I gaurantee you DO NOT want to structure your code/game in a similar method. The complexity of it would be mind numbing and beyond fruitless for the hours put in versus the product received. Maybe I'm biased but I believe using a shader has to be better then down-stepping technology to below OpenGL 1.3(when I believe GLSL was invented/implemented).

I'm sure you don't NEED a shader, but it is very practical, in my opinion. Just load the shader to change the color balance of the texture, if it is picked/under mouse, or selected, then unload it after.

If by "practical" you mean "won't work on the majority of laptop computers" then yes, using a shader is practical.

For a non-shader approach it depends exactly what effect you're after. If you just need the "can place"/"can't place" feedback then just changing the vertex colours will multiply the texture by the vertex colour so a light green or red will give the sprite a green or red appearence (but with the side effect of making it darker too, since you're multiplying).

Alternatively you can use glTexEnv with DOT3 to make your sprite greyscale, or SECONDARY_COLOR to tint a sprite towards a specific colour. Both of which will work on pretty much any hardware still in use today.

Alternatively you can use glTexEnv with DOT3 to make your sprite greyscale, or SECONDARY_COLOR to tint a sprite towards a specific colour. Both of which will work on pretty much any hardware still in use today.

Alternatively you can use glTexEnv with DOT3 to make your sprite greyscale, or SECONDARY_COLOR to tint a sprite towards a specific colour. Both of which will work on pretty much any hardware still in use today.

How, exactly, would I use glTexEnv with DOT3 again? I mean, what's the precise syntax? Are you talking about generating a secondary texture?

1. render the item to the stencil buffer2. render it for real3. render a semi-transparant red/green quad using the 'shape' in the stencil buffer

No shaders, and it looks perfect, as there is a colored haze over the item, independant of the item's texture - even a totally black item would end up red-ish or green-ish.

If you're just looking to tint a texture then SECONDARY_COLOR is a better option IMHO. Whereas vertex colours multiply the texture colour with an additional colour, secondary colour can be added on top - so you can either brighten a texture or shift it's hue towards a specific colour (including rendering a sprite as pure white, which can be very useful for masking effects).

Now if you wanted to tint towards purple at 80% then you set that as your secondary colour (1, 0, 1), and set the primary vertex colour as (1 - tintAlpha, 1 - tintAlpha, 1 - tintAlpha, 1), in this case (0.2, 0.2, 0.2, 1).

This only requires a single draw call, and you don't need a pesky stencil buffer either.

I'd forgotten about the pesky -0.5 in the DOT3 extension, stupid bumpmapping hacks. However if you combine that with SECONDARY_COLOR above you could use that to add 0.5 onto your texture colour and hopefully eliminate the clamping.

However I'm not entirely sure what order those operations are done in, so you might find that the colours have already been clamped before the +0.5 gets applied.

I might be a bit off mark here, but is this the sort of effect you're looking for:

Very similar, yes. (The screen looks nice, by the way- where'd you get it from?) I'll use vertex colouring if push comes to shove, but I'm reasonably sure there must be some simple method for getting true greyscale, and then tinting toward a specific colour.

Quote

This might sound dumb but what if you multi-textured it and made a screen-texture for the second texture...

Oh, sure- you can manufacture luminance textures easily enough... I dunno. It just seems sort of like a waste of memory...

Quote

I'd forgotten about the pesky -0.5 in the DOT3 extension, stupid bumpmapping hacks. However if you combine that with SECONDARY_COLOR above you could use that to add 0.5 onto your texture colour and hopefully eliminate the clamping.

However I'm not entirely sure what order those operations are done in, so you might find that the colours have already been clamped before the +0.5 gets applied.

I'll try and give that a shot and see what the results are, thanks. (Mind you, I'd be quite interested to know how DOT3 is used for bumpmapping. )

(Mind you, I'd be quite interested to know how DOT3 is used for bumpmapping. )

This is getting somewhat before my time, but IIRC the idea is to put the current light direction and strength into the vertex colour, then DOT3 that with a normal map texture. The output of that gives you a bumpmapped light intensity, which you then need further texenv shenanigans to multiply by an additional base texture to give your final lit output.

Things get even fruitier when you're dealing with proper 3d and have to deal with object space or tangent space normal maps, or if you want to do specular as well, but for the basic 2d effect that should be all you need.

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