blf,bgl font question (am I understanding this right?)

Hey! I’ve been fiddling with the font drawing stuff and I had a small moment when I had to think how I wish to put various properties with different text elements on my screen, code is below (bolded part is which I want a clarification to). Since it read the whole function anyway line by line is it “alright” to recolor the next line texts as I have now put them (it seems to work)?

Edit: nevermind the bold didn’t work on

 so I just marked the lines :P
 

def fontInit():
	font_path = logic.expandPath('//assets/fonts/arialbd.ttf')
	logic.font_id = blf.load(font_path)
	scene = logic.getCurrentScene()
	scene.post_draw = [writeStats]
	
def writeStats():
	width = render.getWindowWidth()
	height = render.getWindowHeight()

	bgl.glMatrixMode(bgl.GL_PROJECTION)
	bgl.glLoadIdentity()
	bgl.gluOrtho2D(0, width, 0, height)
	bgl.glMatrixMode(bgl.GL_MODELVIEW)
	bgl.glLoadIdentity()

-this -> bgl.glColor4f(1.0, 0.0, 0.0, 1)

	font_id = logic.font_id		
	blf.size(font_id, 40, 72)
	
	blf.position(font_id, (width * 0.05), (height * 0.45), 0)
	writeScore = str(own["score"])
	blf.draw(font_id, writeScore)
	
	blf.position(font_id, (width * 0.05), (height * 0.24), 0)
	writeMultiplier = str(own["multiplier"])
	blf.draw(font_id, writeMultiplier)

-this -> bgl.glColor4f(0.0, 0.0, 1.0, 1)
blf.size(font_id, 40, 72)

	blf.position(font_id, (width * 0.05), (height * 0.90), 0)
	titleScore = str(own["scoreTitle"])
	blf.draw(font_id, titleScore)
	
	blf.position(font_id, (width * 0.05), (height * 0.54), 0)
	titleMultiplier = str(own["multiTitle"])
	blf.draw(font_id, titleMultiplier)

bgl.glColor4f(1.0, 0.0, 0.0, 1)
i think it stands for bgl.glColor4f(Red, Green, Blue, Alpha), RGBA and 4f means a vector of floating point arguments.
According to http://www.opengl.org/sdk/docs/man/xhtml/glColor.xml
void glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);

Basically it sets the color to be used to draw in opengl( here the font text)
So if you want to the text to be red:
bgl.glColor4f(0.0, 0.0, 1.0, 1)

Also opengl will keep using the same colour to draw untill you change it with the same function.
Edit:

Therefore it’s okay to recolour the second line of text by choosing a different value for RGBA.

Uhm. Maybe I formed my question in wrong way. What I meant to ask is that is it alright to use that method to make the first two texts to appear in red and latter ones in other colors (just by giving a new color value for next texts) :slight_smile:

Yes. it’s okay and would work just fine.:slight_smile:

Thank you!