jdaniel7's picture

Use QuickFont to print text at 3D positions

Project:The Open Toolkit library
Version:all versions
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:open
Description

I am in the process of removing all dependencies on TAO in my project. I am generating text in the GLControl using GDI and I would like to replace it with QuickFont. I cant figure out a couple of things:

I have a coordinate system I create in 3D space. It has an origin at 0,0,0 , - 3 lines and 3 cones for the axes. I need to place a label at the end of each axis for "X", "Y", "Z". Using GDI I simply do this:

 
            GL.Color3(xComponents); 
            GL.RasterPos3(textOffset, 0.0, 0.0);
            coordFont.Print("X");
 
            GL.Color3(yComponents);
            GL.RasterPos3(0.0, textOffset, 0.0);
            coordFont.Print("Y");
 
            GL.Color3(zComponents);
            GL.RasterPos3(0.0, 0.0, textOffset);
            coordFont.Print("Z");

note: coordFont is a class that used gdi to generate the characters.

 
           public GLFont(Font inputFont)
        {
            m_hDC = CreateCompatibleDC(HDC.Zero);
 
            if (m_hDC == HDC.Zero)
            {
                if (m_hDC == HDC.Zero)
                    throw new Exception(String.Format("Failed to load font '{0}': invalid device context", inputFont.Name));
            }
 
            m_iBase = 0;
 
            m_ftFont = inputFont;
 
            HFONT hFont = m_ftFont.ToHfont();
 
            if (hFont == HFONT.Zero)
            {
                throw new Exception(String.Format("Failed to load font '{0}': invalid handle", inputFont.Name));
            }
 
            m_iBase = GL.GenLists(CHAR_COUNT);
 
            if (m_iBase < 1)
            {
                throw new Exception(String.Format("Failed to load font '{0}': invalid list index", inputFont.Name));
            }
 
            Gdi.SelectObject(m_hDC, hFont);
            Wgl.wglUseFontBitmapsW(m_hDC, 0, CHAR_COUNT, m_iBase);
            Gdi.SelectObject(m_hDC, IntPtr.Zero);
 
        }
 

1. How do I get QuickFont to print the text at the same locations as the RasterPos3 does?
2. How do I keep the font from distorting when the GLControl resizes
3. How do I get the font to stay at its 3D location. If I pan, zoom or rotate I want the text to stay the same size, maintain the same 3D origin as when defined and always be legible.

Thanks