Wether I can Initialize OpenGL RC in the same workspace for different DC

I am developing a project, I render object using OpenGL in the View, and I want to display small picture on a dialog static control too, but after I shut down that dialog, my main rendering view doesn’t run anymore, I don’t know why, who can tell me, thanks.

Are you using just one RC? If so, you are doing wglMakeCurrent() in your view and your dialog before rendering? Also, you’re not doing wglDeleteContext() from the dialog when it closes?

Some code would make it easier …

You need to creat a render context for both the dialog and VIEW. Then you set the current context for each

//in OnDraw of CVIew
wglMakeCurrent(…//hrc for view

//in OnDraw of CDialog
wglMakeCurrent(…//hrc for dialog

Then it will work fine. You of course have do all opengl inits for both, projection, modelview, current color, texture etc…

Just take a look at your CView class and duplicate the opengl wgl code for the dialog.

I use different RC for view and dialog’s static control respectively,though I put wglDeleteContext() in the deconstruct function of the dialog, why I can’t delete this RC, and affect the main window, It is big problem, that the main window can’t display correctly,it doesn’t work anymore, how to solve this problem?

Just as a note, I would put the destruction code in the OnDestroy handler. It seemed to create some issues for me when I put in destructor because critical dialog resources had already been deallocated.

Additionally, make sure you have

wglMakeCurrent(… called either each time
you Draw on your view, or right after dialog is destroyed.

Maybe a few snipets of code would also help in diagnosing your issue. Regards.

this is really strange, If I first display the main scene in the View, everything is Ok, then open the dialog, the object can display correctly on the dialog too, but after close the dialog, the view of the main scene doesn’t render anymore, If I open the dialog first, the object can display on the dialog rightly,so I close the dialog and begin to read data and display it in the main view, but, it stop to work with an excetion, when I trace into, I found when step at glActiveTextureARB, there is an unhandled exception,why? it make me very confused,I need help.

snippet code of the dialog for deinitialize
CModelerDlg::~CModelerDlg()
{
ClearUp();
DeInit();
}
void CModelerDlg: eInit()
{
if (g_hRC)
{
bool bRet = wglMakeCurrent(NULL, NULL);
wglDeleteContext(g_hRC);
}
if (g_hDC)
::ReleaseDC(g_hWnd, g_hDC);
}

I have solved this problem, that is I should change the RC by wglMakeCurrent() each time to switch between different DC.

That is what I posted in my first response to this thread. Anyways, very happy that you solved your problem. Cheers.

thanks, maximian