I am just getting stated with opengl, and I am working with pyside,
numpy, and a new constructive solid geometry library called pyPolyCSG.
My goal is to modify the hellogl.py pyside example found here:
http://qt.gitorious.org/pyside/pyside-examples/blobs/master/examples/opengl/hellogl.py
pyPolyCSG can be found here, if you are interested:
https://github.com/jamesgregson/pyPolyCSG
hellogl.py simply displays the Trolltech logo in a pyside(qt) widget,
rendered using OpenGL. Works great.
I gutted the logo construction code and call pyPolyCSG to construct a
box. pyPolyCSG returns numpy arrays for vertices and triangles. I
modified the paintgl() method to paint the mesh -- but clearly I am
doing something wrong because all I see is a pretty background fill. My
box is MIA.
I am a total n00b with OpenGL, so I suspect I am missing something very
basic.
Relevant code:
The Qt widget paintGL callback:
def paintGL(self):
# copied from example:
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
GL.glLoadIdentity()
GL.glTranslated(0.0, 0.0, -10.0)
GL.glRotated(self.xRot / 16.0, 1.0, 0.0, 0.0)
GL.glRotated(self.yRot / 16.0, 0.0, 1.0, 0.0)
GL.glRotated(self.zRot / 16.0, 0.0, 0.0, 1.0)
# my code added here:
v,t = self.object
v = v/10.0 # Is scaling an issue?
t = t.astype('uint16')
colors = numpy.array([1.,0.,0.] * len(v)) # Need some colors??
Maybe???
GL.glVertexPointer(3, GL.GL_FLOAT, 0, v.astype('float32'))
GL.glColorPointer(3, GL.GL_FLOAT,0, colors.astype('float32'))
GL.glDrawElements(GL.GL_TRIANGLES, len(t) ,GL.GL_UNSIGNED_SHORT, t)
My geometry construction:
def makeObject(self):
self.polyBlock = csg.box(2,4,6) # Call pyPolyCSG to construct a box
v = self.polyBlock.get_vertices()
t = self.polyBlock.get_triangles()
print 'v = '
print v
print 't ='
print t
return (v,t)
The mesh in numpy arrays:
v =
[[ 0. 0. 0.]
[ 2. 0. 0.]
[ 2. 4. 0.]
[ 0. 4. 0.]
[ 0. 0. 6.]
[ 2. 0. 6.]
[ 2. 4. 6.]
[ 0. 4. 6.]]
t =
[[4 0 1]
[4 1 5]
[6 2 3]
[6 3 7]
[0 3 2]
[0 2 1]
[7 4 5]
[7 5 6]
[5 1 2]
[5 2 6]
[7 3 0]
[7 0 4]]
I'm a total n00b with OpenGL, so don't make too many assumptions about
what I know :)
Thanks,
Dave
|