bug?

red puck <[email protected]>
Newsgroups gmane.comp.python.opengl.user,gmane.comp.python.opengl.devel
Message-ID <[email protected]>
Hello, Everyone,

I found a interesting question here.

I use the first sample program from chapter 24 from
Python How to Program By Harvey M. Deitel, Paul J.
Deitel, Jonathan P. Liperi, BA Wiedermann; Prentice
Hall, 2002.

This program can get correct figure. But I found a
interesting thing here. or maybe it is a bug?

The run of the program like following

"/usr/lib/python2.4/lib-tk/Tkinter.py", line 1345, in
__call__
return self.func(*args)
File
"/usr/lib/python2.4/site-packages/OpenGL-3.0.0a4-py2.4.egg/OpenGL/Tk/__init__.py",<br
/> line 548, in tkExpose
self.basic_lighting()
File
"/usr/lib/python2.4/site-packages/OpenGL-3.0.0a4-py2.4.egg/OpenGL/Tk/__init__.py",<br
/> line 323, in basic_lighting
glLightfv(GL_LIGHT0, GL_POSITION, light_position)
File
"/usr/lib/python2.4/site-packages/OpenGL-3.0.0a4-py2.4.egg/OpenGL/wrapper.py",
line 664, in wrapperCall
pyArgs.append( converter(arg, self, args) )
File
"/usr/lib/python2.4/site-packages/OpenGL-3.0.0a4-py2.4.egg/OpenGL/converters.py",<br
/> line 113, in __call__
return self.function( incoming )
File
"/usr/lib/python2.4/site-packages/OpenGL-3.0.0a4-py2.4.egg/OpenGL/arrays/arraydatatype.py",<br
/> line 52, in asArray
return cls.getHandler(value).asArray( value, typeCode
or cls.typeConstant )
File
"/usr/lib/python2.4/site-packages/OpenGL-3.0.0a4-py2.4.egg/OpenGL/arrays/arraydatatype.py

Ok, The interesting thing happen here in try block in
this file in line 18 

Handler = cls.TYPE_REGISTRY.get(typ)

In my machine, the first time, Handler equal nothing
and jump out the try block and return, and then
execute this function again, get correct Handler value
and show right figure.

The key problem is here. The source code works well,
but once I compiled it with Cx_freeze. The executable
doesn't work.

Anybody can clear this for me?

for your convenience, I attach the source code here.


#########################################

# Fig 24.1: fig24_01.py
# Colored, rotating box (with open top and bottom).

from Tkinter import *
from OpenGL.GL import *
from OpenGL.Tk import *

class ColorBox( Frame ):
"""A colorful, rotating box"""

def __init__( self ):
"""Initialize GUI and OpenGL"""

Frame.__init__( self )
self.master.title( "Color Box" )
self.master.geometry( "300x300" )
self.pack( expand = YES, fill = BOTH )

# create and pack Opengl -- use double buffering
self.openGL = Opengl( self, double = 1 )
self.openGL.pack( expand = YES, fill = BOTH )

self.openGL.redraw = self.redraw # set redraw function
self.openGL.set_eyepoint( 30 ) # move away from object

self.amountRotated = 0 # total degrees of rotation
self.increment = 2 # rotate amount in degrees
self.update() # begin rotation

def redraw( self, openGL ):
"""Draw box on black background"""

# clear background and disable lighting
glClearColor( 1.0, 1.0, 1.0, 0.0 ) # set clearing
color
glClear( GL_COLOR_BUFFER_BIT ) # clear background
glDisable( GL_LIGHTING )

# constants
red = ( 1.0, 0.0, 0.0 )
green = ( 0.0, 1.0, 0.0 )
blue = ( 0.0, 0.0, 1.0 )
purple = ( 1.0, 0.0, 1.0 )

vertices = \
[ ( ( -3.0, 3.0, -3.0 ), red ),
( ( -3.0, -3.0, -3.0 ), green ),
( ( 3.0, 3.0, -3.0 ), blue ),
( ( 3.0, -3.0, -3.0 ), purple ),
( ( 3.0, 3.0, 3.0 ), red ),
( ( 3.0, -3.0, 3.0 ), green ),
( ( -3.0, 3.0, 3.0 ), blue ),
( ( -3.0, -3.0, 3.0 ), purple ),
( ( -3.0, 3.0, -3.0 ), red ),
( ( -3.0, -3.0, -3.0 ), green ) ]

glBegin( GL_QUAD_STRIP ) # begin drawing

# change color and plot point for each vertex
for vertex in vertices:
location, color = vertex
apply( glColor3f, color )
apply( glVertex3f, location )

glEnd() # stop drawing

def update( self ):
"""Rotate box"""

if self.amountRotated >= 500: # change rotation
direction
self.increment = -2 # rotate left
elif self.amountRotated <= 0: # change rotation
direction
self.increment = 2 # rotate right

# rotate box around x, y, z axis ( 1.0, 1.0, 1.0 )
glRotate( self.increment, 1.0, 1.0, 1.0 )
self.amountRotated += self.increment

self.openGL.tkRedraw() # redraw geometry
self.openGL.after( 10, self.update ) # call update in
10ms

def main():
ColorBox().mainloop()

if __name__ == "__main__":
main()

#################################

I add two print line in
"/usr/lib/python2.4/site-packages/OpenGL-3.0.0a4-py2.4.egg/OpenGL/arrays/arraydatatype.py"

and get following 

0
return
0
<Opengl.arrays.numpymodule.NumpyHandler Object at
0x8ae0fcc>
return

#########################


handler = 0;
		try:
			print handler
			handler = cls.TYPE_REGISTRY.get( typ )
			print handler
		except AttributeError, err:
			formathandler.FormatHandler.loadAll()
			cls.TYPE_REGISTRY =
formathandler.FormatHandler.TYPE_REGISTRY
			handler = cls.TYPE_REGISTRY.get( typ )
		if handler is None:
			if hasattr( typ, '__mro__' ):
				for base in typ.__mro__:
					if cls.TYPE_REGISTRY.has_key( base ):
						handler = cls.TYPE_REGISTRY[ base ]
						handler.registerEquivalent( typ, base )
						cls.TYPE_REGISTRY[ typ ] = handler 
						return handler
			raise TypeError(
				"""No array-type handler for type %r (value: %s)
registered"""%(
					typ, repr(value)[:50]
				)
			)
		print "return"
		return handler
##########################

Thanks,

John

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
PyOpenGL Homepage
http://pyopengl.sourceforge.net
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.