[Bf-committers] BGE Python Drawing Patch
Mitchell Stokes
mitchell at daboys4u.com
Mon Oct 19 02:08:47 CEST 2009
Hello Blender Devs!
Over six weeks ago I submitted a patch to the tracker to allow Python
to draw to the screen in the BGE. I'm posting now to the mailing list
to see if I could get some feedback on the patch and hopefully get it
committed sometime. :)
Here is a video demonstrating the patch:
http://www.youtube.com/watch?v=eWdDDEX6xv0
Here is the link to the tracker post:
https://projects.blender.org/tracker/?func=detail&aid=19258&group_id=9&atid=306
And here is the message from the tracker post:
"Here is a patch to be able to draw to the screen with BGE Python.
This will be very handy for GUI stuff. This patch
works by having the user register a callback in the scene. Two options
are available KX_Scene['pre_draw']
and KX_Scene['post_draw']. The difference between these is when Python
draws to the screen (before or after the BGE).
Each can take a list of functions, or just a single function. Here is
an example that draws a blue semi-transparent
square that rotates:
from BGL import *
import GameLogic as gl
def myFunc():
glMatrixMode(GL_PROJECTION)
glLoadIdentity();
glOrtho(-50.0, 50.0, -25.0, 25.0, -1.0, 1.0)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glDisable(GL_LIGHTING)
glPushMatrix()
glColor4f(0.0, 0.0, 1.0, 0.8)
glRotatef(gl.spin, 0.0, 0.0, 1.0)
glRectf(-15.0, -15.0, 15.0, 15.0)
gl.spin += 2.0
if gl.spin > 360:
gl.spin -= 360
glPopMatrix()
if not hasattr(gl, "spin"):
gl.spin = 0.0
gl.getCurrentScene()['post_draw'] = [myFunc]"
Thank you!
Mitchell Stokes (Moguri)
More information about the Bf-committers
mailing list