Change image colour

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
jpspe
Posts: 10
Joined: Fri Feb 22, 2008 8:30 am

Change image colour

Post by jpspe »

Hi,

I have created a font system using images. The image consists of black letters with anti-aliasing. I would know like to change the colour of the image at runtime from black to say orange. The problem I'm having is to do with anti-aliasing. I worked out a quick way to subtract the differences between pixels, and the result is not bad... however, it is still not good enough.

How can I change the colour of my black anti-aliased image to another colour?

Thanks
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

You need to use MODULATE. See my pgeFont library for more details.

http://insomniac.0x89.org/index.php?id=77
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

Split each pixel into R,G,B values as seperate bytes,
calculate mean average of each.
Use that value as the level of transparency for each pixel.
That's one way that works if the image is greyscale.
Art.
If not actually, then potentially.
danzel
Posts: 182
Joined: Fri Nov 04, 2005 11:03 pm

Post by danzel »

Some more possible ways:

Make your image white characters on a transparent background and use glcolor/gu-something-color or vertexes with a color component to colorise it when rendering.

Or you could use CLUTs with different color bands.
User avatar
jean
Posts: 489
Joined: Sat Jan 05, 2008 2:44 am

Post by jean »

The canonical way of doing this is to save the entire charset as a whole image with the chars monospaced and drawn in white on a white background, delineated only with alpha. In your rendering functions you can use sprites (what in standard openGL is called billboarding or impostoring) with the desired letter (portion of the charset texture) mapped onto it and the desired color specified as the "vertex" color. Be sure to set the GE state machine properly (i.e. texture mapping on, alpha channel on, z-buffer off, etc..)
jpspe
Posts: 10
Joined: Fri Feb 22, 2008 8:30 am

Post by jpspe »

Thanks everyone for your input.

I am definitely using an image including all possible characters. I've already done all the work in regards to grabbing characters for the image and displaying...

So, essentially regardless of whether the image I'm displaying has a character in it or some other interesting picture, I need to accomplish the same thing, i.e.in layman terms transform the main colour of the image.

Jean, I will give this a try. I'm new to graphics so I'll probably get back with a 'how do I...'.

Thanks so far.

Josh
jpspe
Posts: 10
Joined: Fri Feb 22, 2008 8:30 am

Post by jpspe »

Hi Jean,

I managed to get a sample working on its own using sprites.

I currently draw png graphics on screen as GU_TRIANGLE_STRIP. So what I did was draw my image as normal, then after draw the sprite on top. The sprite would appear and the whole screen would suddenly go blank.

Is there some problem in using the two drawing methods together?

Thanks,

Josh
jpspe
Posts: 10
Joined: Fri Feb 22, 2008 8:30 am

Post by jpspe »

I really don't have time to get this working as I have loads of other tasks to do in this app. I'm willing to pay someone to create a few functions that will:
1. accept an image (with black characters on a white background) as an input and convert it to:
- White characters on an orange background
- Orange characters on a white background
- Black characters on a grey background

Now, the image has anti-aliasing, so this must be converted as well. I'm using the graphics.h library for basic image png loading and image drawing. I can provide the framework for you. If anyone can do this for me please contact me.

Thanks,

Josh
Post Reply