1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/glcanvas.cpp
3 // Purpose: wxGLCanvas, for using OpenGL with wxWidgets under MS Windows
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
22 #if defined(__BORLANDC__)
34 #include "wx/msw/private.h"
36 #include "wx/glcanvas.h"
38 // from src/msw/window.cpp
39 LRESULT WXDLLEXPORT APIENTRY _EXPORT
wxWndProc(HWND hWnd
, UINT message
,
40 WPARAM wParam
, LPARAM lParam
);
42 #ifdef GL_EXT_vertex_array
43 #define WXUNUSED_WITHOUT_GL_EXT_vertex_array(name) name
45 #define WXUNUSED_WITHOUT_GL_EXT_vertex_array(name) WXUNUSED(name)
48 // ----------------------------------------------------------------------------
49 // define possibly missing WGL constants
50 // ----------------------------------------------------------------------------
52 #ifndef WGL_ARB_pixel_format
53 #define WGL_DRAW_TO_WINDOW_ARB 0x2001
54 #define WGL_ACCELERATION_ARB 0x2003
55 #define WGL_NUMBER_OVERLAYS_ARB 0x2008
56 #define WGL_NUMBER_UNDERLAYS_ARB 0x2009
57 #define WGL_SUPPORT_OPENGL_ARB 0x2010
58 #define WGL_DOUBLE_BUFFER_ARB 0x2011
59 #define WGL_STEREO_ARB 0x2012
60 #define WGL_COLOR_BITS_ARB 0x2014
61 #define WGL_RED_BITS_ARB 0x2015
62 #define WGL_GREEN_BITS_ARB 0x2017
63 #define WGL_BLUE_BITS_ARB 0x2019
64 #define WGL_ALPHA_BITS_ARB 0x201B
65 #define WGL_ACCUM_RED_BITS_ARB 0x201E
66 #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
67 #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
68 #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
69 #define WGL_DEPTH_BITS_ARB 0x2022
70 #define WGL_STENCIL_BITS_ARB 0x2023
71 #define WGL_AUX_BUFFERS_ARB 0x2024
72 #define WGL_FULL_ACCELERATION_ARB 0x2027
75 #ifndef WGL_ARB_multisample
76 #define WGL_SAMPLE_BUFFERS_ARB 0x2041
77 #define WGL_SAMPLES_ARB 0x2042
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
85 The following two compiler directives are specific to the Microsoft Visual
86 C++ family of compilers
88 Fundementally what they do is instruct the linker to use these two libraries
89 for the resolution of symbols. In essence, this is the equivalent of adding
90 these two libraries to either the Makefile or project file.
92 This is NOT a recommended technique, and certainly is unlikely to be used
93 anywhere else in wxWidgets given it is so specific to not only wxMSW, but
94 also the VC compiler. However, in the case of opengl support, it's an
95 applicable technique as opengl is optional in setup.h This code (wrapped by
96 wxUSE_GLCANVAS), now allows opengl support to be added purely by modifying
97 setup.h rather than by having to modify either the project or DSP fle.
99 See MSDN for further information on the exact usage of these commands.
102 # pragma comment( lib, "opengl32" )
103 # pragma comment( lib, "glu32" )
106 // ----------------------------------------------------------------------------
108 // ----------------------------------------------------------------------------
110 IMPLEMENT_CLASS(wxGLContext
, wxObject
)
112 wxGLContext::wxGLContext(wxGLCanvas
*win
, const wxGLContext
* other
)
114 m_glContext
= wglCreateContext(win
->GetHDC());
115 wxCHECK_RET( m_glContext
, wxT("Couldn't create OpenGL context") );
119 if ( !wglShareLists(other
->m_glContext
, m_glContext
) )
121 wxLogLastError(wxT("wglShareLists"));
126 wxGLContext::~wxGLContext()
128 // note that it's ok to delete the context even if it's the current one
129 wglDeleteContext(m_glContext
);
132 bool wxGLContext::SetCurrent(const wxGLCanvas
& win
) const
134 if ( !wglMakeCurrent(win
.GetHDC(), m_glContext
) )
136 wxLogLastError(wxT("wglMakeCurrent"));
142 // ============================================================================
144 // ============================================================================
146 IMPLEMENT_CLASS(wxGLCanvas
, wxWindow
)
148 BEGIN_EVENT_TABLE(wxGLCanvas
, wxWindow
)
150 EVT_PALETTE_CHANGED(wxGLCanvas::OnPaletteChanged
)
151 EVT_QUERY_NEW_PALETTE(wxGLCanvas::OnQueryNewPalette
)
155 // ----------------------------------------------------------------------------
156 // wxGLCanvas construction
157 // ----------------------------------------------------------------------------
159 static int ChoosePixelFormatARB(HDC hdc
, const int *attribList
);
161 void wxGLCanvas::Init()
163 #if WXWIN_COMPATIBILITY_2_8
169 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
171 const int *attribList
,
175 const wxString
& name
,
176 const wxPalette
& palette
)
180 (void)Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
);
183 wxGLCanvas::~wxGLCanvas()
185 ::ReleaseDC(GetHwnd(), m_hDC
);
188 // Replaces wxWindow::Create functionality, since we need to use a different
190 bool wxGLCanvas::CreateWindow(wxWindow
*parent
,
195 const wxString
& name
)
197 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
199 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
202 parent
->AddChild(this);
205 A general rule with OpenGL and Win32 is that any window that will have a
206 HGLRC built for it must have two flags: WS_CLIPCHILDREN & WS_CLIPSIBLINGS.
207 You can find references about this within the knowledge base and most OpenGL
208 books that contain the wgl function descriptions.
211 DWORD msflags
= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
212 msflags
|= MSWGetStyle(style
, &exStyle
);
214 if ( !MSWCreate(wxApp::GetRegisteredClassName(wxT("wxGLCanvas"), -1, CS_OWNDC
),
215 NULL
, pos
, size
, msflags
, exStyle
) )
218 m_hDC
= ::GetDC(GetHwnd());
225 bool wxGLCanvas::Create(wxWindow
*parent
,
230 const wxString
& name
,
231 const int *attribList
,
232 const wxPalette
& palette
)
234 // Create the window first: we will either use it as is or use it to query
235 // for multisampling support and recreate it later with another pixel format
236 if ( !CreateWindow(parent
, id
, pos
, size
, style
, name
) )
239 PIXELFORMATDESCRIPTOR pfd
;
240 const int setupVal
= DoSetup(pfd
, attribList
);
241 if ( setupVal
== 0 ) // PixelFormat error
244 if ( setupVal
== -1 ) // FSAA requested
246 // now that we have a valid OpenGL window, query it for FSAA support
249 wxGLContext
ctx(this);
250 ctx
.SetCurrent(*this);
251 pixelFormat
= ::ChoosePixelFormatARB(m_hDC
, attribList
);
254 if ( pixelFormat
> 0 )
256 // from http://msdn.microsoft.com/en-us/library/ms537559(VS.85).aspx:
258 // Setting the pixel format of a window more than once can
259 // lead to significant complications for the Window Manager
260 // and for multithread applications, so it is not allowed. An
261 // application can only set the pixel format of a window one
262 // time. Once a window's pixel format is set, it cannot be
265 // so we need to delete the old window and create the new one
268 ::ReleaseDC(GetHwnd(), m_hDC
);
271 parent
->RemoveChild(this);
272 const HWND hwnd
= GetHwnd();
273 DissociateHandle(); // will do SetHWND(0);
274 ::DestroyWindow(hwnd
);
276 // now recreate with FSAA pixelFormat
277 if ( !CreateWindow(parent
, id
, pos
, size
, style
, name
) )
280 if ( !::SetPixelFormat(m_hDC
, pixelFormat
, &pfd
) )
282 wxLogLastError(wxT("SetPixelFormat"));
289 if ( !SetupPalette(palette
) )
291 #else // !wxUSE_PALETTE
292 wxUnusedVar(palette
);
293 #endif // wxUSE_PALETTE/!wxUSE_PALETTE
298 // ----------------------------------------------------------------------------
300 // ----------------------------------------------------------------------------
302 bool wxGLCanvas::SwapBuffers()
304 if ( !::SwapBuffers(m_hDC
) )
306 wxLogLastError(wxT("SwapBuffers"));
314 // ----------------------------------------------------------------------------
315 // multi sample support
316 // ----------------------------------------------------------------------------
318 // this macro defines a variable of type "name_t" called "name" and initializes
319 // it with the pointer to WGL function "name" (which may be NULL)
320 #define wxDEFINE_WGL_FUNC(name) \
321 name##_t name = (name##_t)wglGetProcAddress(#name)
324 bool wxGLCanvasBase::IsExtensionSupported(const char *extension
)
326 static const char *s_extensionsList
= (char *)wxUIntPtr(-1);
327 if ( s_extensionsList
== (char *)wxUIntPtr(-1) )
329 typedef const char * (WINAPI
*wglGetExtensionsStringARB_t
)(HDC hdc
);
331 wxDEFINE_WGL_FUNC(wglGetExtensionsStringARB
);
332 if ( wglGetExtensionsStringARB
)
334 s_extensionsList
= wglGetExtensionsStringARB(wglGetCurrentDC());
338 typedef const char * (WINAPI
* wglGetExtensionsStringEXT_t
)();
340 wxDEFINE_WGL_FUNC(wglGetExtensionsStringEXT
);
341 if ( wglGetExtensionsStringEXT
)
343 s_extensionsList
= wglGetExtensionsStringEXT();
347 s_extensionsList
= NULL
;
352 return s_extensionsList
&& IsExtensionInList(s_extensionsList
, extension
);
355 // this is a wrapper around wglChoosePixelFormatARB(): returns the pixel format
356 // index matching the given attributes on success or 0 on failure
357 static int ChoosePixelFormatARB(HDC hdc
, const int *attribList
)
359 if ( !wxGLCanvas::IsExtensionSupported("WGL_ARB_multisample") )
362 typedef BOOL (WINAPI
* wglChoosePixelFormatARB_t
)
364 const int *piAttribIList
,
365 const FLOAT
*pfAttribFList
,
371 wxDEFINE_WGL_FUNC(wglChoosePixelFormatARB
);
372 if ( !wglChoosePixelFormatARB
)
373 return 0; // should not occur if extension is supported
375 int iAttributes
[128];
376 int dst
= 0; // index in iAttributes array
378 #define ADD_ATTR(attr, value) \
379 iAttributes[dst++] = attr; iAttributes[dst++] = value
381 ADD_ATTR( WGL_DRAW_TO_WINDOW_ARB
, GL_TRUE
);
382 ADD_ATTR( WGL_SUPPORT_OPENGL_ARB
, GL_TRUE
);
383 ADD_ATTR( WGL_ACCELERATION_ARB
, WGL_FULL_ACCELERATION_ARB
);
387 ADD_ATTR( WGL_COLOR_BITS_ARB
, 24 );
388 ADD_ATTR( WGL_ALPHA_BITS_ARB
, 8 );
389 ADD_ATTR( WGL_DEPTH_BITS_ARB
, 16 );
390 ADD_ATTR( WGL_STENCIL_BITS_ARB
, 0 );
391 ADD_ATTR( WGL_DOUBLE_BUFFER_ARB
, GL_TRUE
);
392 ADD_ATTR( WGL_SAMPLE_BUFFERS_ARB
, GL_TRUE
);
393 ADD_ATTR( WGL_SAMPLES_ARB
, 4 );
395 else // have custom attributes
397 #define ADD_ATTR_VALUE(attr) ADD_ATTR(attr, attribList[src++])
400 while ( attribList
[src
] )
402 switch ( attribList
[src
++] )
405 ADD_ATTR( WGL_COLOR_BITS_ARB
, 24 );
406 ADD_ATTR( WGL_ALPHA_BITS_ARB
, 8 );
409 case WX_GL_BUFFER_SIZE
:
410 ADD_ATTR_VALUE( WGL_COLOR_BITS_ARB
);
414 if ( attribList
[src
] > 0 )
416 ADD_ATTR( WGL_NUMBER_OVERLAYS_ARB
, 1 );
418 else if ( attribList
[src
] <0 )
420 ADD_ATTR( WGL_NUMBER_UNDERLAYS_ARB
, 1 );
424 src
++; // skip the value in any case
427 case WX_GL_DOUBLEBUFFER
:
428 ADD_ATTR( WGL_DOUBLE_BUFFER_ARB
, GL_TRUE
);
432 ADD_ATTR( WGL_STEREO_ARB
, GL_TRUE
);
435 case WX_GL_AUX_BUFFERS
:
436 ADD_ATTR_VALUE( WGL_AUX_BUFFERS_ARB
);
440 ADD_ATTR_VALUE( WGL_RED_BITS_ARB
);
443 case WX_GL_MIN_GREEN
:
444 ADD_ATTR_VALUE( WGL_GREEN_BITS_ARB
);
448 ADD_ATTR_VALUE( WGL_BLUE_BITS_ARB
);
451 case WX_GL_MIN_ALPHA
:
452 ADD_ATTR_VALUE( WGL_ALPHA_BITS_ARB
);
455 case WX_GL_DEPTH_SIZE
:
456 ADD_ATTR_VALUE( WGL_DEPTH_BITS_ARB
);
459 case WX_GL_STENCIL_SIZE
:
460 ADD_ATTR_VALUE( WGL_STENCIL_BITS_ARB
);
463 case WX_GL_MIN_ACCUM_RED
:
464 ADD_ATTR_VALUE( WGL_ACCUM_RED_BITS_ARB
);
467 case WX_GL_MIN_ACCUM_GREEN
:
468 ADD_ATTR_VALUE( WGL_ACCUM_GREEN_BITS_ARB
);
471 case WX_GL_MIN_ACCUM_BLUE
:
472 ADD_ATTR_VALUE( WGL_ACCUM_BLUE_BITS_ARB
);
475 case WX_GL_MIN_ACCUM_ALPHA
:
476 ADD_ATTR_VALUE( WGL_ACCUM_ALPHA_BITS_ARB
);
479 case WX_GL_SAMPLE_BUFFERS
:
480 ADD_ATTR_VALUE( WGL_SAMPLE_BUFFERS_ARB
);
484 ADD_ATTR_VALUE( WGL_SAMPLES_ARB
);
489 #undef ADD_ATTR_VALUE
494 iAttributes
[dst
++] = 0;
499 if ( !wglChoosePixelFormatARB(hdc
, iAttributes
, NULL
, 1, &pf
, &numFormats
) )
501 wxLogLastError(wxT("wglChoosePixelFormatARB"));
505 // Although TRUE is returned if no matching formats are found (see
506 // http://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt), pf is
507 // not initialized in this case so we need to check for numFormats being
508 // not 0 explicitly (however this is not an error so don't call
509 // wxLogLastError() here).
516 // ----------------------------------------------------------------------------
517 // pixel format stuff
518 // ----------------------------------------------------------------------------
520 // returns true if pfd was adjusted accordingly to attributes provided, false
521 // if there is an error with attributes or -1 if the attributes indicate
522 // features not supported by ChoosePixelFormat() at all (currently only multi
525 AdjustPFDForAttributes(PIXELFORMATDESCRIPTOR
& pfd
, const int *attribList
)
530 // remove default attributes
531 pfd
.dwFlags
&= ~PFD_DOUBLEBUFFER
;
532 pfd
.iPixelType
= PFD_TYPE_COLORINDEX
;
534 bool requestFSAA
= false;
535 for ( int arg
= 0; attribList
[arg
]; )
537 switch ( attribList
[arg
++] )
540 pfd
.iPixelType
= PFD_TYPE_RGBA
;
543 case WX_GL_BUFFER_SIZE
:
544 pfd
.cColorBits
= attribList
[arg
++];
548 // this member looks like it may be obsolete
549 if ( attribList
[arg
] > 0 )
550 pfd
.iLayerType
= PFD_OVERLAY_PLANE
;
551 else if ( attribList
[arg
] < 0 )
552 pfd
.iLayerType
= (BYTE
)PFD_UNDERLAY_PLANE
;
554 pfd
.iLayerType
= PFD_MAIN_PLANE
;
558 case WX_GL_DOUBLEBUFFER
:
559 pfd
.dwFlags
|= PFD_DOUBLEBUFFER
;
563 pfd
.dwFlags
|= PFD_STEREO
;
566 case WX_GL_AUX_BUFFERS
:
567 pfd
.cAuxBuffers
= attribList
[arg
++];
571 pfd
.cColorBits
+= (pfd
.cRedBits
= attribList
[arg
++]);
574 case WX_GL_MIN_GREEN
:
575 pfd
.cColorBits
+= (pfd
.cGreenBits
= attribList
[arg
++]);
579 pfd
.cColorBits
+= (pfd
.cBlueBits
= attribList
[arg
++]);
582 case WX_GL_MIN_ALPHA
:
583 // doesn't count in cColorBits
584 pfd
.cAlphaBits
= attribList
[arg
++];
587 case WX_GL_DEPTH_SIZE
:
588 pfd
.cDepthBits
= attribList
[arg
++];
591 case WX_GL_STENCIL_SIZE
:
592 pfd
.cStencilBits
= attribList
[arg
++];
595 case WX_GL_MIN_ACCUM_RED
:
596 pfd
.cAccumBits
+= (pfd
.cAccumRedBits
= attribList
[arg
++]);
599 case WX_GL_MIN_ACCUM_GREEN
:
600 pfd
.cAccumBits
+= (pfd
.cAccumGreenBits
= attribList
[arg
++]);
603 case WX_GL_MIN_ACCUM_BLUE
:
604 pfd
.cAccumBits
+= (pfd
.cAccumBlueBits
= attribList
[arg
++]);
607 case WX_GL_MIN_ACCUM_ALPHA
:
608 pfd
.cAccumBits
+= (pfd
.cAccumAlphaBits
= attribList
[arg
++]);
611 case WX_GL_SAMPLE_BUFFERS
:
613 // There is no support for multisample when using PIXELFORMATDESCRIPTOR
614 requestFSAA
= true; // Remember that multi sample is requested.
615 arg
++; // will call ChoosePixelFormatARB() later
620 return requestFSAA
? -1 : 1;
625 wxGLCanvas::ChooseMatchingPixelFormat(HDC hdc
,
626 const int *attribList
,
627 PIXELFORMATDESCRIPTOR
*ppfd
)
629 // default neutral pixel format
630 PIXELFORMATDESCRIPTOR pfd
=
632 sizeof(PIXELFORMATDESCRIPTOR
), // size
636 PFD_DOUBLEBUFFER
, // use double-buffering by default
637 PFD_TYPE_RGBA
, // default pixel type
638 0, // preferred color depth (don't care)
639 0, 0, 0, 0, 0, 0, // color bits and shift bits (ignored)
640 0, 0, // alpha bits and shift (ignored)
641 0, // accumulation total bits
642 0, 0, 0, 0, // accumulator RGBA bits (not used)
644 0, // no stencil buffer
645 0, // no auxiliary buffers
646 PFD_MAIN_PLANE
, // main layer
648 0, 0, 0, // no layer, visible, damage masks
656 // adjust the PFD using the provided attributes and also check if we can
657 // use PIXELFORMATDESCRIPTOR at all: if multisampling is requested, we
658 // can't as it's not supported by ChoosePixelFormat()
659 switch ( AdjustPFDForAttributes(*ppfd
, attribList
) )
662 return ::ChoosePixelFormat(hdc
, ppfd
);
665 wxFAIL_MSG( "unexpected AdjustPFDForAttributes() return value" );
669 // error in attributes
673 // requestFSAA == true, will continue as normal
674 // in order to query later for a FSAA pixelformat
680 bool wxGLCanvasBase::IsDisplaySupported(const int *attribList
)
682 // We need a device context to test the pixel format, so get one
683 // for the root window.
684 return wxGLCanvas::ChooseMatchingPixelFormat(ScreenHDC(), attribList
) > 0;
687 int wxGLCanvas::DoSetup(PIXELFORMATDESCRIPTOR
&pfd
, const int *attribList
)
689 int pixelFormat
= ChooseMatchingPixelFormat(m_hDC
, attribList
, &pfd
);
691 const bool requestFSAA
= pixelFormat
== -1;
693 pixelFormat
= ::ChoosePixelFormat(m_hDC
, &pfd
);
697 wxLogLastError(wxT("ChoosePixelFormat"));
701 if ( !::SetPixelFormat(m_hDC
, pixelFormat
, &pfd
) )
703 wxLogLastError(wxT("SetPixelFormat"));
707 return requestFSAA
? -1 : 1;
710 // ----------------------------------------------------------------------------
712 // ----------------------------------------------------------------------------
716 bool wxGLCanvas::SetupPalette(const wxPalette
& palette
)
718 const int pixelFormat
= ::GetPixelFormat(m_hDC
);
721 wxLogLastError(wxT("GetPixelFormat"));
725 PIXELFORMATDESCRIPTOR pfd
;
726 if ( !::DescribePixelFormat(m_hDC
, pixelFormat
, sizeof(pfd
), &pfd
) )
728 wxLogLastError(wxT("DescribePixelFormat"));
732 if ( !(pfd
.dwFlags
& PFD_NEED_PALETTE
) )
737 if ( !m_palette
.IsOk() )
739 m_palette
= CreateDefaultPalette();
740 if ( !m_palette
.IsOk() )
744 if ( !::SelectPalette(m_hDC
, GetHpaletteOf(m_palette
), FALSE
) )
746 wxLogLastError(wxT("SelectPalette"));
750 if ( ::RealizePalette(m_hDC
) == GDI_ERROR
)
752 wxLogLastError(wxT("RealizePalette"));
759 wxPalette
wxGLCanvas::CreateDefaultPalette()
761 PIXELFORMATDESCRIPTOR pfd
;
763 int pixelFormat
= GetPixelFormat(m_hDC
);
765 DescribePixelFormat(m_hDC
, pixelFormat
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
767 paletteSize
= 1 << pfd
.cColorBits
;
770 (LOGPALETTE
*) malloc(sizeof(LOGPALETTE
) + paletteSize
* sizeof(PALETTEENTRY
));
771 pPal
->palVersion
= 0x300;
772 pPal
->palNumEntries
= (WORD
)paletteSize
;
774 /* build a simple RGB color palette */
775 int redMask
= (1 << pfd
.cRedBits
) - 1;
776 int greenMask
= (1 << pfd
.cGreenBits
) - 1;
777 int blueMask
= (1 << pfd
.cBlueBits
) - 1;
779 for (int i
=0; i
<paletteSize
; ++i
)
781 pPal
->palPalEntry
[i
].peRed
=
782 (BYTE
)((((i
>> pfd
.cRedShift
) & redMask
) * 255) / redMask
);
783 pPal
->palPalEntry
[i
].peGreen
=
784 (BYTE
)((((i
>> pfd
.cGreenShift
) & greenMask
) * 255) / greenMask
);
785 pPal
->palPalEntry
[i
].peBlue
=
786 (BYTE
)((((i
>> pfd
.cBlueShift
) & blueMask
) * 255) / blueMask
);
787 pPal
->palPalEntry
[i
].peFlags
= 0;
790 HPALETTE hPalette
= CreatePalette(pPal
);
794 palette
.SetHPALETTE((WXHPALETTE
) hPalette
);
799 void wxGLCanvas::OnQueryNewPalette(wxQueryNewPaletteEvent
& event
)
801 /* realize palette if this is the current window */
802 if ( GetPalette()->IsOk() ) {
803 ::UnrealizeObject((HPALETTE
) GetPalette()->GetHPALETTE());
804 ::SelectPalette(GetHDC(), (HPALETTE
) GetPalette()->GetHPALETTE(), FALSE
);
805 ::RealizePalette(GetHDC());
807 event
.SetPaletteRealized(true);
810 event
.SetPaletteRealized(false);
813 void wxGLCanvas::OnPaletteChanged(wxPaletteChangedEvent
& event
)
815 /* realize palette if this is *not* the current window */
817 GetPalette()->IsOk() && (this != event
.GetChangedWindow()) )
819 ::UnrealizeObject((HPALETTE
) GetPalette()->GetHPALETTE());
820 ::SelectPalette(GetHDC(), (HPALETTE
) GetPalette()->GetHPALETTE(), FALSE
);
821 ::RealizePalette(GetHDC());
826 #endif // wxUSE_PALETTE
828 // ----------------------------------------------------------------------------
829 // deprecated wxGLCanvas methods using implicit wxGLContext
830 // ----------------------------------------------------------------------------
832 // deprecated constructors creating an implicit m_glContext
833 #if WXWIN_COMPATIBILITY_2_8
835 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
840 const wxString
& name
,
841 const int *attribList
,
842 const wxPalette
& palette
)
846 if ( Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
) )
847 m_glContext
= new wxGLContext(this);
850 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
851 const wxGLContext
*shared
,
856 const wxString
& name
,
857 const int *attribList
,
858 const wxPalette
& palette
)
862 if ( Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
) )
863 m_glContext
= new wxGLContext(this, shared
);
866 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
867 const wxGLCanvas
*shared
,
872 const wxString
& name
,
873 const int *attribList
,
874 const wxPalette
& palette
)
878 if ( Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
) )
879 m_glContext
= new wxGLContext(this, shared
? shared
->m_glContext
: NULL
);
882 #endif // WXWIN_COMPATIBILITY_2_8
885 // ----------------------------------------------------------------------------
887 // ----------------------------------------------------------------------------
889 bool wxGLApp::InitGLVisual(const int *attribList
)
891 if ( !wxGLCanvas::ChooseMatchingPixelFormat(ScreenHDC(), attribList
) )
893 wxLogError(_("Failed to initialize OpenGL"));
900 #endif // wxUSE_GLCANVAS