]>
git.saurik.com Git - wxWidgets.git/blob - interface/glcanvas.h
0c26b513c597cc41abd04071a1458be68741d581
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxGLContext class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
13 An instance of a wxGLContext represents the state of an OpenGL state machine
14 and the connection between OpenGL and the system.
16 The OpenGL state includes everything that can be set with the OpenGL API:
17 colors, rendering variables, display lists, texture objects, etc.
18 Although it is possible to have multiple rendering contexts share display lists
19 in order to save resources,
20 this method is hardly used today any more, because display lists are only a
21 tiny fraction of the overall state.
23 Therefore, one rendering context is usually used with or bound to multiple
24 output windows in turn,
25 so that the application has access to the complete and identical state while
26 rendering into each window.
28 Binding (making current) a rendering context with another instance of a
29 wxGLCanvas however works only
30 if the other wxGLCanvas was created with the same attributes as the wxGLCanvas
31 from which the wxGLContext
32 was initialized. (This applies to sharing display lists among contexts
35 Note that some wxGLContext features are extremely platform-specific - its best
36 to check your native platform's glcanvas header (on windows include/wx/msw/glcanvas.h) to see what features your native platform provides.
44 class wxGLContext
: public wxObject
51 The canvas that is used to initialize this context. This parameter is needed
53 and the caller may do anything with it (e.g. destroy the window) after the
56 It will be possible to bind (make current) this context to any other wxGLCanvas
58 with equivalent attributes as win.
61 Context to share display lists with or @NULL (the default) for no sharing.
63 wxGLContext(wxGLCanvas
* win
, const wxGLContext
* other
=@NULL
);
66 Makes the OpenGL state that is represented by this rendering context current
67 with the wxGLCanvas @e win.
68 Note that @e win can be a different wxGLCanvas window than the one that was
69 passed to the constructor of this rendering context.
70 If @e RC is an object of type wxGLContext, the statements @e
71 RC.SetCurrent(win); and @e win.SetCurrent(RC); are equivalent,
72 see wxGLCanvas::SetCurrent.
74 void SetCurrent(const wxGLCanvas
& win
);
82 wxGLCanvas is a class for displaying OpenGL graphics. It is always used in
83 conjunction with wxGLContext as the context can only be
84 be made current (i.e. active for the OpenGL commands) when it is associated to
87 More precisely, you first need to create a wxGLCanvas window and then create an
88 instance of a wxGLContext that is initialized with this
89 wxGLCanvas and then later use either wxGLCanvas::SetCurrent
90 with the instance of the wxGLContext or
91 wxGLContext::SetCurrent with the instance of
92 the wxGLCanvas (which might be not the same as was used
93 for the creation of the context) to bind the OpenGL state that is represented
94 by the rendering context to the canvas, and then finally call
95 wxGLCanvas::SwapBuffers to swap the buffers of
96 the OpenGL canvas and thus show your current output.
98 Notice that previous versions of wxWidgets used to implicitly create a
99 wxGLContext inside wxGLCanvas itself. This is still supported in the current
100 version but is deprecated now and will be removed in the future, please update
101 your code to create the rendering contexts explicitly.
103 To set up the attributes for the canvas (number of bits for the depth buffer,
104 number of bits for the stencil buffer and so on) you should set up the correct
106 the @e attribList parameter. The values that should be set up and their
107 meanings will be described below.
109 Notice that OpenGL is not enabled by default. To switch it on, you need to edit
110 setup.h under Windows and set @c wxUSE_GLCANVAS to 1 (you may also need
111 to have to add @c opengl32.lib and @c glu32.lib to the list of libraries
112 your program is linked with). On Unix, pass @c --with-opengl to configure.
120 class wxGLCanvas
: public wxWindow
124 Creates a window with the given parameters. Notice that you need to create and
125 use a wxGLContext to output to this window.
129 @param attribList is not specified, double buffered RGBA mode is used.
132 Pointer to a parent window.
135 Window identifier. If -1, will automatically create an identifier.
138 Window position. wxDefaultPosition is (-1, -1) which indicates that wxWidgets
139 should generate a default position for the window.
142 Window size. wxDefaultSize is (-1, -1) which indicates that wxWidgets should
143 generate a default size for the window. If no suitable size can be found, the
144 window will be sized to 20x20 pixels so that the window is visible but obviously not correctly sized.
153 Array of integers. With this parameter you can set the device context
154 attributes associated to this window.
155 This array is zero-terminated: it should be set up with constants described in
157 If a constant should be followed by a value, put it in the next array position.
158 For example, the WX_GL_DEPTH_SIZE should be followed by the value that
159 indicates the number of
160 bits for the depth buffer, so:
163 Palette for indexed colour (i.e. non WX_GL_RGBA) mode.
164 Ignored under most platforms.
166 wxGLCanvas(wxWindow
* parent
, wxWindowID id
= wxID_ANY
,
167 const int* attribList
= @NULL
,
168 const wxPoint
& pos
= wxDefaultPosition
,
169 const wxSize
& size
= wxDefaultSize
,
171 const wxString
& name
="GLCanvas",
172 const wxPalette
& palette
= wxNullPalette
);
175 Determines if a canvas having the specified attributes is available.
177 Returns @true if attributes are supported.
180 See attribList for wxGLCanvas().
182 static bool IsDisplaySupported(const int * attribList
= @NULL
);
185 Sets the current colour for this window (using @c glcolor3f()), using the
186 wxWidgets colour database to find a named colour.
188 void SetColour(const wxString
& colour
);
191 Makes the OpenGL state that is represented by the OpenGL rendering context
192 @e context current, i.e. it will be used by all subsequent OpenGL calls.
194 This is equivalent to wxGLContext::SetCurrent
195 called with this window as parameter.
197 Note that this function may only be called when the window is shown on screen,
198 in particular it can't usually be called from the constructor as the window
199 isn't yet shown at this moment.
201 Returns @false if an error occurred.
203 bool SetCurrent(const wxGLContext context
);
206 Swaps the double-buffer of this window, making the back-buffer the front-buffer
208 so that the output of the previous OpenGL commands is displayed on the window.
210 Returns @false if an error occurred.