2011-07-06 08:29:20 +00:00
|
|
|
"""
|
|
|
|
Hello World Text Example
|
|
|
|
++++++++++++++++++++++++
|
2011-07-29 01:24:03 +00:00
|
|
|
|
2011-07-06 08:29:20 +00:00
|
|
|
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
|
|
|
|
from bge import render
|
|
|
|
from bge import logic
|
|
|
|
# import stand alone modules
|
|
|
|
import bgl
|
|
|
|
import blf
|
|
|
|
|
2011-07-29 01:24:03 +00:00
|
|
|
|
2011-07-06 08:29:20 +00:00
|
|
|
def init():
|
|
|
|
"""init function - runs once"""
|
|
|
|
# create a new font object, use external ttf file
|
|
|
|
font_path = logic.expandPath('//Zeyada.ttf')
|
2011-07-29 01:24:03 +00:00
|
|
|
# store the font indice - to use later
|
2011-07-06 08:29:20 +00:00
|
|
|
logic.font_id = blf.load(font_path)
|
|
|
|
|
2011-07-29 01:24:03 +00:00
|
|
|
# set the font drawing routine to run every frame
|
2011-07-06 08:29:20 +00:00
|
|
|
scene = logic.getCurrentScene()
|
2011-07-29 01:24:03 +00:00
|
|
|
scene.post_draw = [write]
|
|
|
|
|
2011-07-06 08:29:20 +00:00
|
|
|
|
|
|
|
def write():
|
|
|
|
"""write on screen"""
|
|
|
|
width = render.getWindowWidth()
|
|
|
|
height = render.getWindowHeight()
|
2011-07-29 01:24:03 +00:00
|
|
|
|
2011-07-06 08:29:20 +00:00
|
|
|
# OpenGL setup
|
|
|
|
bgl.glMatrixMode(bgl.GL_PROJECTION)
|
|
|
|
bgl.glLoadIdentity()
|
|
|
|
bgl.gluOrtho2D(0, width, 0, height)
|
|
|
|
bgl.glMatrixMode(bgl.GL_MODELVIEW)
|
|
|
|
bgl.glLoadIdentity()
|
2011-07-29 01:24:03 +00:00
|
|
|
|
2011-07-06 08:29:20 +00:00
|
|
|
# BLF drawing routine
|
|
|
|
font_id = logic.font_id
|
2011-07-29 01:24:03 +00:00
|
|
|
blf.position(font_id, (width * 0.2), (height * 0.3), 0)
|
2011-07-06 08:29:20 +00:00
|
|
|
blf.size(font_id, 50, 72)
|
|
|
|
blf.draw(font_id, "Hello World")
|