]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: glcanvas.h | |
e54c96f1 | 3 | // Purpose: interface of wxGLContext |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | /** | |
10 | @class wxGLContext | |
11 | @wxheader{glcanvas.h} | |
7c913512 | 12 | |
23324ae1 FM |
13 | An instance of a wxGLContext represents the state of an OpenGL state machine |
14 | and the connection between OpenGL and the system. | |
7c913512 | 15 | |
23324ae1 FM |
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. | |
7c913512 | 22 | |
23324ae1 FM |
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. | |
7c913512 | 27 | |
23324ae1 FM |
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 | |
33 | analogously.) | |
7c913512 | 34 | |
23324ae1 FM |
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. | |
7c913512 | 37 | |
23324ae1 FM |
38 | @library{wxgl} |
39 | @category{gl} | |
7c913512 | 40 | |
e54c96f1 | 41 | @see wxGLCanvas |
23324ae1 FM |
42 | */ |
43 | class wxGLContext : public wxObject | |
44 | { | |
45 | public: | |
46 | /** | |
47 | Constructor. | |
3c4f71cc | 48 | |
7c913512 | 49 | @param win |
4cc4bfaf FM |
50 | The canvas that is used to initialize this context. This parameter is |
51 | needed only temporarily, | |
52 | and the caller may do anything with it (e.g. destroy the window) after the | |
23324ae1 | 53 | constructor returned. |
4cc4bfaf FM |
54 | It will be possible to bind (make current) this context to any other |
55 | wxGLCanvas that has been created | |
56 | with equivalent attributes as win. | |
7c913512 | 57 | @param other |
4cc4bfaf | 58 | Context to share display lists with or @NULL (the default) for no sharing. |
23324ae1 | 59 | */ |
4cc4bfaf | 60 | wxGLContext(wxGLCanvas* win, const wxGLContext* other = NULL); |
23324ae1 FM |
61 | |
62 | /** | |
63 | Makes the OpenGL state that is represented by this rendering context current | |
64 | with the wxGLCanvas @e win. | |
4cc4bfaf | 65 | Note that @a win can be a different wxGLCanvas window than the one that was |
23324ae1 FM |
66 | passed to the constructor of this rendering context. |
67 | If @e RC is an object of type wxGLContext, the statements @e | |
68 | RC.SetCurrent(win); and @e win.SetCurrent(RC); are equivalent, | |
69 | see wxGLCanvas::SetCurrent. | |
70 | */ | |
71 | void SetCurrent(const wxGLCanvas& win); | |
72 | }; | |
73 | ||
74 | ||
e54c96f1 | 75 | |
23324ae1 FM |
76 | /** |
77 | @class wxGLCanvas | |
78 | @wxheader{glcanvas.h} | |
7c913512 | 79 | |
23324ae1 FM |
80 | wxGLCanvas is a class for displaying OpenGL graphics. It is always used in |
81 | conjunction with wxGLContext as the context can only be | |
82 | be made current (i.e. active for the OpenGL commands) when it is associated to | |
83 | a wxGLCanvas. | |
7c913512 | 84 | |
23324ae1 FM |
85 | More precisely, you first need to create a wxGLCanvas window and then create an |
86 | instance of a wxGLContext that is initialized with this | |
7c913512 FM |
87 | wxGLCanvas and then later use either wxGLCanvas::SetCurrent |
88 | with the instance of the wxGLContext or | |
23324ae1 FM |
89 | wxGLContext::SetCurrent with the instance of |
90 | the wxGLCanvas (which might be not the same as was used | |
91 | for the creation of the context) to bind the OpenGL state that is represented | |
7c913512 | 92 | by the rendering context to the canvas, and then finally call |
23324ae1 FM |
93 | wxGLCanvas::SwapBuffers to swap the buffers of |
94 | the OpenGL canvas and thus show your current output. | |
7c913512 | 95 | |
23324ae1 FM |
96 | Notice that previous versions of wxWidgets used to implicitly create a |
97 | wxGLContext inside wxGLCanvas itself. This is still supported in the current | |
98 | version but is deprecated now and will be removed in the future, please update | |
99 | your code to create the rendering contexts explicitly. | |
7c913512 | 100 | |
23324ae1 FM |
101 | To set up the attributes for the canvas (number of bits for the depth buffer, |
102 | number of bits for the stencil buffer and so on) you should set up the correct | |
103 | values of | |
104 | the @e attribList parameter. The values that should be set up and their | |
105 | meanings will be described below. | |
7c913512 | 106 | |
23324ae1 FM |
107 | Notice that OpenGL is not enabled by default. To switch it on, you need to edit |
108 | setup.h under Windows and set @c wxUSE_GLCANVAS to 1 (you may also need | |
109 | to have to add @c opengl32.lib and @c glu32.lib to the list of libraries | |
110 | your program is linked with). On Unix, pass @c --with-opengl to configure. | |
7c913512 | 111 | |
23324ae1 FM |
112 | @library{wxgl} |
113 | @category{gl} | |
7c913512 | 114 | |
e54c96f1 | 115 | @see wxGLContext |
23324ae1 FM |
116 | */ |
117 | class wxGLCanvas : public wxWindow | |
118 | { | |
119 | public: | |
120 | /** | |
121 | Creates a window with the given parameters. Notice that you need to create and | |
122 | use a wxGLContext to output to this window. | |
7c913512 | 123 | If |
3c4f71cc | 124 | |
23324ae1 | 125 | @param attribList is not specified, double buffered RGBA mode is used. |
3c4f71cc | 126 | |
7c913512 | 127 | parent |
4cc4bfaf | 128 | Pointer to a parent window. |
7c913512 | 129 | @param id |
4cc4bfaf | 130 | Window identifier. If -1, will automatically create an identifier. |
7c913512 | 131 | @param pos |
4cc4bfaf FM |
132 | Window position. wxDefaultPosition is (-1, -1) which indicates that |
133 | wxWidgets | |
134 | should generate a default position for the window. | |
7c913512 | 135 | @param size |
4cc4bfaf FM |
136 | Window size. wxDefaultSize is (-1, -1) which indicates that wxWidgets should |
137 | generate a default size for the window. If no suitable size can be found, | |
138 | the window will be sized to 20x20 pixels so that the window is visible but obviously not correctly sized. | |
7c913512 | 139 | @param style |
4cc4bfaf | 140 | Window style. |
7c913512 | 141 | @param name |
4cc4bfaf | 142 | Window name. |
7c913512 | 143 | @param attribList |
4cc4bfaf | 144 | Array of integers. With this parameter you can set the device context |
23324ae1 | 145 | attributes associated to this window. |
4cc4bfaf FM |
146 | This array is zero-terminated: it should be set up with constants described |
147 | in the table above. | |
148 | If a constant should be followed by a value, put it in the next array | |
149 | position. | |
150 | For example, the WX_GL_DEPTH_SIZE should be followed by the value that | |
23324ae1 | 151 | indicates the number of |
4cc4bfaf | 152 | bits for the depth buffer, so: |
7c913512 | 153 | @param palette |
4cc4bfaf FM |
154 | Palette for indexed colour (i.e. non WX_GL_RGBA) mode. |
155 | Ignored under most platforms. | |
23324ae1 FM |
156 | */ |
157 | wxGLCanvas(wxWindow* parent, wxWindowID id = wxID_ANY, | |
4cc4bfaf | 158 | const int* attribList = NULL, |
23324ae1 FM |
159 | const wxPoint& pos = wxDefaultPosition, |
160 | const wxSize& size = wxDefaultSize, | |
4cc4bfaf FM |
161 | long style = 0, |
162 | const wxString& name = "GLCanvas", | |
23324ae1 FM |
163 | const wxPalette& palette = wxNullPalette); |
164 | ||
165 | /** | |
166 | Determines if a canvas having the specified attributes is available. | |
23324ae1 | 167 | Returns @true if attributes are supported. |
3c4f71cc | 168 | |
7c913512 | 169 | @param attribList |
4cc4bfaf | 170 | See attribList for wxGLCanvas(). |
23324ae1 | 171 | */ |
4cc4bfaf | 172 | static bool IsDisplaySupported(const int* attribList = NULL); |
23324ae1 FM |
173 | |
174 | /** | |
175 | Sets the current colour for this window (using @c glcolor3f()), using the | |
176 | wxWidgets colour database to find a named colour. | |
177 | */ | |
178 | void SetColour(const wxString& colour); | |
179 | ||
180 | /** | |
181 | Makes the OpenGL state that is represented by the OpenGL rendering context | |
4cc4bfaf | 182 | @a context current, i.e. it will be used by all subsequent OpenGL calls. |
7c913512 | 183 | This is equivalent to wxGLContext::SetCurrent |
23324ae1 | 184 | called with this window as parameter. |
23324ae1 FM |
185 | Note that this function may only be called when the window is shown on screen, |
186 | in particular it can't usually be called from the constructor as the window | |
187 | isn't yet shown at this moment. | |
23324ae1 FM |
188 | Returns @false if an error occurred. |
189 | */ | |
190 | bool SetCurrent(const wxGLContext context); | |
191 | ||
192 | /** | |
193 | Swaps the double-buffer of this window, making the back-buffer the front-buffer | |
194 | and vice versa, | |
195 | so that the output of the previous OpenGL commands is displayed on the window. | |
23324ae1 FM |
196 | Returns @false if an error occurred. |
197 | */ | |
198 | bool SwapBuffers(); | |
199 | }; | |
e54c96f1 | 200 |