blf.clipping, aspect, rotation, shadow, blur

hi,
how do you use them? I can’t make it work, is it font dependent ?
thanks for any pointers.

# 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('//yosh.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.clipping(font_id, (width * 0.21), (height * 0.29), (width * 0.4), (height * 0.39)) #Clip the drawing area by these bounds. Clip the full letters
    blf.enable(font_id, blf.CLIPPING)
    blf.draw(font_id, "Hello World")
    blf.disable(font_id, blf.CLIPPING)

    #blf.aspect(font_id, 0.1) # I don't konw how or if this is working
    blf.position(font_id, (width * 0.1), (height * 0.2), 0)
    blf.draw(font_id, "Hello World 2")
 

ok got it thanks HG1.
(cool post reading after a great lunch)

#blf.aspect(font_id, 0.1) # I don't konw how or if this is working

it appears blf.enable is a binary mask :


		# 1 blf.ROTATION
		# 2 blf.CLIPPING
		# 4 blf.SHADOW
		# 8 
		# 16 
		# 32 ASPECT
		blf.rotation(font_id, 30)
		blf.clipping(font_id, 100,100,800,600)
		blf.shadow(font_id , 3 ,1.0 ,0.0 ,0.0 ,1.0 )
		blf.shadow_offset(font_id ,3 ,3)
		blf.aspect(font_id, 0.6)
		blf.blur(font_id, 0) # 1,3 or 5.. ? looks like a glEnable(GLdontrememberwhich) I knew
		b = 39
		blf.enable(font_id, b)
		blf.draw(font_id, area.body)
		blf.disable(font_id, b)
		blf.draw(font_id, area.body)

aspect acts as a zoom, I cant see any ratio change with the font I use.

Yes blf.enable is a binary mask, but my problem was that only the first four constants (ROTATION, CLIPPING, SHADOW or KERNING_DEFAULT) are documented.
http://www.blender.org/documentation/blender_python_api_2_57_release/blf.html
I don’t know that there are more than this your values.

I looked now in the source code to find out how many constants it gives and for what the are for.
#1 blf.ROTATION
#2 blf.CLIPPING
#4 blf.SHADOW
#8 blf.KERNING_DEFAULT
#16 blf.MATRIX
#32 blf.ASPECT

hey guys, I’m having trouble running the codes from above. The console keeps saying ‘module’ object has no attribute ‘font_id’ referring to this line: font_id = logic.font_id

You must call the init not the write function with the python module controller and you must have set the path to and name of your font (yosh.ttf).

Attachments

BLF_text.zip (97.2 KB)

How about multiple texts on separate parts of screen?