I’ve come to enjoy the ease of creating an OpenGL-ready framework via the MFC app wizard in Visual C++. However, one thing that I don’t do is register the window class. So, no CS_OWNDC is called. Can anyone speak to the drawbacks/bugs associated with not registering a window class?
Actually, I can… I could even write a book on that !!! No, kidding… .
Well, I had one problem when removing the CS_OWNDC bit in my 3D Modeller.
Let me just tell you a bit about my architecture: I use one Rendering Context (RC) per document and then one Device Context (DC) per view. That enables me to share Display Lists and textures without using wglShareLists and save memory.
Then, I can pick / transform objects (hey, that’s a modeller !). When removing the CS_OWNDC bit, I sometimes had glitches in the other views while transforming in one of them… Those glitches did never happen when using CS_OWNDC…
I must say I do not know for sure why these things happen… but they do !
So, stay on the safe side, and register your window class with the CS_OWNDC bit !!!
Could I declare CS_OWNDC in the CMainFrame::PreCreateWindow() function? Like cs.style |= CS_OWNDC ? Is that the proper method, or should I be looking elsewhere?
The cs.style method won’t work. That will pass CS_OWNDC to CreateWindow which isn’t what you want. Instead, you should use the AfxRegisterWndClass() function. You can use it something like so…
>>> Let me just tell you a bit about my architecture: I use one Rendering Context (RC) per document and then one Device Context (DC) per view. That enables me to share Display Lists and textures without using wglShareLists and save memory.
I Eric,
Above you mentioned you use one RC per doc and one DC per view - I was just wondering how you got that to work. I tried it and no joy. If you could explain I would be most greatful as I’m writing an editor that suffers alot from having an RC per view. It effectively halves the frame rate per extra view (I have 4 standard views).
Well, the easiest way to solve your problem is to tell me which bug you have (you said that having one RC per document does not work for you !).
As far as I am concerned, I just create the RC with the first view… Then, each time I want to render something in a view, I use wglMakeCurrent with the document’s RC and the view’s DC… Nothing really clever…
The main bug I ever had was to forget about a wglMakeCurrent (which made OpenGL render everywhere except where I expected it !)…
If you can tell us what the bug is when you try to use this technique, we might be able to tell you why !