[PyOpenGL-Users] GLU with multiple tesselators
Brought to you by:
mcfletch
|
From: Maciej K. <ma...@dg...> - 2003-02-06 03:51:19
|
[This has also been posted to comp.graphics.api.opengl, as I don't know whether
this is an OpenGL issue, or pyopengl.]
Hello all. I'm trying to do some 2D CSG stuff using OpenGL's tesselator and
the winding rules. I've run into a problem with using multiple tesselators.
According to the redbook, I should be able to feed one tesselator's output
(using its callbacks) to the input of another one [midway on p421 of 2nd
ed... look for "GLU_TESS_BOUNDARY_ONLY"]. I tried to set up something along
those lines. Here's roughly what occurs at runtime:
(NOTE: "outer" refers to actions taken on the "receiving" tesselator, while
"inner" refers to the "feeding" one)
% ./test.py
outer: gluTessBeginPolygon <GLUtesselator object at 0x816c150>
inner: gluTessBeginPolygon <GLUtesselator object at 0x8121898>
inner: gluTessBeginContour <GLUtesselator object at 0x8121898>
inner: gluTessEndContour <GLUtesselator object at 0x8121898>
inner: gluTessEndPolygon <GLUtesselator object at 0x8121898>
inner: cb_begin <GLUtesselator object at 0x816c150> 2
outer: gluTessEndPolygon <GLUtesselator object at 0x816c150>
Traceback (most recent call last):
File "./test.py", line 75, in ?
main()
File "./test.py", line 70, in main
gluTessEndPolygon(tobj)
OpenGL.GLU.GLUerror: [Errno 100154] gluTessEndContour() must follow a gluTessBeginContour()
Strangely, gluTessEndPolygon() of the "feeding/inner" tesselator only fires the
GLU_TESS_BEGIN callback, and that's it! Bizarre.
Here's the Python code for the above. All it's trying to do is tesselate a
circle using one tesselator, which then feeds the boundary (i.e., the same
circle, it should be) to a second tesselator.
Any ideas? Did I miss something? I tried pyopengl 2.0.0.44, as well as
2.0.1.02.
# --8<--
#!/usr/bin/env python
import math
from math import *
from OpenGL.GL import *
from OpenGL.GLU import *
def inner(tobj):
tobj_inner = gluNewTess()
def cb_begin(type):
print 'inner: cb_begin', tobj, type
gluTessBeginContour(tobj)
print '(done) inner: cb_begin', tobj
def cb_end():
print 'inner: cb_end', tobj
gluTessEndContour(tobj)
def cb_vertex(v):
print 'inner: cb_vertex', tobj, v
gluTessVertex(tobj, v, v)
gluTessCallback(tobj_inner, GLU_TESS_BEGIN, cb_begin)
gluTessCallback(tobj_inner, GLU_TESS_END, cb_end)
gluTessCallback(tobj_inner, GLU_TESS_VERTEX, cb_vertex)
gluTessProperty(tobj_inner, GLU_TESS_WINDING_RULE,
GLU_TESS_WINDING_POSITIVE)
gluTessProperty(tobj_inner, GLU_TESS_BOUNDARY_ONLY, GL_TRUE)
print 'inner: gluTessBeginPolygon', tobj_inner
gluTessBeginPolygon(tobj_inner, None)
SLICES=32
print 'inner: gluTessBeginContour', tobj_inner
gluTessBeginContour(tobj_inner)
for i in range(SLICES):
ang = i/float(SLICES-1) * 2 * math.pi
v = [cos(ang), sin(ang), 0]
gluTessVertex(tobj_inner, v, v)
print 'inner: gluTessEndContour', tobj_inner
gluTessEndContour(tobj_inner)
print 'inner: gluTessEndPolygon', tobj_inner
gluTessEndPolygon(tobj_inner)
gluDeleteTess(tobj_inner)
def main():
tobj = gluNewTess()
def cb_begin(type):
print 'outer: cb_begin', tobj, type
glBegin(type)
def cb_end():
print 'outer: cb_end', tobj
glEnd()
def cb_vertex(v):
print 'outer: cb_vertex', tobj
glVertex3dv(v)
gluTessCallback(tobj, GLU_TESS_BEGIN, cb_begin)
gluTessCallback(tobj, GLU_TESS_END, cb_end)
gluTessCallback(tobj, GLU_TESS_VERTEX, cb_vertex)
print 'outer: gluTessBeginPolygon', tobj
gluTessBeginPolygon(tobj, None)
inner(tobj)
print 'outer: gluTessEndPolygon', tobj
gluTessEndPolygon(tobj)
gluDeleteTess(tobj)
main()
# --8<--
--
"Television: a medium. So called because it is neither rare nor well done."
-- Ernie Kovacs.
|