how can I make transparent images in pyglet?

806 views
Skip to first unread message

amigojapan

unread,
Aug 29, 2009, 12:20:24 PM8/29/09
to pyglet-users
I have tried this
from pyglet.gl import *
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
and then draw an image that is partly transparent in .png
but the transparent part appears red.

also I have tried
import pyglet
pyglet.gl.glClearColor(0, 0, 1, 1)

and then drew an image that is partly transparent in .gif
and the transparent part appears like partly pink...

any ideas as to what I am doing wrong?

do you need to see the whole program I am talking about?

CaffeineDependent

unread,
Aug 30, 2009, 11:27:20 AM8/30/09
to pyglet-users
Are you using a Sprite to draw the image? If you already have a PNG
that has transparent portion, something like this will work:

import pyglet

win = pyglet.window.Window(500, 500)
batch = pyglet.graphics.Batch()

img = pyglet.resource.image('someimagewithalpha.png')

sprite = pyglet.sprite.Sprite(img, x= 200, y = 200, batch = batch)

@win.event
def on_draw():
win.clear()
batch.draw()

pyglet.app.run()
Reply all
Reply to author
Forward
0 new messages