diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2011-07-06 12:29:20 +0400 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2011-07-06 12:29:20 +0400 |
commit | 4260258bb301c91e4b37ec98297fa69f34ae044f (patch) | |
tree | e63174da5603a5f32d47476753cf9488e564f8c2 | |
parent | 2691c6a84f213c69d956816bec4a8ec225c394d8 (diff) |
an example for blf - a basic Hello World (for bge, not blender)
-rw-r--r-- | doc/python_api/examples/blf.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/doc/python_api/examples/blf.py b/doc/python_api/examples/blf.py new file mode 100644 index 00000000000..c91b41bec36 --- /dev/null +++ b/doc/python_api/examples/blf.py @@ -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") |