OpenGL and VC++ -> Switching Views

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

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

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:


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();


This should work.



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?

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…

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

Yes, in both views, in PreCreateWindow handle: |= (WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CS_OWNDC);

Originally posted by link19:
[b]Yes, in both views, in PreCreateWindow handle:



CS_OWNDC won’t do what you think here. The 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.

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!!