I am trying to find a way to display a simple text on an openGL form in Delphi.
I tried this with Labels, but they were not showing up. I'm guessing that the openGL window was rendered on top of it, so I tried to call Label1.BringToFront; but this didn't work.
I also heard of a library called freetype, but I couldn't find info, how to implement it in Delphi.
What is the simplest way to render out text on an openGL form in Delphi?
2
votes
Draw a quad on screen with a texture of a letter mapped to it. You can create one texture with your entire font and modify the quad's UVs to draw the right letter. Repeat the sequence for words.
- Kevin
1 Answers
0
votes
The simplest way is to use opengl's wglfontbitmaps
const numberchar =128
allocate:
wglMakeCurrent(FDC, FRC);
FFontBase := glGenLists(numberchar);
SelectObject(FDC, FFont.Handle);
wglUseFontBitmaps(FDC,0,128, FFontBase);
draw(atext:ansistring);
glPushAttrib(GL_LIST_BIT);
glListBase(FFontbase);
glCallLists(Length(aText), GL_UNSIGNED_BYTE, Pansichar(aText)); list
glPopAttrib;
free:
glDeleteLists(FFontBase, numberchar);
The draw code is only partial. Best to look for tutorials for similar code.
Note this will only give you basic unscaled font. For fancy text effects, indeed, freetype is the most common route.
A good place to start with Delphi and opengl is http://www.delphigl.com/ Mostly German, but some English boards too.
An alternative (provided that you have D2010+) is to look in the direction of DirectX. D2010+ comes with a directx context component.