how to use several ogl control?

i make a static control use ogl to render in mfc,but when i add at least two controls on a form view,it doesn’t work correctly,just the last control do.what’s the matter and how to resolve it? thanks a lot.
BTW:diffrent control use diffrent hwnd and use diffrent hdc of’s no problem when i use d3d9 to make this control.

You need to call wglMakeCurrent(…) to set the control you want to render to. Google it :slight_smile:

Since each control has it’s own HWND and HDC you have to create separate rendering contexts (HGLRC) for both of them, and switch with wglMakeCurrent as Mikkel suggested.

i create separate rendering contexts(HGLRC) and call the funtion of wglMakeCurrent(m_hDC,m_hRC) before clearbuffer to render. but it’s the same problem.

For what it’s worth, you can actually create a single context for multiple windows (just call SetPixelFormat with each DC). You will be limited to a single pixel format tho.


i see,before any ogl fun is called,wglMakeCurrent must be called because any switch in diffirent contexts can make error.for example, creating texture,etc. that’s ok.thanks.

That seems right. However you can call wglShareLists to share resources among your contexts, if that’s the trouble you’re having.