AbitDeveloper's picture

Bitmap-based text with position and size

Hello. Can anyone show me a code which draw text on position with defined width and height? I googled some days in my free time. I found only one code and I edited it for defined size but is was unusable. It was fizzy, on wrong position and it broke my code.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Take a look at this example code: https://github.com/thefiddler/opentk/blob/master/Source/Examples/OpenGL/...

Keep in mind that bitmap or texture fonts are not resizable (if you resize them they will get blurry). If you need resizable text you will need a more complicated approach.

AbitDeveloper's picture

Is here way to draw string ( for example "Hello" ) on x = 0, y = 0 with width = 10 and height = 2.
I need to resize letters in the text and render it.

Seven's picture


Hello, Im writing a graphics engine called SevenEngine which you can find at SevenEngine.com.

I just finished some text rendering for my engine. How Im doing it is loading an alpha channeled bitmap sprite sheet, hardware instancing all sprites to have set positions about the origin(0,0,0), and i use the model view matrix to adjust font size and position. (texture coordinates vary for each char)

You might look into the free program "BMFont" by angelcode, it is a nifty program for generating text sheets.

I have not yet pushed the code to my poject, but i will do so in a week o two in you are interested.

puklaus's picture
I have not yet pushed the code to my poject, but i will do so in a week o two in you are interested.

The sooner, the better.

Seven's picture


When I said I had just finished a version, I meant I had one fully coded, but hadn't tested it. I just got a SEMI-working version. How I'm doing it is very efficient but hard to get it just right (still tweaking values). After loading and selecting a font, it is as simple as "Renderer.DrawText("what to write", XYposition, XYscale, Zrotation, color)". I am pushing the code to my GitHub project now if you wanted to give it a look (SevenEngine.com).

I have seen several good examples of text, but they don't hardware instance sprite values, so they must buffer character positions to the GPU every frame (which is what I'm trying to avoid) . LITERALLY ALL I BUFFER TO THE GPU PER FRAME IS A MODEL VIEW MATRIX, 6 FLOATS PER CHARACTER (two "GL.Translate()" calls per character), AND A COLOR (per call to the function above).

I have not had time to examine the library you suggested, but I really doubt their code is as efficient as mine. I will still give them a look when I can.

EDIT 11-15-13: I have it pretty much fully functional except for the color. Give it a look its working quite well.