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
) )
120 wxLogLastError(_T("wglShareLists"));
124 wxGLContext::~wxGLContext()
126 // note that it's ok to delete the context even if it's the current one
127 wglDeleteContext(m_glContext
);
130 bool wxGLContext::SetCurrent(const wxGLCanvas
& win
) const
132 if ( !wglMakeCurrent(win
.GetHDC(), m_glContext
) )
134 wxLogLastError(_T("wglMakeCurrent"));
140 // ============================================================================
142 // ============================================================================
144 IMPLEMENT_CLASS(wxGLCanvas
, wxWindow
)
146 BEGIN_EVENT_TABLE(wxGLCanvas
, wxWindow
)
147 EVT_PALETTE_CHANGED(wxGLCanvas::OnPaletteChanged
)
148 EVT_QUERY_NEW_PALETTE(wxGLCanvas::OnQueryNewPalette
)
151 // ----------------------------------------------------------------------------
152 // wxGLCanvas construction
153 // ----------------------------------------------------------------------------
155 static int ChoosePixelFormatARB(HDC hdc
, const int *attribList
);
157 void wxGLCanvas::Init()
159 #if WXWIN_COMPATIBILITY_2_8
165 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
167 const int *attribList
,
171 const wxString
& name
,
172 const wxPalette
& palette
)
176 (void)Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
);
179 wxGLCanvas::~wxGLCanvas()
181 ::ReleaseDC(GetHwnd(), m_hDC
);
184 // Replaces wxWindow::Create functionality, since we need to use a different
186 bool wxGLCanvas::CreateWindow(wxWindow
*parent
,
191 const wxString
& name
)
193 wxCHECK_MSG( parent
, false, wxT("can't create wxWindow without parent") );
195 if ( !CreateBase(parent
, id
, pos
, size
, style
, wxDefaultValidator
, name
) )
198 parent
->AddChild(this);
201 A general rule with OpenGL and Win32 is that any window that will have a
202 HGLRC built for it must have two flags: WS_CLIPCHILDREN & WS_CLIPSIBLINGS.
203 You can find references about this within the knowledge base and most OpenGL
204 books that contain the wgl function descriptions.
207 DWORD msflags
= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
208 msflags
|= MSWGetStyle(style
, &exStyle
);
210 if ( !MSWCreate(wxApp::GetRegisteredClassName(_T("wxGLCanvas"), -1, CS_OWNDC
),
211 NULL
, pos
, size
, msflags
, exStyle
) )
214 m_hDC
= ::GetDC(GetHwnd());
221 bool wxGLCanvas::Create(wxWindow
*parent
,
226 const wxString
& name
,
227 const int *attribList
,
228 const wxPalette
& palette
)
230 // Create the window first: we will either use it as is or use it to query
231 // for multisampling support and recreate it later with another pixel format
232 if ( !CreateWindow(parent
, id
, pos
, size
, style
, name
) )
235 PIXELFORMATDESCRIPTOR pfd
;
236 const int setupVal
= DoSetup(pfd
, attribList
);
237 if ( setupVal
== 0 ) // PixelFormat error
240 if ( setupVal
== -1 ) // FSAA requested
242 // now that we have a valid OpenGL window, query it for FSAA support
245 wxGLContext
ctx(this);
246 ctx
.SetCurrent(*this);
247 pixelFormat
= ::ChoosePixelFormatARB(m_hDC
, attribList
);
250 if ( pixelFormat
> 0 )
252 // from http://msdn.microsoft.com/en-us/library/ms537559(VS.85).aspx:
254 // Setting the pixel format of a window more than once can
255 // lead to significant complications for the Window Manager
256 // and for multithread applications, so it is not allowed. An
257 // application can only set the pixel format of a window one
258 // time. Once a window's pixel format is set, it cannot be
261 // so we need to delete the old window and create the new one
264 ::ReleaseDC(GetHwnd(), m_hDC
);
267 parent
->RemoveChild(this);
268 const HWND hwnd
= GetHwnd();
269 DissociateHandle(); // will do SetHWND(0);
270 ::DestroyWindow(hwnd
);
272 // now recreate with FSAA pixelFormat
273 if ( !CreateWindow(parent
, id
, pos
, size
, style
, name
) )
276 if ( !::SetPixelFormat(m_hDC
, pixelFormat
, &pfd
) )
278 wxLogLastError(_T("SetPixelFormat"));
285 if ( !SetupPalette(palette
) )
287 #else // !wxUSE_PALETTE
288 wxUnusedVar(palette
);
289 #endif // wxUSE_PALETTE/!wxUSE_PALETTE
294 // ----------------------------------------------------------------------------
296 // ----------------------------------------------------------------------------
298 bool wxGLCanvas::SwapBuffers()
300 if ( !::SwapBuffers(m_hDC
) )
302 wxLogLastError(_T("SwapBuffers"));
310 // ----------------------------------------------------------------------------
311 // multi sample support
312 // ----------------------------------------------------------------------------
314 // this macro defines a variable of type "name_t" called "name" and initializes
315 // it with the pointer to WGL function "name" (which may be NULL)
316 #define wxDEFINE_WGL_FUNC(name) \
317 name##_t name = (name##_t)wglGetProcAddress(#name)
320 bool wxGLCanvasBase::IsExtensionSupported(const char *extension
)
322 static const char *s_extensionsList
= (char *)wxUIntPtr(-1);
323 if ( s_extensionsList
== (char *)wxUIntPtr(-1) )
325 typedef const char * (WINAPI
*wglGetExtensionsStringARB_t
)(HDC hdc
);
327 wxDEFINE_WGL_FUNC(wglGetExtensionsStringARB
);
328 if ( wglGetExtensionsStringARB
)
330 s_extensionsList
= wglGetExtensionsStringARB(wglGetCurrentDC());
334 typedef const char * (WINAPI
* wglGetExtensionsStringEXT_t
)();
336 wxDEFINE_WGL_FUNC(wglGetExtensionsStringEXT
);
337 if ( wglGetExtensionsStringEXT
)
339 s_extensionsList
= wglGetExtensionsStringEXT();
343 s_extensionsList
= NULL
;
348 return s_extensionsList
&& IsExtensionInList(s_extensionsList
, extension
);
351 // this is a wrapper around wglChoosePixelFormatARB(): returns the pixel format
352 // index matching the given attributes on success or 0 on failure
353 static int ChoosePixelFormatARB(HDC hdc
, const int *attribList
)
355 if ( !wxGLCanvas::IsExtensionSupported("WGL_ARB_multisample") )
358 typedef BOOL (WINAPI
* wglChoosePixelFormatARB_t
)
360 const int *piAttribIList
,
361 const FLOAT
*pfAttribFList
,
367 wxDEFINE_WGL_FUNC(wglChoosePixelFormatARB
);
368 if ( !wglChoosePixelFormatARB
)
369 return 0; // should not occur if extension is supported
371 int iAttributes
[128];
372 int dst
= 0; // index in iAttributes array
374 #define ADD_ATTR(attr, value) \
375 iAttributes[dst++] = attr; iAttributes[dst++] = value
377 ADD_ATTR( WGL_DRAW_TO_WINDOW_ARB
, GL_TRUE
);
378 ADD_ATTR( WGL_SUPPORT_OPENGL_ARB
, GL_TRUE
);
379 ADD_ATTR( WGL_ACCELERATION_ARB
, WGL_FULL_ACCELERATION_ARB
);
383 ADD_ATTR( WGL_COLOR_BITS_ARB
, 24 );
384 ADD_ATTR( WGL_ALPHA_BITS_ARB
, 8 );
385 ADD_ATTR( WGL_DEPTH_BITS_ARB
, 16 );
386 ADD_ATTR( WGL_STENCIL_BITS_ARB
, 0 );
387 ADD_ATTR( WGL_DOUBLE_BUFFER_ARB
, GL_TRUE
);
388 ADD_ATTR( WGL_SAMPLE_BUFFERS_ARB
, GL_TRUE
);
389 ADD_ATTR( WGL_SAMPLES_ARB
, 4 );
391 else // have custom attributes
393 #define ADD_ATTR_VALUE(attr) ADD_ATTR(attr, attribList[src++])
396 while ( attribList
[src
] )
398 switch ( attribList
[src
++] )
401 ADD_ATTR( WGL_COLOR_BITS_ARB
, 24 );
402 ADD_ATTR( WGL_ALPHA_BITS_ARB
, 8 );
405 case WX_GL_BUFFER_SIZE
:
406 ADD_ATTR_VALUE( WGL_COLOR_BITS_ARB
);
410 if ( attribList
[src
] > 0 )
412 ADD_ATTR( WGL_NUMBER_OVERLAYS_ARB
, 1 );
414 else if ( attribList
[src
] <0 )
416 ADD_ATTR( WGL_NUMBER_UNDERLAYS_ARB
, 1 );
420 src
++; // skip the value in any case
423 case WX_GL_DOUBLEBUFFER
:
424 ADD_ATTR( WGL_DOUBLE_BUFFER_ARB
, GL_TRUE
);
428 ADD_ATTR( WGL_STEREO_ARB
, GL_TRUE
);
431 case WX_GL_AUX_BUFFERS
:
432 ADD_ATTR_VALUE( WGL_AUX_BUFFERS_ARB
);
436 ADD_ATTR_VALUE( WGL_RED_BITS_ARB
);
439 case WX_GL_MIN_GREEN
:
440 ADD_ATTR_VALUE( WGL_GREEN_BITS_ARB
);
444 ADD_ATTR_VALUE( WGL_BLUE_BITS_ARB
);
447 case WX_GL_MIN_ALPHA
:
448 ADD_ATTR_VALUE( WGL_ALPHA_BITS_ARB
);
451 case WX_GL_DEPTH_SIZE
:
452 ADD_ATTR_VALUE( WGL_DEPTH_BITS_ARB
);
455 case WX_GL_STENCIL_SIZE
:
456 ADD_ATTR_VALUE( WGL_STENCIL_BITS_ARB
);
459 case WX_GL_MIN_ACCUM_RED
:
460 ADD_ATTR_VALUE( WGL_ACCUM_RED_BITS_ARB
);
463 case WX_GL_MIN_ACCUM_GREEN
:
464 ADD_ATTR_VALUE( WGL_ACCUM_GREEN_BITS_ARB
);
467 case WX_GL_MIN_ACCUM_BLUE
:
468 ADD_ATTR_VALUE( WGL_ACCUM_BLUE_BITS_ARB
);
471 case WX_GL_MIN_ACCUM_ALPHA
:
472 ADD_ATTR_VALUE( WGL_ACCUM_ALPHA_BITS_ARB
);
475 case WX_GL_SAMPLE_BUFFERS
:
476 ADD_ATTR_VALUE( WGL_SAMPLE_BUFFERS_ARB
);
480 ADD_ATTR_VALUE( WGL_SAMPLES_ARB
);
485 #undef ADD_ATTR_VALUE
490 iAttributes
[dst
++] = 0;
494 if ( !wglChoosePixelFormatARB(hdc
, iAttributes
, NULL
, 1, &pf
, &numFormats
) )
496 wxLogLastError(_T("wglChoosePixelFormatARB"));
503 // ----------------------------------------------------------------------------
504 // pixel format stuff
505 // ----------------------------------------------------------------------------
507 // returns true if pfd was adjusted accordingly to attributes provided, false
508 // if there is an error with attributes or -1 if the attributes indicate
509 // features not supported by ChoosePixelFormat() at all (currently only multi
512 AdjustPFDForAttributes(PIXELFORMATDESCRIPTOR
& pfd
, const int *attribList
)
517 // remove default attributes
518 pfd
.dwFlags
&= ~PFD_DOUBLEBUFFER
;
519 pfd
.iPixelType
= PFD_TYPE_COLORINDEX
;
521 bool requestFSAA
= false;
522 for ( int arg
= 0; attribList
[arg
]; )
524 switch ( attribList
[arg
++] )
527 pfd
.iPixelType
= PFD_TYPE_RGBA
;
530 case WX_GL_BUFFER_SIZE
:
531 pfd
.cColorBits
= attribList
[arg
++];
535 // this member looks like it may be obsolete
536 if ( attribList
[arg
] > 0 )
537 pfd
.iLayerType
= PFD_OVERLAY_PLANE
;
538 else if ( attribList
[arg
] < 0 )
539 pfd
.iLayerType
= (BYTE
)PFD_UNDERLAY_PLANE
;
541 pfd
.iLayerType
= PFD_MAIN_PLANE
;
545 case WX_GL_DOUBLEBUFFER
:
546 pfd
.dwFlags
|= PFD_DOUBLEBUFFER
;
550 pfd
.dwFlags
|= PFD_STEREO
;
553 case WX_GL_AUX_BUFFERS
:
554 pfd
.cAuxBuffers
= attribList
[arg
++];
558 pfd
.cColorBits
+= (pfd
.cRedBits
= attribList
[arg
++]);
561 case WX_GL_MIN_GREEN
:
562 pfd
.cColorBits
+= (pfd
.cGreenBits
= attribList
[arg
++]);
566 pfd
.cColorBits
+= (pfd
.cBlueBits
= attribList
[arg
++]);
569 case WX_GL_MIN_ALPHA
:
570 // doesn't count in cColorBits
571 pfd
.cAlphaBits
= attribList
[arg
++];
574 case WX_GL_DEPTH_SIZE
:
575 pfd
.cDepthBits
= attribList
[arg
++];
578 case WX_GL_STENCIL_SIZE
:
579 pfd
.cStencilBits
= attribList
[arg
++];
582 case WX_GL_MIN_ACCUM_RED
:
583 pfd
.cAccumBits
+= (pfd
.cAccumRedBits
= attribList
[arg
++]);
586 case WX_GL_MIN_ACCUM_GREEN
:
587 pfd
.cAccumBits
+= (pfd
.cAccumGreenBits
= attribList
[arg
++]);
590 case WX_GL_MIN_ACCUM_BLUE
:
591 pfd
.cAccumBits
+= (pfd
.cAccumBlueBits
= attribList
[arg
++]);
594 case WX_GL_MIN_ACCUM_ALPHA
:
595 pfd
.cAccumBits
+= (pfd
.cAccumAlphaBits
= attribList
[arg
++]);
598 case WX_GL_SAMPLE_BUFFERS
:
600 // There is no support for multisample when using PIXELFORMATDESCRIPTOR
601 requestFSAA
= true; // Remember that multi sample is requested.
602 arg
++; // will call ChoosePixelFormatARB() later
607 return requestFSAA
? -1 : 1;
612 wxGLCanvas::ChooseMatchingPixelFormat(HDC hdc
,
613 const int *attribList
,
614 PIXELFORMATDESCRIPTOR
*ppfd
)
616 // default neutral pixel format
617 PIXELFORMATDESCRIPTOR pfd
=
619 sizeof(PIXELFORMATDESCRIPTOR
), // size
623 PFD_DOUBLEBUFFER
, // use double-buffering by default
624 PFD_TYPE_RGBA
, // default pixel type
625 0, // preferred color depth (don't care)
626 0, 0, 0, 0, 0, 0, // color bits and shift bits (ignored)
627 0, 0, // alpha bits and shift (ignored)
628 0, // accumulation total bits
629 0, 0, 0, 0, // accumulator RGBA bits (not used)
631 0, // no stencil buffer
632 0, // no auxiliary buffers
633 PFD_MAIN_PLANE
, // main layer
635 0, 0, 0, // no layer, visible, damage masks
643 // adjust the PFD using the provided attributes and also check if we can
644 // use PIXELFORMATDESCRIPTOR at all: if multisampling is requested, we
645 // can't as it's not supported by ChoosePixelFormat()
646 switch ( AdjustPFDForAttributes(*ppfd
, attribList
) )
649 return ::ChoosePixelFormat(hdc
, ppfd
);
652 wxFAIL_MSG( "unexpected AdjustPFDForAttributes() return value" );
656 // error in attributes
660 // requestFSAA == true, will continue as normal
661 // in order to query later for a FSAA pixelformat
667 bool wxGLCanvasBase::IsDisplaySupported(const int *attribList
)
669 // We need a device context to test the pixel format, so get one
670 // for the root window.
671 return wxGLCanvas::ChooseMatchingPixelFormat(ScreenHDC(), attribList
) > 0;
674 int wxGLCanvas::DoSetup(PIXELFORMATDESCRIPTOR
&pfd
, const int *attribList
)
676 int pixelFormat
= ChooseMatchingPixelFormat(m_hDC
, attribList
, &pfd
);
678 const bool requestFSAA
= pixelFormat
== -1;
680 pixelFormat
= ::ChoosePixelFormat(m_hDC
, &pfd
);
684 wxLogLastError(_T("ChoosePixelFormat"));
688 if ( !::SetPixelFormat(m_hDC
, pixelFormat
, &pfd
) )
690 wxLogLastError(_T("SetPixelFormat"));
694 return requestFSAA
? -1 : 1;
697 // ----------------------------------------------------------------------------
699 // ----------------------------------------------------------------------------
703 bool wxGLCanvas::SetupPalette(const wxPalette
& palette
)
705 const int pixelFormat
= ::GetPixelFormat(m_hDC
);
708 wxLogLastError(_T("GetPixelFormat"));
712 PIXELFORMATDESCRIPTOR pfd
;
713 if ( !::DescribePixelFormat(m_hDC
, pixelFormat
, sizeof(pfd
), &pfd
) )
715 wxLogLastError(_T("DescribePixelFormat"));
719 if ( !(pfd
.dwFlags
& PFD_NEED_PALETTE
) )
724 if ( !m_palette
.Ok() )
726 m_palette
= CreateDefaultPalette();
727 if ( !m_palette
.Ok() )
731 if ( !::SelectPalette(m_hDC
, GetHpaletteOf(m_palette
), FALSE
) )
733 wxLogLastError(_T("SelectPalette"));
737 if ( ::RealizePalette(m_hDC
) == GDI_ERROR
)
739 wxLogLastError(_T("RealizePalette"));
746 wxPalette
wxGLCanvas::CreateDefaultPalette()
748 PIXELFORMATDESCRIPTOR pfd
;
750 int pixelFormat
= GetPixelFormat(m_hDC
);
752 DescribePixelFormat(m_hDC
, pixelFormat
, sizeof(PIXELFORMATDESCRIPTOR
), &pfd
);
754 paletteSize
= 1 << pfd
.cColorBits
;
757 (LOGPALETTE
*) malloc(sizeof(LOGPALETTE
) + paletteSize
* sizeof(PALETTEENTRY
));
758 pPal
->palVersion
= 0x300;
759 pPal
->palNumEntries
= (WORD
)paletteSize
;
761 /* build a simple RGB color palette */
762 int redMask
= (1 << pfd
.cRedBits
) - 1;
763 int greenMask
= (1 << pfd
.cGreenBits
) - 1;
764 int blueMask
= (1 << pfd
.cBlueBits
) - 1;
766 for (int i
=0; i
<paletteSize
; ++i
)
768 pPal
->palPalEntry
[i
].peRed
=
769 (BYTE
)((((i
>> pfd
.cRedShift
) & redMask
) * 255) / redMask
);
770 pPal
->palPalEntry
[i
].peGreen
=
771 (BYTE
)((((i
>> pfd
.cGreenShift
) & greenMask
) * 255) / greenMask
);
772 pPal
->palPalEntry
[i
].peBlue
=
773 (BYTE
)((((i
>> pfd
.cBlueShift
) & blueMask
) * 255) / blueMask
);
774 pPal
->palPalEntry
[i
].peFlags
= 0;
777 HPALETTE hPalette
= CreatePalette(pPal
);
781 palette
.SetHPALETTE((WXHPALETTE
) hPalette
);
786 void wxGLCanvas::OnQueryNewPalette(wxQueryNewPaletteEvent
& event
)
788 /* realize palette if this is the current window */
789 if ( GetPalette()->Ok() ) {
790 ::UnrealizeObject((HPALETTE
) GetPalette()->GetHPALETTE());
791 ::SelectPalette(GetHDC(), (HPALETTE
) GetPalette()->GetHPALETTE(), FALSE
);
792 ::RealizePalette(GetHDC());
794 event
.SetPaletteRealized(true);
797 event
.SetPaletteRealized(false);
800 void wxGLCanvas::OnPaletteChanged(wxPaletteChangedEvent
& event
)
802 /* realize palette if this is *not* the current window */
804 GetPalette()->Ok() && (this != event
.GetChangedWindow()) )
806 ::UnrealizeObject((HPALETTE
) GetPalette()->GetHPALETTE());
807 ::SelectPalette(GetHDC(), (HPALETTE
) GetPalette()->GetHPALETTE(), FALSE
);
808 ::RealizePalette(GetHDC());
813 #endif // wxUSE_PALETTE
815 // ----------------------------------------------------------------------------
816 // deprecated wxGLCanvas methods using implicit wxGLContext
817 // ----------------------------------------------------------------------------
819 // deprecated constructors creating an implicit m_glContext
820 #if WXWIN_COMPATIBILITY_2_8
822 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
827 const wxString
& name
,
828 const int *attribList
,
829 const wxPalette
& palette
)
833 if ( Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
) )
834 m_glContext
= new wxGLContext(this);
837 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
838 const wxGLContext
*shared
,
843 const wxString
& name
,
844 const int *attribList
,
845 const wxPalette
& palette
)
849 if ( Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
) )
850 m_glContext
= new wxGLContext(this, shared
);
853 wxGLCanvas::wxGLCanvas(wxWindow
*parent
,
854 const wxGLCanvas
*shared
,
859 const wxString
& name
,
860 const int *attribList
,
861 const wxPalette
& palette
)
865 if ( Create(parent
, id
, pos
, size
, style
, name
, attribList
, palette
) )
866 m_glContext
= new wxGLContext(this, shared
? shared
->m_glContext
: NULL
);
869 #endif // WXWIN_COMPATIBILITY_2_8
872 // ----------------------------------------------------------------------------
874 // ----------------------------------------------------------------------------
876 bool wxGLApp::InitGLVisual(const int *attribList
)
878 if ( !wxGLCanvas::ChooseMatchingPixelFormat(ScreenHDC(), attribList
) )
880 wxLogError(_("Failed to initialize OpenGL"));
887 #endif // wxUSE_GLCANVAS