OpenGL Truetype font output

I'm trying to output text with OpenGL, but can't seem to get anything out. I'm trying to print a simple 'A' letter with following code:

var agmf: GLYPHMETRICSFLOAT;

wglUseFontOutlines(dc, Ord('A'),  1,  1000,  0.0,  0.1, WGL_FONT_POLYGONS, @agmf);

glLoadIdentity;
glTranslated(0.5, 0.0, -2.0);
glCallList(1000) ;


Drawing a sphere etc. works fine, so there should be nothing wrong with the OpenGL initialization. Any code which actually manages to draw 3D text would be greatly appreciated!
KeijoAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
i have an example of some 3d text (the text object has been created into a class T3dText)part of the example looks like:


var
  texto:T3dText;
begin
  Scene:=TsceneGL.create;
  {creation of the tunnel as an scene´s object}
  tunnel:=Tentity.create;
  tunnel.SetColor(139,139,139);
  tunnel.LoadDXF('..\tunnel.dxf', true);
  tunnel.CalcNormals;
  tunnel.Center;
  with tunnel do
  begin
    Move(0,0,-20);  {center tunnel in scene}
    id:=1;         {now the tunnel is identIfied with "name" 1 }
  end;
  Scene.Entities.add(tunnel);

  {create the light}
  light:=Tlight.create(1);
  light.LightType:=CLstar;
  light.CutOffAngle:=5;
  Light.SpotExponent:=100;
  {orientation is given in degrees}
  Light.SetOrientation(0,0,-1);  {looking towards bottom of screen}
  Light.Source.SetPosition(0,0,0);
  {set the light type using the ComboBox control}
  CBlightType.itemIndex:=1;  {select Positional light on the interface}
  Scene.Lights.add(light);

  Scene.InitRC(panel1.handle);
  Scene.UpdateArea(panel1.width,panel1.height);

    {this creates the 3D text object, but note that we had to issue Scene.InitRC
   before creating the text object}
  Texto:=T3Dtext.create(Scene.DC, 1000);
  Texto.setColor(255,150,50);
  Texto.Move(-1,0,-5);
  texto.rotate(0,0,0);
  texto.SetText('Barry');
  texto.id:=2;
  Scene.Entities.Add(texto);

    {Now create the 3dMouse object}
  mouse:=T3dMouse.create(texto);     {link mouse with texto object}
  mouse.scale(0.1,-0.1,0.1,1,1,1);    {set movement and rotation speeds}
  ColorActual:=0;  {pure black}
end;

this came as part of several examples of opengl i downloaded as Text3D.zip
from :
http://www.geocities.com/SiliconValley/Way/2132/tutorial.html
0
intheCommented:
T3dText id defined in u3dpolys.pas in same zip file.
more more opengl related stuff see :
http://www.delphi-jedi.org/DelphiGraphics/jedi-index.htm
and
http://www.lischke-online.de/GLScene.html
0
LischkeCommented:
Keijo, your calling sequence is wrong as well as the display list handling. Look at this:

// don't waste time with the glyph metrics
Base = glGenLists(256); // one for each letter in the alphabet
wglUseFontOutlines(dc, 0,  256,  Base,  0.0,  0.1, WGL_FONT_POLYGONS, NULL);

glLoadIdentity;
glTranslated(0.5, 0.0, -2.0);
    glListBase(Base);
    glCallLists(1, GL_UNSIGNED_BYTE, 'A');


Ciao, Mike
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

KeijoAuthor Commented:
Still having problems, the glCallLists seems to do nothing. Should i repaint or refresh the OpenGL output or something? I think I'm making some stupid mistake here that I don't notice... The code looks like this now:

 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
 glLoadIdentity;

 Base:=glGenLists(256);
 wglUseFontOutlines(GetDC(Panel1.Handle), 0,  256,  Base,  0.0,  0.1, WGL_FONT_POLYGONS, nil);

 glLoadIdentity;
 glTranslated(0.5, 0.0, -2.0);
 glListBase(Base);
 glCallLists(4, GL_UNSIGNED_BYTE, PChar('Test'));

 SwapBuffers(wglGetCurrentDC);

Again, if I try to draw a gluSphere or some other polygon instead of the glCallLists, it works fine. Maybe there's something wrong with the DC? Does it matter which DC I use as long as there is a font assigned to it?
0
LischkeCommented:
Keijo,

this looks almost perfect apart from the fact that you shouldn't create 256 display list each time enter a paint cycle :-) Take out the glGenLists and wglUseFontOutlines calls and put them into an initialization procedure. Check whether Base has a valid number (>0) and don't forget to delete the list on program exit (or RC destruction). Translate a bit further away say:

glTranslatef(0.5, 0, -10);

For the DC I use:

MemDC := CreateCompatibleDC(0);
  :
DeleteDC(MemDC);

but I assume any DC will make it here as long as the correct font is selected into it.

Ciao, Mike
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KeijoAuthor Commented:
Thanks Mike, I finally got it working!

Btw. do you know why the wglUseFontOutlines takes about 20 seconds to run on my NT4? Some other apps, such as the basic OpenGL 3dText screensaver that comes with windows starts instantly. Can the lists be generated faster or be saved for future use or something?
0
LischkeCommented:
The reason is Delphi. More specific its debugger. Try running your application not under control of Delphi and it runs fine. I don't know what this is, but this problem has been there since at least D3. (Would be interesting to see whether VC6++ causes similar problems...).

Ciao, Mike
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Fonts Typography

From novice to tech pro — start learning today.