How to write "Hello World" in OF? (NEWBIE)

Hi, I’m a newbie OF user.

I would like to draw text Label on screen but I have no idea how to.

Maybe ‘ofxLabel addon’ could do this job?

I tried to search example codes but I couldn’t.

Can somebody teach me how to write “Hello World” text on screen?

You can write

ofDrawBitmapString("Hello World!", 100, 100);

in your draw() function

As Mat said above, ofDrawBitmapString would do the job in the simplest way.

I f you want to get fancier, check out the example under examples > graphics > fonts example. That example shows a lot of the things you can do when writing text to the screen: setting fonts, sizes, scaling etc.

Thank you so much guys!!

How do I find out the Width of String drawn by ofTrueTypeFont?

I want to be able to locate my text, based on the center position(X,Y) of my text.

I solved it by stringWidth, and stringHeight.

Thank you

@cuinjune you can also use getStringBoundingBox(...) to get both the width and height in one go (stringWidth(...) and stringHeight(...) both call getStringBoundingBox(...) under the hood).

You might already know this, but it caused a bit of confusion for me when I started using text in openFrameworks. The origin of your text is leftmost point on the baseline of your text. Here’s a graphic from freetype, the library openFrameworks uses to load fonts:

So when you draw a string at (x,y), you are starting the baseline at (x,y).