user1097772
user1097772

Reputation: 3549

How to show text on the screen using OpenGL and C#

Situation: Simple 3D game project - OpenGL + C# I read that OpenGL functions doesn't support easily print the text on the screen. Have anyone clue how to do it? I don't need any too much sophisticated solution. I just need show for example FPS rate in one corner or show the number of picked up objects in anohter corner. thx.

Upvotes: 3

Views: 3250

Answers (3)

shekhar
shekhar

Reputation: 1422

http://nehe.gamedev.net/tutorial/freetype_fonts_in_opengl/24001/ This should give you all you want. Its in C++ but I am guessing that should not be a problem. It basically elaborates on what neodelphi suggested.

Although you say you don't need to much complexity and require it for just the FPS, having a nice font rendering system comes in extremely handy.

HTH

Upvotes: 0

dthorpe
dthorpe

Reputation: 36082

Use wgl functions of Opengl32.dll on windows to render text. Example here: http://www.pinvoke.net/default.aspx/opengl32.wglusefontoutlines#

The basic process is you have to build a display list of glyphs in advance (rending the Windows font into an OpenGL context), then you can draw characters on the OpenGL display surface using the characters as indices into the pre-rendered display list.

For a prepackaged managed solution, take a look at Mono's Tao library: http://www.mono-project.com/Tao

Upvotes: 0

neodelphi
neodelphi

Reputation: 2786

One good method for text rendering is to use a texture with the font characters and draw one quad for each character with the good texturing coordinates. This usually gives good results and is platform independant. However this is quite heavy to implement.

Upvotes: 1

Related Questions