Home

wglMakeCurrent

wglMakeCurrent is a Windows-specific function in the WGL API that binds an OpenGL rendering context to a device context for the calling thread. It allows subsequent OpenGL commands issued by that thread to render to the specified device context using the specified rendering context. The function is typically declared as BOOL wglMakeCurrent(HDC hdc, HGLRC hglrc); and returns a nonzero value on success or zero on failure.

When both hdc and hglrc are non-NULL, wglMakeCurrent binds the given rendering context to the given device

Usage in a typical OpenGL flow involves obtaining a device context, selecting a suitable pixel format, creating

Important considerations include thread ownership: a GL context may be current on only one thread at a

context
for
the
calling
thread.
If
both
parameters
are
NULL,
the
function
releases
the
current
rendering
context
from
the
thread,
meaning
no
GL
context
is
current
for
that
thread.
If
only
one
parameter
is
NULL,
the
call
generally
fails
and
leaves
the
current
context
unchanged.
a
GL
rendering
context,
and
then
calling
wglMakeCurrent(hdc,
hglrc)
to
begin
rendering.
To
stop
rendering
and
detach
the
context,
a
common
step
is
to
call
wglMakeCurrent(NULL,
NULL).
Proper
cleanup
also
includes
releasing
the
device
context
and
destroying
the
GL
context
when
it
is
no
longer
needed.
time,
and
a
thread
may
have
at
most
one
current
GL
context.
Errors
can
arise
from
invalid
or
mismatched
device
contexts
or
rendering
contexts,
or
from
attempting
to
use
GL
commands
when
no
context
is
current.
Retrieve
extended
error
information
via
system
APIs
if
wglMakeCurrent
fails.