Example pyglet code that uses gluSphere and gluCylinder

1,579 views
Skip to first unread message

rpmu...@gmail.com

unread,
Mar 1, 2008, 5:30:51 PM3/1/08
to pyglet-users
Just started using pyglet and love it! Does anyone have any example
code that shows how gluSphere and/or gluCylinder are called? I'm
getting a crash every time I try to use them.

Rick

Richard Jones

unread,
Mar 1, 2008, 6:32:02 PM3/1/08
to pyglet...@googlegroups.com

Please post your code.


Richard

rpmu...@gmail.com

unread,
Mar 1, 2008, 6:48:30 PM3/1/08
to pyglet-users
> Please post your code.
>
> Richard

Sure thing. The short of it is that I'm doing something like

sphere = gluNewQuadric()
gluSphere(sphere,10.0,10,10)

and the code crashes when I do the second step.

But here's the code. It's a slight mod of one of the nehe demos.

from pyglet import window
from pyglet.gl import *
from pyglet.gl.glu import *
import pyglet.clock

def resize(width, height):
if height==0:
height=1
glViewport(0, 0, width, height)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45, 1.0*width/height, 0.1, 100.0)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()

def init():
glShadeModel(GL_SMOOTH)
glClearColor(0.0, 0.0, 0.0, 0.0)
glClearDepth(1.0)
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LEQUAL)
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)

def draw():
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
glLoadIdentity()

glBegin(GL_TRIANGLES)
sphere = gluNewQuadric()
gluSphere(sphere,10.0,10,10)

def main():
win = window.Window(width=640,height=480,visible=False)
win.on_resize=resize

init()

win.set_visible()
clock=pyglet.clock.Clock()

while not win.has_exit:
win.dispatch_events()

draw()

win.flip()
clock.tick()

print "fps: %d" % clock.get_fps()

if __name__ == '__main__': main()




Drew Smathers

unread,
Mar 1, 2008, 10:38:16 PM3/1/08
to pyglet...@googlegroups.com

Why are you calling glBegin(GL_TRIANGLES)? In addition to posting
code, you should also post a stacktrace to explain your crash.
Anyhow, just glancing at the code, I imagine the explosion is due to
calling glBegin(...) without a corresponding glEnd() .. or calling
gluSpehere in the context of glBegin(GL_TRIANGLES).

Regards,
--
\\\\\/\"/\\\\\\\\\\\
\\\\/ // //\/\\\\\\\
\\\/ \\// /\ \/\\\\
\\/ /\/ / /\/ /\ \\\
\/ / /\/ /\ /\\\ \\
/ /\\\ /\\\ \\\\\/\
\/\\\\\/\\\\\/\\\\\\
d.p.s

rpmu...@gmail.com

unread,
Mar 1, 2008, 10:48:08 PM3/1/08
to pyglet-users
My bad, I was pasting code a little too quickly, as I have been re-
editing the file back and forth between demos that work and other
things that do not.

So just delete the glBegin(GL_TRIANGLES). I still can't get any
spheres. Even when I just paste the two lines into a working program.

On Mar 1, 8:38 pm, "Drew Smathers" <drew.smath...@gmail.com> wrote:

Txema Vicente

unread,
Mar 2, 2008, 12:23:08 AM3/2/08
to pyglet...@googlegroups.com
If you remove the offending glBegin, it works, but I dont know where is your
projection looking at.

See
http://groups.google.com/group/pyglet-users/web/pyglet-projection-matrix?hl=en
You can test those 2 lines in projections.py, and they work perfectly.

def playground():
# Test your code here
sphere = gluNewQuadric()
gluSphere(sphere,10.0,10,10)


>> Why are you calling glBegin(GL_TRIANGLES)? In addition to posting
>> code, you should also post a stacktrace to explain your crash.

This what I get with that lost glBegin.
File ".\xx.py", line 30, in draw
gluSphere(sphere,10.0,10,10)
WindowsError: exception: access violation reading 0x00000000
Presione una tecla para continuar . . .

Txema Vicente

unread,
Mar 2, 2008, 12:28:08 AM3/2/08
to pyglet...@googlegroups.com
> If you remove the offending glBegin, it works, but I dont know where is
> your
> projection looking at.

Funny, your camera is INSIDE the sphere ;)

rpmu...@gmail.com

unread,
Mar 2, 2008, 9:04:22 AM3/2/08
to pyglet-users
Ooops! Thanks.

rpmu...@gmail.com

unread,
Mar 2, 2008, 9:06:46 AM3/2/08
to pyglet-users
Thanks very much. This works great!

Rick

On Mar 1, 10:23 pm, "Txema Vicente" <tx...@nabla.net> wrote:
> If you remove the offending glBegin, it works, but I dont know where is your
> projection looking at.
>
> Seehttp://groups.google.com/group/pyglet-users/web/pyglet-projection-mat...
Reply all
Reply to author
Forward
0 new messages