pontifikas's picture

Create 3D Glyphs

I'm trying to port an application from Tao to OpenTK. One of the problems I have encountered is how to render 3D glyphs. Is there a how to or some sample because I cannot find sth relevant

I thank you


Comment viewing options

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

How did you render 3d glyphs with Tao? The best solution I am aware of is to use the FreeType library, either through Tao.FreeType (difficult) or via FTGL# or via ISE.FreeType (easier).

pontifikas's picture
 /// <summary>
        /// Windows Font ID
        /// </summary>
        private IntPtr font;
        private void BuildFont()
            font = Gdi.CreateFont(                                              // Create The Font
                -12,                                                            // Height Of Font
                0,                                                              // Width Of Font
                0,                                                              // Angle Of Escapement
                0,                                                              // Orientation Angle
                Gdi.FW_BOLD,                                                    // Font Weight
                false,                                                          // Italic
                false,                                                          // Underline
                false,                                                          // Strikeout
                Gdi.ANSI_CHARSET,                                               // Character Set Identifier
                Gdi.OUT_TT_PRECIS,                                              // Output Precision
                Gdi.CLIP_DEFAULT_PRECIS,                                        // Clipping Precision
                Gdi.ANTIALIASED_QUALITY,                                        // Output Quality
                Gdi.FF_DONTCARE | Gdi.DEFAULT_PITCH,                            // Family And Pitch
                "Courier New");                                               // Font Name
        private void DrawGlyph(int DC_ID,char letter,int DisplayList)
            int startChar = (int)letter;
            // Storage For Information About Our Outline Font Characters
            Gdi.SelectObject(H_DC[DC_ID], font);                                        // Selects The Font We Created
                H_DC[DC_ID],                                                            // Select The Current DC
                startChar,                                                              // Starting Character
                1,                                                            // Number Of Display Lists To Build
                DisplayList,                                                  // Starting Display Lists
                0,                                                              // Deviation From The True Outlines
                0.2f,                                                           // Font Thickness In The Z Direction
                Wgl.WGL_FONT_POLYGONS,                                          // Use Polygons, Not Lines
                                                          // Address Of Buffer To Recieve Data

And I was Drawing the letters with DrawGlyph at will.

the Fiddler's picture

Ah, the good old WGL font routines. OpenTK doesn't expose any platform-specific APIs, so it cannot provide direct access to WGL.

The easiest solution is to reference Tao.Platform.Windows/dll and access those routines through that. If you want to avoid the extra dependency, you can copy the relevant p/invokes to your project: Gdi.cs and Wgl.cs (use the download link).

Unfortunately, this way you'll lose cross-platform support. If you need that, the best solution is to move to freetype through one of the wrappers linked above.

pontifikas's picture

I'm OK with the extra dependency. Better than to turn to C++ implementation. But the Tao dependency brings me to my other problem. I will be using the GLControl but I need to be able to get the DeviceContext ID. The Context property of GLControl does not provide sth like that. How do I get It?

the Fiddler's picture

You can get a device context using the Gdi.CreateDC method (should be provided by Tao.Platform.Windows).

I do not think you need the internal device context used by OpenTK for this to work, but if you do, you can use reflection on the WindowInfo property and access its DeviceContext property. If you do this, please add a large warning that you are relying on internal OpenTK APIs that might change at some future version (unlikely, but possible).

pontifikas's picture

Thank you for your answers Fiddler. I will hold on to my previous implementations as far as the windows specific part is concerned.
But I want to change all OpenGL specific functions.
One more question if you don't mind. Where is GLU? I've read somewhere that it was moved to Compatibility. I included the dll to my references but
I'm not able to see any functions from that dll.

the Fiddler's picture

Glu lives in OpenTK.Compatibility.dll under the OpenTK.Graphics namespace (yes, it's still there, I just checked! :) )