]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/glcanvas.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxGLContext and wxGLCanvas
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
12 An instance of a wxGLContext represents the state of an OpenGL state
13 machine and the connection between OpenGL and the system.
15 The OpenGL state includes everything that can be set with the OpenGL API:
16 colors, rendering variables, display lists, texture objects, etc. Although
17 it is possible to have multiple rendering contexts share display lists in
18 order to save resources, this method is hardly used today any more, because
19 display lists are only a tiny fraction of the overall state.
21 Therefore, one rendering context is usually used with or bound to multiple
22 output windows in turn, so that the application has access to the complete
23 and identical state while rendering into each window.
25 Binding (making current) a rendering context with another instance of a
26 wxGLCanvas however works only if the other wxGLCanvas was created with the
27 same attributes as the wxGLCanvas from which the wxGLContext was
28 initialized. (This applies to sharing display lists among contexts
31 Note that some wxGLContext features are extremely platform-specific - its
32 best to check your native platform's glcanvas header (on windows
33 include/wx/msw/glcanvas.h) to see what features your native platform
41 class wxGLContext
: public wxObject
48 The canvas that is used to initialize this context. This parameter
49 is needed only temporarily, and the caller may do anything with it
50 (e.g. destroy the window) after the constructor returned. @n
51 It will be possible to bind (make current) this context to any
52 other wxGLCanvas that has been created with equivalent attributes
55 Context to share display lists with or @NULL (the default) for no
58 wxGLContext(wxGLCanvas
* win
, const wxGLContext
* other
= NULL
);
61 Makes the OpenGL state that is represented by this rendering context
62 current with the wxGLCanvas @e win.
64 @note @a win can be a different wxGLCanvas window than the one that was
65 passed to the constructor of this rendering context. If @e RC is
66 an object of type wxGLContext, the statements
67 @e "RC.SetCurrent(win);" and @e "win.SetCurrent(RC);" are
68 equivalent, see wxGLCanvas::SetCurrent().
70 virtual bool SetCurrent(const wxGLCanvas
& win
) const;
76 Constants for use with wxGLCanvas.
78 @note Not all implementations support options such as stereo, auxiliary
79 buffers, alpha channel, and accumulator buffer, use
80 wxGLCanvas::IsDisplaySupported() to check for individual attributes
85 /// Use true color (the default if no attributes at all are specified);
86 /// do not use a palette.
89 /// Specifies the number of bits for buffer if not WX_GL_RGBA.
92 /// Must be followed by 0 for main buffer, >0 for overlay, <0 for underlay.
95 /// Use double buffering if present (on if no attributes specified).
98 /// Use stereoscopic display.
101 /// Specifies number of auxiliary buffers.
104 /// Use red buffer with most bits (> MIN_RED bits)
107 /// Use green buffer with most bits (> MIN_GREEN bits)
110 /// Use blue buffer with most bits (> MIN_BLUE bits)
113 /// Use alpha buffer with most bits (> MIN_ALPHA bits)
116 /// Specifies number of bits for Z-buffer (typically 0, 16 or 32).
119 /// Specifies number of bits for stencil buffer.
122 /// Specifies minimal number of red accumulator bits.
125 /// Specifies minimal number of green accumulator bits.
126 WX_GL_MIN_ACCUM_GREEN
,
128 /// Specifies minimal number of blue accumulator bits.
129 WX_GL_MIN_ACCUM_BLUE
,
131 /// Specifies minimal number of alpha accumulator bits.
132 WX_GL_MIN_ACCUM_ALPHA
,
134 /// 1 for multisampling support (antialiasing)
135 WX_GL_SAMPLE_BUFFERS
,
137 /// 4 for 2x2 antialising supersampling on most graphics cards
145 wxGLCanvas is a class for displaying OpenGL graphics. It is always used in
146 conjunction with wxGLContext as the context can only be made current (i.e.
147 active for the OpenGL commands) when it is associated to a wxGLCanvas.
149 More precisely, you first need to create a wxGLCanvas window and then
150 create an instance of a wxGLContext that is initialized with this
151 wxGLCanvas and then later use either SetCurrent() with the instance of the
152 wxGLContext or wxGLContext::SetCurrent() with the instance of the
153 wxGLCanvas (which might be not the same as was used for the creation of the
154 context) to bind the OpenGL state that is represented by the rendering
155 context to the canvas, and then finally call SwapBuffers() to swap the
156 buffers of the OpenGL canvas and thus show your current output.
158 Notice that versions of wxWidgets previous to 2.9 used to implicitly create a
159 wxGLContext inside wxGLCanvas itself. This is still supported in the
160 current version but is deprecated now and will be removed in the future,
161 please update your code to create the rendering contexts explicitly.
163 To set up the attributes for the canvas (number of bits for the depth
164 buffer, number of bits for the stencil buffer and so on) you should set up
165 the correct values of the @e attribList parameter. The values that should
166 be set up and their meanings will be described below.
169 On those platforms which use a configure script (e.g. Linux and Mac OS)
170 OpenGL support is automatically enabled if the relative headers and
172 To switch it on under the other platforms (e.g. Windows), you need to edit
173 the @c setup.h file and set @c wxUSE_GLCANVAS to @c 1 and then also pass
174 @c USE_OPENGL=1 to the make utility. You may also need to add @c opengl32.lib
175 and @c glu32.lib to the list of the libraries your program is linked with.
182 class wxGLCanvas
: public wxWindow
186 Creates a window with the given parameters. Notice that you need to
187 create and use a wxGLContext to output to this window.
189 If @a attribList is not specified, double buffered RGBA mode is used.
192 Pointer to a parent window.
194 Window identifier. If -1, will automatically create an identifier.
196 Window position. wxDefaultPosition is (-1, -1) which indicates that
197 wxWidgets should generate a default position for the window.
199 Window size. wxDefaultSize is (-1, -1) which indicates that
200 wxWidgets should generate a default size for the window. If no
201 suitable size can be found, the window will be sized to 20x20
202 pixels so that the window is visible but obviously not correctly
209 Array of integers. With this parameter you can set the device
210 context attributes associated to this window. This array is
211 zero-terminated: it should be set up using @ref wxGL_FLAGS
212 constants. If a constant should be followed by a value, put it in
213 the next array position. For example, WX_GL_DEPTH_SIZE should be
214 followed by the value that indicates the number of bits for the
217 attribList[n++] = WX_GL_DEPTH_SIZE;
218 attribList[n++] = 32;
219 attribList[n] = 0; // terminate the list
221 If the attribute list is not specified at all, i.e. if this
222 parameter is @NULL, the default attributes including WX_GL_RGBA and
223 WX_GL_DOUBLEBUFFER are used. But notice that if you do specify some
224 attributes you also need to explicitly include these two default
225 attributes in the list if you need them.
227 Palette for indexed colour (i.e. non WX_GL_RGBA) mode. Ignored
228 under most platforms.
230 wxGLCanvas(wxWindow
* parent
, wxWindowID id
= wxID_ANY
,
231 const int* attribList
= NULL
,
232 const wxPoint
& pos
= wxDefaultPosition
,
233 const wxSize
& size
= wxDefaultSize
,
235 const wxString
& name
= "GLCanvas",
236 const wxPalette
& palette
= wxNullPalette
);
239 Determines if a canvas having the specified attributes is available.
242 See @a attribList for wxGLCanvas().
244 @return @true if attributes are supported.
246 static bool IsDisplaySupported(const int* attribList
= NULL
);
249 Returns true if the extension with given name is supported
251 Notice that while this function is implemented for all of GLX, WGL and
252 AGL the extensions names are usually not the same for different
253 platforms and so the code using it still usually uses conditional
256 static bool IsExtensionSupported(const char *extension
);
259 Sets the current colour for this window (using @c glcolor3f()), using
260 the wxWidgets colour database to find a named colour.
262 bool SetColour(const wxString
& colour
);
265 Makes the OpenGL state that is represented by the OpenGL rendering
266 context @a context current, i.e. it will be used by all subsequent
269 This is equivalent to wxGLContext::SetCurrent() called with this window
272 @note This function may only be called when the window is shown on
273 screen, in particular it can't usually be called from the
274 constructor as the window isn't yet shown at this moment.
276 @return @false if an error occurred.
278 bool SetCurrent(const wxGLContext
& context
) const;
281 Swaps the double-buffer of this window, making the back-buffer the
282 front-buffer and vice versa, so that the output of the previous OpenGL
283 commands is displayed on the window.
285 @return @false if an error occurred.
287 virtual bool SwapBuffers();