[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38138] trunk/blender/doc/python_api/ examples/blf.py: an example for blf - a basic Hello World (for bge, not blender)

Dalai Felinto dfelinto at gmail.com
Wed Jul 6 10:29:20 CEST 2011


Revision: 38138
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38138
Author:   dfelinto
Date:     2011-07-06 08:29:20 +0000 (Wed, 06 Jul 2011)
Log Message:
-----------
an example for blf - a basic Hello World (for bge, not blender)

Added Paths:
-----------
    trunk/blender/doc/python_api/examples/blf.py

Added: trunk/blender/doc/python_api/examples/blf.py
===================================================================
--- trunk/blender/doc/python_api/examples/blf.py	                        (rev 0)
+++ trunk/blender/doc/python_api/examples/blf.py	2011-07-06 08:29:20 UTC (rev 38138)
@@ -0,0 +1,42 @@
+"""
+Hello World Text Example
+++++++++++++++++++++++++
+Blender Game Engine example of using the blf module. For this module to work we
+need to use the OpenGL wrapper :class:`~bgl` as well.
+"""
+# import game engine modules
+import bge
+from bge import render
+from bge import logic
+# import stand alone modules
+import bgl
+import blf
+
+def init():
+    """init function - runs once"""
+    # create a new font object, use external ttf file
+    font_path = logic.expandPath('//Zeyada.ttf')
+	# store the font indice - to use later
+    logic.font_id = blf.load(font_path)
+
+    # set the font drawing routine to run every frame   
+    scene = logic.getCurrentScene()
+    scene.post_draw=[write]
+
+def write():
+    """write on screen"""
+    width = render.getWindowWidth()
+    height = render.getWindowHeight()
+    
+    # OpenGL setup
+    bgl.glMatrixMode(bgl.GL_PROJECTION)
+    bgl.glLoadIdentity()
+    bgl.gluOrtho2D(0, width, 0, height)
+    bgl.glMatrixMode(bgl.GL_MODELVIEW)
+    bgl.glLoadIdentity()
+    
+    # BLF drawing routine
+    font_id = logic.font_id
+    blf.position(font_id, (width*0.2), (height*0.3), 0)
+    blf.size(font_id, 50, 72)
+    blf.draw(font_id, "Hello World")


Property changes on: trunk/blender/doc/python_api/examples/blf.py
___________________________________________________________________
Added: svn:keywords
   + Author Date Id Revision
Added: svn:eol-style
   + native




More information about the Bf-blender-cvs mailing list