PDA

View Full Version : general question - greying out RGB textures?


WhatMeWorry
2004.10.21, 03:18 PM
I've got a game with colored units (textures mapped into
rectangles) which move one a game board. The user selects
them with a mouse and moves it to a new game square.

I want to create an effect where the moving unit is greyed out
over the game board squares (and maybe even fades out the
its movement points are expended.

Can anybody suggest a very general approach to such an
effect? I'd like to avoid creating another texture map for
each unit as there are quite alot of these guys.

Thannk!

Simon Schoelly
2004.10.21, 06:09 PM
hope this is correct:
glTextureEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTextureEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGB); /* or GL_DOT3RGBA if you want to use color and alpha values for the calculation */
/* the next two lines are not in every case necesary */
glTextureEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
glTextureEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR);

Then you can use glColor4f to set how much of every color channel should be used in the calcuation and to set the brightnes of your texture.

source: the red book p. 438

arekkusu
2004.10.21, 06:20 PM
Define "grey out"... do you mean lowering the contrast of the image towards neutral grey? If so you can do this just by mixing the texture with 0x7f7f7fff with texture_combine.

If you mean converting the RGB texture into a luminance value ("Grayscale" in Photoshop), then you either need a fragment program or another texture. If you keep the client copy of the texture data then you can reupload it as a luminance texture, fiddling with the glPixelTransfer RGB scale to get a balanced grayscale image. Of course this is slow and eats more texture ram.