Search code examples
vb.netopenglopentk

With OpenTK and VB.NET, how to use GLControl with OpenGL 3.x features?


I'm using OpenTK with rendering through a GLControl. However, I cannot find any examples on the internet or figure out how to use OpenGL 3.x features (Disregarding the short mention in the OpenTK FAQ, which wasn't overly helpful).

By OpenGL 3.x features, I'm meaning that the whole 'glTranslate' model is unaccessible, and the only rendering or translation, etc, is used through shaders and passing around model/view/projection matrices.


Solution

  • GLControl by default creates a compatibility context with the maximum version supported by your drivers. For example, if you have a recent Nvidia card with up-to-date drivers, GLControl will give you an OpenGL 4.5 compatibility context.

    Note that on Linux and Mac OS X, compatibility contexts are limited to OpenGL 2.1. To access higher versions you need to create a core context instead:

    var glControl = new GLControl(GraphicsMode.Default, 4, 0, GraphicsContextFlags.ForwardCompatible);
    

    Deprecated functions, such as glTranslate, are not available on core contexts.

    If you are using the WinForms UI designer, you can achieve the same result by deriving a custom control from GLControl and specifying the desired (minimum) version in its constructor:

    class CoreGLControl : GLControl
    {
        public CoreGLControl() : base(GraphicsMode.Default, 3, 0, GraphicsContextFlags.ForwardCompatible)
        { }
    }
    

    You can then drag and drop this onto your form.