I was going through Pyglet's examples and wanted to repicate the
Stencil Buffer example in an even simpler form, to better understand
it. The problem seems to be that I just can't get it working
properly.
I'm sure there's something missing but I can't seem to find it. I even
went around and compared with a C example but so far no dice.
Here's the code that so far only gives me a deliciously blue window:
#!/usr/bin/env python
import math
import pyglet
import pyglet.clock
from pyglet.gl import *
import pyglet.window
#__________________
x = 0.0
y = 0.0
dim = 100.0
xmax = dim
ymax = dim
speed = 30.0 # units per second
rsize = 25
xsign = 1.0
ysign = 1.0
def draw():
#Clear blue window.
glClearColor(0.0, 0.0, 1.0, 0.0)
#Use 0 for clear stencil.
glClearStencil(0)
glEnable(GL_STENCIL_TEST)
#Clear color and stencil buffer.
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)
#All drawing commands fail the stencil test, and are not
#drawn, but increment the value in the stencil buffer.
glStencilFunc(GL_NEVER, 0x0, 0x0)
glStencilOp(GL_INCR, GL_INCR, GL_INCR)
#Draw pattern.
glColor3f(1.0, 1.0, 1.0)
glBegin(GL_LINE_STRIP)
radius = 0.1
angle = 0.0
while angle < 400.0:
glVertex2d(radius * math.cos(angle), radius * math.sin(angle))
radius *= 1.002
angle += 0.1
glEnd()
#Now, allow drawing, except where the stencil pattern is 0x1
#and do not make any further changes to the stencil buffer
glStencilFunc(GL_NOTEQUAL, 0x1, 0x1)
glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP)
#Now, add square.
glColor3f(1.0, 0.0, 0.0)
glRectf(x, y, x + rsize, y - rsize)
config = Config(double_buffer=True, stencil_size=8)
window = pyglet.window.Window(caption = 'OpenGL Stencil Test',
resizable = True,
config = config)
@window.event
def on_draw():
window.clear()
#window.draw()
draw()
pyglet.app.run()
I must be missing something. Does anyone have any suggestions?
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en.