PDA

View Full Version : OpenGL and VC++ -> Switching Views



link19
01-31-2001, 11:59 AM
Hello all,
Ive got two views in my app that i can switch to and from. The problem is that after adding the second view, the first is affected. I cant see the rendering. Dont know why or how since they're independent of each other. Ive been fooling around with wglMakeCurrent(NULL, NULL) which i call only at the end of OnCreate in my first view. If i make that call in my second view (which i thought i was supposed to) i cant see the rendering there either.
So the current situation is that on execution, the first view comes up empty (blank). When i switch to the second, its all good. When i switch back...i still see the second.
Hope ive been clear.
thanx for any help http://www.opengl.org/discussion_boards/ubb/smile.gif

[This message has been edited by link19 (edited 01-31-2001).]

Eric
01-31-2001, 11:32 PM
It depends on how you defined your rendering context: in my programs, I have one rendering context (HGLRC) per document shared amongst all views (each of them having one HDC). But you could have one HGLRC and one HDC per view...

I assume you are in the first case: one HGLRC for the document and one HDC per view.
Since you are using MFC, you probaby use the HDC wrapper, which is a CDC.

So, in your CMyDocument definition, you should have somewhere:





HGLRC m_hRC;



And in your CMyView definition:





CDC *m_pDC;



I suppose you initialize m_pDC in the OnCreate member of your CMyView by:





m_pDC = new CClientDC(this);



Now, let's say you render everything in a Render() member function of your CView object. The proper way to set this is:




void CMyView::Render(void)
{

CMyDocument *pDoc=GetDocument();
wglMakeCurrent(m_pDC->GetSafeHdc(),pDoc->m_hRC);
// RENDER YOUR STUFF //
wglMakeCurrent(NULL,NULL);

}


This should work.

Regards.

Eric

link19
02-01-2001, 06:43 AM
Thanx Eric,
you are correct with respect to having one rendering context for per doc shared amongst all views. However, as this should work, it still does not.
Ive gone through my code again and cannot find my error. On execution i still get an empty view (the view is my source code window in VC++). May this have something to do with glClear or glClearColor? Im not sure...ideas anyone?

link19
02-02-2001, 05:56 AM
Another thought...both the first and second views are shared with a CFormView separated by a splitter. Could this be where the problem lies?
This has been driving me mad for days... http://www.opengl.org/discussion_boards/ubb/mad.gif

Thaellin
02-02-2001, 10:10 AM
I'm not sure if it applies in your case, but are the windows being created with the CS_OWNDC flag set? It can take care of problems like this...

-- Jeff

link19
02-02-2001, 12:19 PM
Yes, in both views, in PreCreateWindow handle:



cs.style |= (WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CS_OWNDC);

Deiussum
02-02-2001, 12:45 PM
Originally posted by link19:
Yes, in both views, in PreCreateWindow handle:



cs.style |= (WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CS_OWNDC);


CS_OWNDC won't do what you think here. The cs.style flags are used when MFC does the CreateWindow. You need CS_OWNDC as a class style when the class is registered. You have to do something like...

cs.lpszClass = AfxRegisterWndClass(CS_OWNDC | CS_HREDRAW | CS_VREDRAW);

You can also specify things like the HCURSOR, HICON, and HBRUSH for the class with that function. Take a look at the description of it in MSDN.

link19
02-05-2001, 07:49 AM
I know somebody's got the answer out there.
Ive overridden the PreCreateWindow function in my CMyChildWnd class (MDI app) and changed the style to indicate the above, but this has no effect.
I still cannot see my initial view!! http://www.opengl.org/discussion_boards/ubb/confused.gif