CS_OWNDC obligatory?

I have read that it can be necessary to use the class style flag CS_OWNDC for windows you wish to render in via OpenGL.

Does this restriction still apply in Windows XP?

Experimentally I can render sucessfully on Windows XP regardless of the value of this flag, but I only have a few machines to test on. On Windows 98 I have found that some systems need the flag set while others dont seem to mind.

Thanks,

Tom

I think this is an urban legend. I have never found an official Microsoft document requiring the use of CS_OWNDC. But I know that a lot of early OpenGL implementations had problems with applications using different HDCs to make the context current. E.g. if you bracket your WM_PAINT handler with BeginPaint - EndPaint, the HDC returned by BeginPaint may change if you don’t use CS_OWNDC, but that’s ok according to the OpenGl context handling in MS docs.
I use OpenGL on Windows since NT 3.5.1 and if you didn’t use CS_OWNDC some implementations just crashed on exit, didn’t SwapBuffers correctly etc. in the early years.
I don’t comment on Win9x, I never even installed it.
Since then I locked my HDC down once at WM_CREATE time, no need to use CS_OWNDC.
I think the OpenGL drivers have matured since then, but for the fun of it give it a try. :wink:

Originally posted by Relic:
I think this is an urban legend. I have never found an official Microsoft document requiring the use of CS_OWNDC. But I know that a lot of early OpenGL implementations had problems with applications using different HDCs to make the context current. E.g. if you bracket your WM_PAINT handler with BeginPaint - EndPaint, the HDC returned by BeginPaint may change if you don’t use CS_OWNDC, but that’s ok according to the OpenGl context handling in MS docs.
[…]
Since then I locked my HDC down once at WM_CREATE time, no need to use CS_OWNDC.
I think the OpenGL drivers have matured since then, but for the fun of it give it a try. :wink:

It’s urban legend upto a point, you must know very well what you are doing if you don’t set CS_OWNDC.

As you mention, CS_OWNDC means that when you do a GetDC/BeginPaint on a given window handle, that handle will always be the same.

If you don’t use CS_OWNDC, then you have to call wglMakeCurrent after every BeginPaint or use a stock DC you GetDC() but never ReleaseDC() (I assume that’s what you mean with “locking your HDC down at WM_CREATE”).

I don’t think the “locking” thing is a good idea if you want to do GDI rendering on top of your OpenGL rendering. You should only be rendering to your window HDC between BeginPaint/EndPaint invocations and you should be using the HDC returned by BeginPaint. Also, you won’t benefit from things like the cliprects of the update region, which are setup by the window manager when a region of the HDC is invalidated.

All in all, I don’t see any reason for not using CS_OWNDC, all I see are inconveniences.

querying the MSDN may be helps
http://search.microsoft.com/search/results.aspx?qu=CS_OWNDC&View=msdn&st=b&c=0&s=1&swc=0

Agreed, holding the HDC with GetDC at WM_CREATE time is not really smart (and, for historic interest, didn’t work for Win 3.1 which had only five HDCs at a time, of which one was reserved for the desktop), but I’m writing small apps most of the time. :slight_smile:

Gollum, I meant CS_OWNDC as requirement for OpenGL rendering is never mentioned. Good link anyway, I didn’t realize the HDC cache across threads.

For win9x systems, you need to have CS_OWNDC, at least that’s what I have learned.
I don’t typically do GDI rendering on GL and call wglMakeCurrent every time I need to make GL calls.

In Win9x systems, the same DC may be recycled between you and other Windows. These OSs had resource issues. I think it is limited to 15 HDC on Win95.

On NT systems, this is not a problem. It has a virtually unlimited number of resources.

Neverthless, I include it always in my projects, D3D or GL.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.