1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/glcanvas.h
3 // Purpose: wxGLCanvas, for using OpenGL with wxWidgets under Windows
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GLCANVAS_H_
13 #define _WX_GLCANVAS_H_
15 #include "wx/palette.h"
17 #include "wx/msw/wrapwin.h"
21 // ----------------------------------------------------------------------------
22 // wxGLContext: OpenGL rendering context
23 // ----------------------------------------------------------------------------
25 class WXDLLIMPEXP_GL wxGLContext
: public wxGLContextBase
28 wxGLContext(wxGLCanvas
*win
, const wxGLContext
* other
= NULL
);
29 virtual ~wxGLContext();
31 virtual bool SetCurrent(const wxGLCanvas
& win
) const;
33 HGLRC
GetGLRC() const { return m_glContext
; }
39 DECLARE_CLASS(wxGLContext
)
42 // ----------------------------------------------------------------------------
43 // wxGLCanvas: OpenGL output window
44 // ----------------------------------------------------------------------------
46 class WXDLLIMPEXP_GL wxGLCanvas
: public wxGLCanvasBase
49 wxEXPLICIT
// avoid implicitly converting a wxWindow* to wxGLCanvas
50 wxGLCanvas(wxWindow
*parent
,
51 wxWindowID id
= wxID_ANY
,
52 const int *attribList
= NULL
,
53 const wxPoint
& pos
= wxDefaultPosition
,
54 const wxSize
& size
= wxDefaultSize
,
56 const wxString
& name
= wxGLCanvasName
,
57 const wxPalette
& palette
= wxNullPalette
);
59 bool Create(wxWindow
*parent
,
60 wxWindowID id
= wxID_ANY
,
61 const wxPoint
& pos
= wxDefaultPosition
,
62 const wxSize
& size
= wxDefaultSize
,
64 const wxString
& name
= wxGLCanvasName
,
65 const int *attribList
= NULL
,
66 const wxPalette
& palette
= wxNullPalette
);
68 virtual ~wxGLCanvas();
70 // implement wxGLCanvasBase methods
71 virtual bool SwapBuffers();
74 // MSW-specific helpers
75 // --------------------
77 // get the HDC used for OpenGL rendering
78 HDC
GetHDC() const { return m_hDC
; }
80 // try to find pixel format matching the given attributes list for the
81 // specified HDC, return 0 on error, otherwise pfd is filled in with the
82 // information from attribList if non-NULL
83 static int ChooseMatchingPixelFormat(HDC hdc
, const int *attribList
,
84 PIXELFORMATDESCRIPTOR
*pfd
= NULL
);
88 bool SetupPalette(const wxPalette
& palette
);
89 virtual wxPalette
CreateDefaultPalette();
90 void OnQueryNewPalette(wxQueryNewPaletteEvent
& event
);
91 void OnPaletteChanged(wxPaletteChangedEvent
& event
);
92 #endif // wxUSE_PALETTE
94 // deprecated methods using the implicit wxGLContext, associate the context
95 // explicitly with the window instead
96 #if WXWIN_COMPATIBILITY_2_8
98 wxGLCanvas(wxWindow
*parent
,
99 wxWindowID id
= wxID_ANY
,
100 const wxPoint
& pos
= wxDefaultPosition
,
101 const wxSize
& size
= wxDefaultSize
,
103 const wxString
& name
= wxGLCanvasName
,
104 const int *attribList
= NULL
,
105 const wxPalette
& palette
= wxNullPalette
)
109 wxGLCanvas(wxWindow
*parent
,
110 const wxGLContext
*shared
,
111 wxWindowID id
= wxID_ANY
,
112 const wxPoint
& pos
= wxDefaultPosition
,
113 const wxSize
& size
= wxDefaultSize
,
115 const wxString
& name
= wxGLCanvasName
,
116 const int *attribList
= NULL
,
117 const wxPalette
& palette
= wxNullPalette
)
121 wxGLCanvas(wxWindow
*parent
,
122 const wxGLCanvas
*shared
,
123 wxWindowID id
= wxID_ANY
,
124 const wxPoint
& pos
= wxDefaultPosition
,
125 const wxSize
& size
= wxDefaultSize
,
127 const wxString
& name
= wxGLCanvasName
,
128 const int *attribList
= NULL
,
129 const wxPalette
& palette
= wxNullPalette
)
131 #endif // WXWIN_COMPATIBILITY_2_8
134 // common part of all ctors
137 // the real window creation function, Create() may reuse it twice as we may
138 // need to create an OpenGL window to query the available extensions and
139 // then potentially delete and recreate it with another pixel format
140 bool CreateWindow(wxWindow
*parent
,
141 wxWindowID id
= wxID_ANY
,
142 const wxPoint
& pos
= wxDefaultPosition
,
143 const wxSize
& size
= wxDefaultSize
,
145 const wxString
& name
= wxGLCanvasName
);
147 // set up the pixel format using the given attributes and palette
148 int DoSetup(PIXELFORMATDESCRIPTOR
&pfd
, const int *attribList
);
151 // HDC for this window, we keep it all the time
155 DECLARE_EVENT_TABLE()
156 DECLARE_CLASS(wxGLCanvas
)
159 #endif // _WX_GLCANVAS_H_