color switching

Started by
2 comments, last by cyberia_2ooo 20 years, 11 months ago
meaning, is there a way to take a Direct Draw 7 surface, and switch every pixel that is in color a, and switch it color b?
Advertisement
If you mean changing a specific colour in a sprite at drawing time, what you could do is:

1) render a rectangle the same size as the sprite which is all colour B at the location you want to render the sprite.

2) set the colour key for the sprite surface to colour A

3) draw the sprite on top of the rectangle which was drawn in 1)


You could also do that into a temporary surface if you''ll be doing it a lot.



--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

using a sprite that is all colur A is to much of a memory hugger.

and i already have another keyed color which is not color A.

thanx any way...

i did it the hard way.
since i don''t need to that on drawing time.
i locked the surface, and checked each pixel if it is of color A, and if so, changed it to color B, slow, but reliable
You don''t need to use a sprite which is all of colour A though...
just use a Blt() to fill in one colour - it requires no storage.
If you use a temporary surface then you can change the key back afterwards e.g.:

1) you have *one* temporary surface in the application, created when it starts up. Call this lpDDSTemp.

2) use a Blt() colourfill to change all of lpDDSTemp to colour B

3) say the surface your sprite is on is called lpDDSSprite, set the colour key for lpDDSSprite to colour A

4) Blt() from lpDDSSprite to lpDDSTemp with colour keying enabled. This replaces colour A with colour B in lpDDSTemp

5) Blt() from lpDDSTemp to lpDDSSprite with colour keying disabled, this copies the sprites back.

6) set the colour key for lpDDSSprite to the proper/original colour key

7) lpDDSTemp is now unused and can be used for any other purpose - having a temp buffer around is always handy...


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

This topic is closed to new replies.

Advertisement