OpenGL Context with Anti-Aliasing but without wxGLCanvas

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
LukasBanana
Knows some wx things
Knows some wx things
Posts: 27
Joined: Mon Jul 11, 2011 5:02 pm

OpenGL Context with Anti-Aliasing but without wxGLCanvas

Post by LukasBanana » Tue Apr 15, 2014 8:38 pm

Hi,
I'm currently working with wxWidgets 3.0.0 and everything works pretty good :-)
There is only one thing which is currently not working as I want it.

First of all, I know about the wxGLCanvas class, but the problem is, I'm writing my own Game Engine, which has its own GL Context class and also a Direct3D 11 context class.
So I can't use "wxGLCanvas" or "wxGLContext".

This is actually working, but I can not enable anti-aliasing (i.e. choose an multi-sampling pixel format) for the wxWindow object.

This is how I get the HWND and HDC inside my game engine:

Code: Select all

// Inside my editor:
class MyScreenFrame : public wxWindow { /* ... */ };
MyScreenFrame* myScreen = /* ... */

auto nativeHandle = myScreen->GetHWND(); // <-- Get native HWND handle from wxWidgets

CreateRenderContext(nativeHandle);

// Inside my game engine:
CreateRenderContext(HWND nativeHandle)
{
    HWND hDC = GetDC(nativeHandle); // <-- Get native HDC handle.
    wglChoosePixelFormatARB(hDC, /* ... */); // <-- Choose pixel format with multi-sampling configuration via GL ARB extension. (THIS WILL FAIL)
    /* ... */
}
Can anyone tell me how wxGLCanvas can handle multi-sampling render contexts, so I can do this as well, but with "wxWindow" as base class.

Thanks in advance :-)
OS: Windows 7 Ultimate 64bit
wxVersion: 2.9.2
Compiler: VisualC++ 2008

User avatar
doublemax
Moderator
Moderator
Posts: 15690
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: OpenGL Context with Anti-Aliasing but without wxGLCanvas

Post by doublemax » Tue Apr 15, 2014 9:39 pm

I can only suggest to look into the wx source file and check if there's something missing/different in your code: <wxdir>\src\msw\glcanvas.cpp

Is it possible that you're setting the pixel format more than once? Because there's this comment in the above mentioned file:

Code: Select all

            // from http://msdn.microsoft.com/en-us/library/ms537559(VS.85).aspx:
            //
            //      Setting the pixel format of a window more than once can
            //      lead to significant complications for the Window Manager
            //      and for multithread applications, so it is not allowed. An
            //      application can only set the pixel format of a window one
            //      time. Once a window's pixel format is set, it cannot be
            //      changed.
            //
            // so we need to delete the old window and create the new one
Use the source, Luke!

LukasBanana
Knows some wx things
Knows some wx things
Posts: 27
Joined: Mon Jul 11, 2011 5:02 pm

Re: OpenGL Context with Anti-Aliasing but without wxGLCanvas

Post by LukasBanana » Tue Apr 15, 2014 10:13 pm

Yes, I remembered that I re-created the window, when I do my own Win32 programming.

Is there an elegant way to re-create a wxWindow without destroying it completely?
OS: Windows 7 Ultimate 64bit
wxVersion: 2.9.2
Compiler: VisualC++ 2008

LukasBanana
Knows some wx things
Knows some wx things
Posts: 27
Joined: Mon Jul 11, 2011 5:02 pm

Re: OpenGL Context with Anti-Aliasing but without wxGLCanvas

Post by LukasBanana » Tue Apr 15, 2014 10:21 pm

Ok by now, I found a very ugly solution (currently with deleting and re-creating the entire wxWindow object).
But maybe I can do this a little better next day.
Thanks anyway :-)
OS: Windows 7 Ultimate 64bit
wxVersion: 2.9.2
Compiler: VisualC++ 2008

Post Reply