Acidic32's picture

Enable WGL Access

Project:The Open Toolkit library
Version:all versions
Component:Code
Category:support request
Priority:critical
Assigned:Unassigned
Status:by design
Description

How can i enable WGL Access in OpenTK?

I dont want to include Tao's Platform class if possible

Thanks


Comments

Comment viewing options

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

#1

Status:open» by design

The WGL bindings are an implementation detail that is hidden by design. The only way to access them is to copy the code from Source/Platform/Windows/Bindings directly into your project.

Note that you'll need to create a context and call Wgl.LoadAll() prior to using any Wgl methods, otherwise you will get a NullReferenceException. This is necessary to ensure WGL extensions work correctly (Tao.Platform.Windows fails here).

However, I strongly suggest that you file a feature request against the GraphicsContext class instead of using WGL directly. If possible, we will expose the necessary functionality and make sure that it works correctly along the rest of OpenTK.

Acidic32's picture

#2

Well all i really use it for is Text Printing as OpenTK's Text Printer seems to be slow compared to using the WGL method

the Fiddler's picture

#3

In that case, the simplest solution is to copy the two or three DllImports from WglCore.cs. This will bind you to the windows platform, though.

Another possibility is to use System.Drawing.Graphics to print text onto a System.Drawing.Bitmap and upload that to a texture. As long as you text doesn't change every frame, this is likely to be even faster than WGL.

Acidic32's picture

#4

Not sure really...

the Fiddler's picture

#5

Not sure about what? :)

Acidic32's picture

#6

What i need to take from the OpenTK Source to use WGL

;)

the Fiddler's picture

#7

This should be all:

            [System.Security.SuppressUnmanagedCodeSecurity()]
            [System.Runtime.InteropServices.DllImport(Wgl.Library, EntryPoint = "wglUseFontBitmapsA", CharSet = CharSet.Auto)]
            internal extern static Boolean UseFontBitmapsA(IntPtr hDC, Int32 first, Int32 count, Int32 listBase);
            [System.Security.SuppressUnmanagedCodeSecurity()]
            [System.Runtime.InteropServices.DllImport(Wgl.Library, EntryPoint = "wglUseFontBitmapsW", CharSet = CharSet.Auto)]
            internal extern static Boolean UseFontBitmapsW(IntPtr hDC, Int32 first, Int32 count, Int32 listBase);
            [System.Security.SuppressUnmanagedCodeSecurity()]
            [System.Runtime.InteropServices.DllImport(Wgl.Library, EntryPoint = "wglUseFontOutlinesA", CharSet = CharSet.Auto)]
            internal extern static unsafe Boolean UseFontOutlinesA(IntPtr hDC, Int32 first, Int32 count, Int32 listBase, float thickness, float deviation, Int32 fontMode, GlyphMetricsFloat[] glyphMetrics);
            [System.Security.SuppressUnmanagedCodeSecurity()]
            [System.Runtime.InteropServices.DllImport(Wgl.Library, EntryPoint = "wglUseFontOutlinesW", CharSet = CharSet.Auto)]
            internal extern static unsafe Boolean UseFontOutlinesW(IntPtr hDC, Int32 first, Int32 count, Int32 listBase, float thickness, float deviation, Int32 fontMode, GlyphMetricsFloat[] glyphMetrics);
 
    #region GlyphMetricsFloat
 
    /// <summary>
    /// The <b>GlyphMetricsFloat</b> structure contains information about the placement and orientation of a glyph in a
    /// character cell.
    /// </summary>
    /// <remarks>The values of <b>GlyphMetricsFloat</b> are specified as notional units.</remarks>
    /// <seealso cref="PointFloat" />
    [StructLayout(LayoutKind.Sequential)]
    internal struct GlyphMetricsFloat
    {
        /// <summary>
        /// Specifies the width of the smallest rectangle (the glyph's black box) that completely encloses the glyph.
        /// </summary>
        internal float BlackBoxX;
        /// <summary>
        /// Specifies the height of the smallest rectangle (the glyph's black box) that completely encloses the glyph.
        /// </summary>
        internal float BlackBoxY;
        /// <summary>
        /// Specifies the x and y coordinates of the upper-left corner of the smallest rectangle that completely encloses the glyph.
        /// </summary>
        internal PointFloat GlyphOrigin;
        /// <summary>
        /// Specifies the horizontal distance from the origin of the current character cell to the origin of the next character cell.
        /// </summary>
        internal float CellIncX;
        /// <summary>
        /// Specifies the vertical distance from the origin of the current character cell to the origin of the next character cell.
        /// </summary>
        internal float CellIncY;
    }
 
    #endregion
 
    #region PointFloat
 
    /// <summary>
    /// The <b>PointFloat</b> structure contains the x and y coordinates of a point.
    /// </summary>
    /// <seealso cref="GlyphMetricsFloat" />
    [StructLayout(LayoutKind.Sequential)]
    internal struct PointFloat
    {
        /// <summary>
        /// Specifies the horizontal (x) coordinate of a point.
        /// </summary>
        internal float X;
        /// <summary>
        /// Specifies the vertical (y) coordinate of a point.
        /// </summary>
        internal float Y;
    };
 
    #endregion
Acidic32's picture

#8

oh right, cheers now trying it ;)

Acidic32's picture

#9

What is Wgl.Library ?

Acidic32's picture

#10

Right, do i need to Load the Library?