HangDude's picture

using WGL Extensions


I'm trying to synchronize two displays for stereo vision on a quadro card using a Genlock card. Therefore I need access to the wglJoinSwapGroupNV (and friends) method. What would be the best way to do this using OpenTK?
I would really dislike having to switch away from OpenTK just because of this.

Thank you in advance,


Comment viewing options

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

OpenTK doesn't expose this extension right now, but please add a feature request and I will look into adding it in a future version.

In the meantime, it is quite easy to p/invoke the necessary functions by hand:

using System;
using System.RuntimeInteropServices;
static class Wgl
    // WGL_swap_group extension
    public delegate bool wglJoinSwapGroupNV(IntPtr dc, uint group);
    public delegate bool wglBindSwapBarrierNV(uint group, uint barrier);
    public delegate bool wglQuerySwapGroupNV(IntPtr dc, out uint group, out uint barrier);
    // Necessary "core" WGL functions
    [DllImport("opengl32.dll", EntryPoint = "wglGetProcAddress", ExactSpelling = true, SetLastError = true)]
    extern static IntPtr GetProcAddress(string lpszProc);
    [DllImport("opengl32.dll", EntryPoint = "wglGetCurrentDC", ExactSpelling = true, SetLastError = true)]
    extern static IntPtr GetCurrentDC();
    public static readonly wglJoinSwapGroupNV JoinSwapGroupNV;
    public static readonly wglBindSwapBarrierNV BindSwapBarrierNV;
    public static readonly wglQuerySwapGroupNV QuerySwapGroupNV;
    public static Wgl()
        JoinSwapGroupNV = Marshal.GetDelegateForFunctionPointer(
        BindSwapBarrierNV = Marshal.GetDelegateForFunctionPointer(
// Usage: create an OpenGL context (through GLControl) and use WGL_swap_group normally.
IntPtr dc = Wgl.GetCurrentDC();
int group = 1;
Wgl.JoinSwapGroupNV(dc, group);