I´m trying to draw a text using the bge module. This is my code:

# import game engine modules
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.gluOrtho2D(0, width, 0, height)

    # 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")

I add an object, a sensor and a controller as you can see in the next picture: enter image description here

But, when I pulse "p" on the 3D viewer screen and it´s suppose my game runs I only see this: enter image description here

I´ve tried to change the text´s size and the frequency of the sensor. Any idea about something that may be failing?


1 Answer 1


I´ve just realized that I don´t have the file called "Zeyada.ttf" so my problem is in the line:

 font_path = logic.expandPath('//Zeyada.ttf')

Apparently I need a ttf file to present the text and it makes sense, every text has format.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .