Display sprite without background color?

109 views
Skip to first unread message

Drozzy

unread,
Nov 5, 2008, 12:38:09 PM11/5/08
to pyglet-users
How would I display the sprite that has background color brown (let's
say) so that the brown pixels are not shown?

I've looked at the astraea that comes with pyglet example but it uses
sprites with white background...
Is it the glBlendFunc that I need to look into? Or do I have to use
textures?
Right now I just do:
pyglet.image.load('ogre_standing0000.bmp')

Thanks!

Brian Hook

unread,
Nov 5, 2008, 12:43:50 PM11/5/08
to pyglet...@googlegroups.com
You're trying to do what's called "chromakeying", which I don't believe OpenGL supports.  What you want to do is edit the BMP so that all the transparent pixels have their alpha values set to 0 and then save it out in a format that supports alpha (such as TGA).  Alternatively you could load the BMP and do a manual substitution in code by converting to an RGBA format and then setting alpha to 0 where it's brown and 255 where it's not.

Once you have alpha set, you then use the glBlendFunc to blend properly.

Drozzy

unread,
Nov 5, 2008, 12:46:39 PM11/5/08
to pyglet-users
Thanks.. could you go a little slower please.
So if I ever to convert this image in gimp say, I'll have to set mode
to.. indexed?
How would i set the alpha to 0 on brown pixels?
Thanks

Brian Hook

unread,
Nov 5, 2008, 12:52:45 PM11/5/08
to pyglet...@googlegroups.com
I don't know Gimp very well, maybe someone else can help, but maybe something like this helps?


Just search for "Gimp alpha channel" for some tutorials.

Nathan Whitehead

unread,
Nov 5, 2008, 2:02:52 PM11/5/08
to pyglet...@googlegroups.com
On Wed, Nov 5, 2008 at 11:38 AM, Drozzy <dro...@gmail.com> wrote:
> How would I display the sprite that has background color brown (let's
> say) so that the brown pixels are not shown?

To do this in the Gimp, first use the dropper tool to select the color
you want to make transparent. Click the dropper, then click a brown
pixel. Next choose "Colors" - "Color to Alpha..." Then drag the
foreground color you previously selected and drop it in the color
selector. It should show you a preview of the sprite with the color
turned transparent. Click OK to make it happen, then save the image
in a format that supports transparency (png works, I don't know if bmp
does).
--
Nathan Whitehead

Reply all
Reply to author
Forward
0 new messages