PDA

View Full Version : Wether I can Initialize OpenGL RC in the same workspace for different DC



victorswan
12-16-2003, 07:33 AM
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.

Rog
12-16-2003, 07:41 AM
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 .....

maximian
12-16-2003, 07:44 AM
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.

victorswan
12-16-2003, 07:48 AM
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?

maximian
12-16-2003, 07:51 AM
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.

victorswan
12-16-2003, 08:10 AM
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.

victorswan
12-16-2003, 08:21 AM
snippet code of the dialog for deinitialize
CModelerDlg::~CModelerDlg()
{
ClearUp();
DeInit();
}
void CModelerDlg: http://www.opengl.org/discussion_boards/ubb/biggrin.gifeInit()
{
if (g_hRC)
{
bool bRet = wglMakeCurrent(NULL, NULL);
wglDeleteContext(g_hRC);
}
if (g_hDC)
::ReleaseDC(g_hWnd, g_hDC);
}

victorswan
12-17-2003, 05:40 AM
I have solved this problem, that is I should change the RC by wglMakeCurrent() each time to switch between different DC.

maximian
12-17-2003, 02:52 PM
That is what I posted in my first response to this thread. Anyways, very happy that you solved your problem. Cheers.

victorswan
12-18-2003, 07:52 PM
thanks, maximian