]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/glcanvas.tex
Added newline for PDF RTF
[wxWidgets.git] / docs / latex / wx / glcanvas.tex
1 \section{\class{wxGLCanvas}}\label{wxglcanvas}
2
3 wxGLCanvas is a class for displaying OpenGL graphics.
4
5 There are two ways to use this class:
6
7 For the older (before wx 2.7.x) and simpler method, create a wxGLCanvas window using one of the three
8 constructors that implicitly create a rendering context, call \helpref{wxGLCanvas::SetCurrent}{wxglcanvassetcurrent}
9 to direct normal OpenGL commands to the window, and then call \helpref{wxGLCanvas::SwapBuffers}{wxglcanvasswapbuffers}
10 to show the OpenGL buffer on the window.
11
12 For the newer (wx 2.7.x+) method, create a wxGLCanvas window using the constructor that does \emph{not} create an implicit rendering context,
13 create an explicit instance of a \helpref{wxGLContext}{wxglcontext} that is initialized with the wxGLCanvas yourself,
14 then use either \helpref{wxGLCanvas::SetCurrent}{wxglcanvassetcurrentrc} with the instance of the \helpref{wxGLContext}{wxglcontext}
15 or \helpref{wxGLContext::SetCurrent}{wxglcontextsetcurrent} with the instance of the \helpref{wxGLCanvas}{wxglcanvas}
16 to bind the OpenGL state that is represented by the rendering context to the canvas, and then call
17 \helpref{wxGLCanvas::SwapBuffers}{wxglcanvasswapbuffers} to swap the buffers of the OpenGL canvas and thus show your current output.
18
19 To set up the attributes for the canvas (number of bits for the depth buffer,
20 number of bits for the stencil buffer and so on) you should set up the correct values of
21 the {\it attribList} parameter. The values that should be set up and their meanings will be described below.
22
23 To switch on wxGLCanvas support on under Windows, edit setup.h and set
24 {\tt wxUSE\_GLCANVAS} to $1$. You may also need to have to add
25 {\tt opengl32.lib} to the list of libraries your program is linked with. On
26 Unix, pass {\tt --with-opengl} to configure to compile using OpenGL or Mesa.
27
28 \wxheading{Derived from}
29
30 \helpref{wxWindow}{wxwindow}\\
31 \helpref{wxEvtHandler}{wxevthandler}\\
32 \helpref{wxObject}{wxobject}
33
34 \wxheading{Include files}
35
36 <wx/glcanvas.h>
37
38 \wxheading{Window styles}
39
40 There are no specific window styles for this class.
41
42 See also \helpref{window styles overview}{windowstyles}.
43
44 \wxheading{Constants}
45
46 The generic GL implementation doesn't support many of these options, such as stereo, auxiliary buffers,
47 alpha channel, and accum buffer. Other implementations may support them.
48
49 \twocolwidtha{5cm}
50 \begin{twocollist}\itemsep=0pt
51 \twocolitem{\windowstyle{WX\_GL\_RGBA}}{Use true colour}
52 \twocolitem{\windowstyle{WX\_GL\_BUFFER\_SIZE}}{Bits for buffer if not WX\_GL\_RGBA}
53 \twocolitem{\windowstyle{WX\_GL\_LEVEL}}{0 for main buffer, >0 for overlay, <0 for underlay}
54 \twocolitem{\windowstyle{WX\_GL\_DOUBLEBUFFER}}{Use doublebuffer}
55 \twocolitem{\windowstyle{WX\_GL\_STEREO}}{Use stereoscopic display}
56 \twocolitem{\windowstyle{WX\_GL\_AUX\_BUFFERS}}{Number of auxiliary buffers (not all implementation support this option)}
57 \twocolitem{\windowstyle{WX\_GL\_MIN\_RED}}{Use red buffer with most bits (> MIN\_RED bits)}
58 \twocolitem{\windowstyle{WX\_GL\_MIN\_GREEN}}{Use green buffer with most bits (> MIN\_GREEN bits) }
59 \twocolitem{\windowstyle{WX\_GL\_MIN\_BLUE}}{Use blue buffer with most bits (> MIN\_BLUE bits) }
60 \twocolitem{\windowstyle{WX\_GL\_MIN\_ALPHA}}{Use alpha buffer with most bits (> MIN\_ALPHA bits)}
61 \twocolitem{\windowstyle{WX\_GL\_DEPTH\_SIZE}}{Bits for Z-buffer (0,16,32)}
62 \twocolitem{\windowstyle{WX\_GL\_STENCIL\_SIZE}}{Bits for stencil buffer}
63 \twocolitem{\windowstyle{WX\_GL\_MIN\_ACCUM\_RED}}{Use red accum buffer with most bits (> MIN\_ACCUM\_RED bits)}
64 \twocolitem{\windowstyle{WX\_GL\_MIN\_ACCUM\_GREEN}}{Use green buffer with most bits (> MIN\_ACCUM\_GREEN bits)}
65 \twocolitem{\windowstyle{WX\_GL\_MIN\_ACCUM\_BLUE}}{Use blue buffer with most bits (> MIN\_ACCUM\_BLUE bits)}
66 \twocolitem{\windowstyle{WX\_GL\_MIN\_ACCUM\_ALPHA}}{Use blue buffer with most bits (> MIN\_ACCUM\_ALPHA bits)}
67 \end{twocollist}
68
69 \wxheading{See also}
70
71 \helpref{wxGLContext}{wxglcontext}
72
73 \latexignore{\rtfignore{\wxheading{Members}}}
74
75
76 \membersection{wxGLCanvas::wxGLCanvas}\label{wxglcanvasconstr}
77
78 \func{void}{wxGLCanvas}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id = -1},
79 \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},
80 \param{long}{ style=0}, \param{const wxString\& }{name="GLCanvas"},
81 \param{int*}{ attribList = 0}, \param{const wxPalette\&}{ palette = wxNullPalette}}
82
83 \func{void}{wxGLCanvas}{\param{wxWindow* }{parent}, \param{wxGLContext* }{sharedContext}, \param{wxWindowID}{ id = -1},
84 \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},
85 \param{long}{ style=0}, \param{const wxString\& }{name="GLCanvas"},
86 \param{int*}{ attribList = 0}, \param{const wxPalette\&}{ palette = wxNullPalette}}
87
88 \func{void}{wxGLCanvas}{\param{wxWindow* }{parent}, \param{wxGLCanvas* }{sharedCanvas}, \param{wxWindowID}{ id = -1},
89 \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},
90 \param{long}{ style=0}, \param{const wxString\& }{name="GLCanvas"},
91 \param{int*}{ attribList = 0}, \param{const wxPalette\&}{ palette = wxNullPalette}}
92
93 \func{void}{wxGLCanvas}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id = wxID\_ANY},
94 \param{int*}{ attribList = 0},
95 \param{const wxPoint\&}{ pos = wxDefaultPosition}, \param{const wxSize\&}{ size = wxDefaultSize},
96 \param{long}{ style=0}, \param{const wxString\& }{name="GLCanvas"},
97 \param{const wxPalette\&}{ palette = wxNullPalette}}
98
99 Constructors.
100 The first three constructors implicitly create an instance of \helpref{wxGLContext}{wxglcontext}.
101 The fourth constructur is identical to the first, except for the fact that it does \emph{not}
102 create such an implicit rendering context, which means that you have to create an explicit instance
103 of \helpref{wxGLContext}{wxglcontext} yourself (highly recommended for future compatibility with wxWidgets
104 and the flexibility of your own program!).
105
106 Note that if you used one of the first three constructors, \helpref{wxGLCanvas::GetContext}{wxglcanvasgetcontext}
107 returns the pointer to the implicitly created instance, and the \helpref{wxGLCanvas::SetCurrent}{wxglcanvassetcurrent}
108 method \emph{without} the parameter should be used.
109 If however you used the fourth constructor, \helpref{wxGLCanvas::GetContext}{wxglcanvasgetcontext} always returns NULL
110 and the \helpref{wxGLCanvas::SetCurrent}{wxglcanvassetcurrentrc} method \emph{with} the parameter must be used!
111
112 \docparam{parent}{Pointer to a parent window.}
113
114 \docparam{sharedContext}{Context to share object resources with.}
115
116 %TODO document sharedCanvas meaning
117
118 \docparam{id}{Window identifier. If -1, will automatically create an identifier.}
119
120 \docparam{pos}{Window position. wxDefaultPosition is (-1, -1) which indicates that wxWidgets
121 should generate a default position for the window.}
122
123 \docparam{size}{Window size. wxDefaultSize is (-1, -1) which indicates that wxWidgets should
124 generate a default size for the window. If no suitable size can be found, the window will be sized to 20x20 pixels so that the window is visible but obviously not correctly sized.}
125
126 \docparam{style}{Window style.}
127
128 \docparam{name}{Window name.}
129
130 \docparam{attribList}{Array of int. With this parameter you can set the device context attributes associated to this window.
131 This array is zero-terminated: it should be set up with constants described in the table above.
132 If a constant should be followed by a value, put it in the next array position.
133 For example, the WX\_GL\_DEPTH\_SIZE should be followed by the value that indicates the number of
134 bits for the depth buffer, so:}
135
136 \begin{verbatim}
137 attribList[index]= WX_GL_DEPTH_SIZE;
138 attribList[index+1]=32;
139 and so on.
140 \end{verbatim}
141
142 \docparam{palette}{If the window has the palette, it should by pass this value.
143 Note: palette and WX\_GL\_RGBA are mutually exclusive.}
144
145
146 \membersection{wxGLCanvas::GetContext}\label{wxglcanvasgetcontext}
147
148 \func{wxGLContext*}{GetContext}{\void}
149
150 Obtains the context that is associated with this canvas if one was implicitly created (by use of one of the first three constructors).
151 Always returns NULL if the canvas was constructed with the fourth constructor.
152
153
154 \membersection{wxGLCanvas::SetCurrent}\label{wxglcanvassetcurrent}
155
156 \func{void}{SetCurrent}{\void}
157
158 If this canvas was created with one of the first three constructors,
159 a call to this method makes the implicit rendering context of this canvas current with this canvas,
160 so that subsequent OpenGL calls modify the OpenGL state of the implicit rendering context.
161
162 If this canvas was created with the fourth constructor, this method should not be called
163 (use the SetCurrent method below with the parameter instead)!
164
165 Note that this function may only be called \emph{after} the window has been shown.
166
167
168 \membersection{wxGLCanvas::SetCurrent}\label{wxglcanvassetcurrentrc}
169
170 \func{void}{SetCurrent}{ \param{const wxGLContext&}{ RC} }
171
172 If this canvas was created with one of the first three constructors,
173 this method should not be called (use the SetCurrent above without the parameter instead)!
174
175 If this canvas was created with the fourth constructor, a call to this method
176 makes the OpenGL state that is represented by the OpenGL rendering context { \it RC } current with this canvas,
177 and if { \it win } is an object of type wxGLCanvas, the statements { \it win.SetCurrent(RC); } and { \it RC.SetCurrent(win); } are equivalent,
178 see \helpref{wxGLContext::SetCurrent}{wxglcontextsetcurrent}.
179
180 Note that this function may only be called \emph{after} the window has been shown.
181
182
183 \membersection{wxGLCanvas::SetColour}\label{wxglcanvassetcolour}
184
185 \func{void}{SetColour}{\param{const char*}{ colour}}
186
187 Sets the current colour for this window, using the wxWidgets colour database to find a named colour.
188
189
190 \membersection{wxGLCanvas::SwapBuffers}\label{wxglcanvasswapbuffers}
191
192 \func{void}{SwapBuffers}{\void}
193
194 Swaps the double-buffer of this window, making the back-buffer the front-buffer and vice versa,
195 so that the output of the previous OpenGL commands is displayed on the window.
196