Drawing3d documented Class Library

FeaturesW32.wglMakeCurrent Method

The wglMakeCurrent function makes a specified OpenGL rendering context the calling thread's current rendering context. All subsequent OpenGL calls made by the thread are drawn on the device identified by deviceContext. You can also use wglMakeCurrent to change the calling thread's current rendering context so it's no longer current.

[Visual Basic]
<PreserveSig> _
<DllImport(EntryPoint:="wglMakeCurrent", CharSet:=CharSet.None, SetLastError:=True, ExactSpelling:=False, PreserveSig:=True, CallingConvention:=CallingConvention.Winapi, BestFitMapping:=False, ThrowOnUnmappableChar:=False, Value:="opengl32.dll")> _
<SuppressUnmanagedCodeSecurity> _
Public Shared Sub wglMakeCurrent( _
   ByVal deviceContext As IntPtr, _
   ByVal renderingContext As IntPtr _
)
[C#]
[PreserveSig]
[DllImport(EntryPoint="wglMakeCurrent", CharSet=CharSet.None, SetLastError=True, ExactSpelling=False, PreserveSig=True, CallingConvention=CallingConvention.Winapi, BestFitMapping=False, ThrowOnUnmappableChar=False, Value="opengl32.dll")]
[SuppressUnmanagedCodeSecurity]
public static bool wglMakeCurrent(
   IntPtr deviceContext,
   IntPtr renderingContext
);

Parameters

deviceContext

Handle to a device context. Subsequent OpenGL calls made by the calling thread are drawn on the device identified by deviceContext.

renderingContext

Handle to an OpenGL rendering context that the function sets as the calling thread's rendering context.

If rendingContext is Zero, the function makes the calling thread's current rendering context no longer current, and releases the device context that is used by the rendering context. In this case, deviceContext is ignored.

Return Value

When the wglMakeCurrent function succeeds, the return value is true; otherwise the return value is false. To get extended error information, call GetLastWin32Error.

Remarks

The deviceContext parameter must refer to a drawing surface supported by OpenGL. It need not be the same deviceContext that was passed to wglCreateContext when renderingContext was created, but it must be on the same device and have the same pixel format. GDI transformation and clipping in deviceContext are not supported by the rendering context. The current rendering context uses the deviceContext device context until the rendering context is no longer current.

Before switching to the new rendering context, OpenGL flushes any previous rendering context that was current to the calling thread.

A thread can have one current rendering context. A process can have multiple rendering contexts by means of multithreading. A thread must set a current rendering context before calling any OpenGL functions. Otherwise, all OpenGL calls are ignored.

A rendering context can be current to only one thread at a time. You cannot make a rendering context current to multiple threads.

An application can perform multithread drawing by making different rendering contexts current to different threads, supplying each thread with its own rendering context and device context.

If an error occurs, the wglMakeCurrent function makes the thread's current rendering context not current before returning.

See Also

FeaturesW32 Class | Drawing3d.OS.Windows Namespace | wglCreateContext | wglDeleteContext | wglGetCurrentContext