opengl render context

In windows GDI, when you want to draw to the screen you create a device context and use the HDC (handle to the device context) with any function, for example:
BOOL Ellipse(HDC hdc, int nLeftRect, ...);

in opengl programing you don't specify the HRC (handle to render context) every time you use opengl function.
how does it work ?
In case of two different processes that run in the same time, how the opengl dll know which process called. why it is importent to the opengl dll to know that?, this is because every process defines states for the opengl (for example line stippling), that means that the opengl should apply the line stippling state according to the current process which request to draw a line.

how does it work ?
hope i explained the question :)
Who is Participating?
nomad516Connect With a Mentor Commented:
yep, you don't specify the HRC because you told
openGL that a window uses this specific RC.

I have a tutorial at:

Take a look at the first opengl tutorial (setting
it up), it explains where to "bind" the RC and the

Hope this helps!
Jan LouwerensSoftware EngineerCommented:
HDC is a structure used by Windows to draw to the screen.
OpenGL does not draw to the screen using windows. It accesses the video hardware directly, through the use of your video drivers.

An analogy could be that you could draw with a pen or with a pencil. And in your question, you're asking how the pencil can draw without using any ink. The ink is just the means of how the pen draws, not the pencil. And HDC is a means of how Windows draws, but not OpenGL
to accomplish the portablity of the core Open GL  functions each environment must implement some means specifying a current rendering window before executing any OPEN GL commands.just as the windows GDI functions use the windows device contexts ,the OpenGl environment is embodied in what is known as rendering context .just as device contxet remembers settings abt drawing modes and commands for the GDI,teh rendering context remembers Opengl
settings and commands

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Ronnie_ShmuelAuthor Commented:
you answered what are role of the rendering context. but the question is: HOW DOES THE OPENGL DLL KNOW which process (in case of more then one) called him and accordingly USE it's RENDERING CONTEXT. in windows programing we specify the device context but in openGL we do not do that in any place.

hope that's clear !
Copied from the MSDN library:
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 hdc. You can also use wglMakeCurrent to change the calling thread's current rendering context so it's no longer current.

BOOL wglMakeCurrent(
  HDC  hdc,      // device context of device that OpenGL calls are
                 // to be drawn on
  HGLRC  hglrc   // OpenGL rendering context to be made the calling
                 // thread's current rendering context

Hope this helps
To create such a opengl specific rendering context. (Just like HRC, just that opengl has their own).  You use the function wglCreateContext.
Again from MSDN

The wglCreateContext function creates a new OpenGL rendering context, which is suitable for drawing on the device referenced by hdc. The rendering context has the same pixel format as the device context.

HGLRC wglCreateContext(
  HDC  hdc   // device context of device that the rendering context
             // will be suitable for

There you go
This is what nomad meant when he said, "look at tutorial...".  So I think, with the addition of my comments, his explanation is clear enough.  So give him the points :)
Ronnie_ShmuelAuthor Commented:
sorry nomad for the long time it took me to give you the point. you should thanks Vincenz which explained me your answer.

tnx Vincenz!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.