Try this:
# coding: utf-8
import pyglet
window = pyglet.window.Window()
vertexes = [(208, 41), (208, 266), (514, 266), (514, 41)]
#Enable blending
pyglet.gl.glEnable(GL_BLEND)
pyglet.gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
#Enable transparency
glEnable(GL_ALPHA_TEST)
glAlphaFunc(GL_GREATER, .1)
@window.event
def on_draw():
window.clear()
pyglet.gl.glColor4f(0.5, 1.0, 0.2, 0.5)
pyglet.gl.glBegin(pyglet.gl.GL_QUADS)
pyglet.gl.glVertex3f(vertexes[0][0], vertexes[0][1], 0)
pyglet.gl.glVertex3f(vertexes[1][0], vertexes[1][1], 0)
pyglet.gl.glVertex3f(vertexes[2][0], vertexes[2][1], 0)
pyglet.gl.glVertex3f(vertexes[3][0], vertexes[3][1], 0)
pyglet.gl.glEnd()
pyglet.app.run()
On Thursday, June 29, 2017 at 3:10:11 PM UTC-4, Bastien Sevajol wrote:
>
> Hello,
>
> I'm new user of pyglet or OpenGL components and i have a question about
> opacity/transparency about drawing objects. With this example code, i wrote
> a rectangle:
>
> # coding: utf-8
> import pyglet
>
> window = pyglet.window.Window()
> vertexes = [(208, 41), (208, 266), (514, 266), (514, 41)]
>
>
> @window.event
> def on_draw():
> window.clear()
>
> pyglet.gl.glColor3ub(125, 255, 23)
> pyglet.gl.glBegin(pyglet.gl.GL_QUADS)
>
> pyglet.gl.glVertex3f(vertexes[0][0], vertexes[0][1], 0)
> pyglet.gl.glVertex3f(vertexes[1][0], vertexes[1][1], 0)
> pyglet.gl.glVertex3f(vertexes[2][0], vertexes[2][1], 0)
> pyglet.gl.glVertex3f(vertexes[3][0], vertexes[3][1], 0)
>
> pyglet.gl.glEnd()
>
> pyglet.app.run()
>
> But i don't know how change it's opacity. How to do that ?
>
> Regards,
> Bastien.
>
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.