]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/glcanvas.tex
rename UpdatePulse() to Pulse() (forgot to commit with the rest of the changes)
[wxWidgets.git] / docs / latex / wx / glcanvas.tex
CommitLineData
8b089c5e
JS
1\section{\class{wxGLCanvas}}\label{wxglcanvas}
2
d0ebe20b 3wxGLCanvas is a class for displaying OpenGL graphics.
8b089c5e 4
b7ea712c
RR
5There are two ways to use this class:
6
7For the older (before wx 2.7.x) and simpler method, create a wxGLCanvas window using one of the three
8constructors that implicitly create a rendering context, call \helpref{wxGLCanvas::SetCurrent}{wxglcanvassetcurrent}
8b089c5e
JS
9to direct normal OpenGL commands to the window, and then call \helpref{wxGLCanvas::SwapBuffers}{wxglcanvasswapbuffers}
10to show the OpenGL buffer on the window.
11
b7ea712c
RR
12For the newer (wx 2.7.x+) method, create a wxGLCanvas window using the constructor that does \emph{not} create an implicit rendering context,
13create an explicit instance of a \helpref{wxGLContext}{wxglcontext} that is initialized with the wxGLCanvas yourself,
418ab1e7 14then use either \helpref{wxGLCanvas::SetCurrent}{wxglcanvassetcurrentrc} with the instance of the \helpref{wxGLContext}{wxglcontext}
b7ea712c
RR
15or \helpref{wxGLContext::SetCurrent}{wxglcontextsetcurrent} with the instance of the \helpref{wxGLCanvas}{wxglcanvas}
16to 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
19To set up the attributes for the canvas (number of bits for the depth buffer,
dd27a3bd
JS
20number of bits for the stencil buffer and so on) you should set up the correct values of
21the {\it attribList} parameter. The values that should be set up and their meanings will be described below.
22
b7ea712c 23To switch on wxGLCanvas support on under Windows, edit setup.h and set
1162d0a2
VZ
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
26Unix, pass {\tt --with-opengl} to configure to compile using OpenGL or Mesa.
8b089c5e
JS
27
28\wxheading{Derived from}
29
8b089c5e
JS
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
40There are no specific window styles for this class.
41
42See also \helpref{window styles overview}{windowstyles}.
43
dd27a3bd
JS
44\wxheading{Constants}
45
46The generic GL implementation doesn't support many of these options, such as stereo, auxiliary buffers,
47alpha 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
f2ac0386 69\wxheading{See also}
38fc80ae
RN
70
71\helpref{wxGLContext}{wxglcontext}
72
8b089c5e
JS
73\latexignore{\rtfignore{\wxheading{Members}}}
74
2d918775 75
8b089c5e
JS
76\membersection{wxGLCanvas::wxGLCanvas}\label{wxglcanvasconstr}
77
b636c599
MR
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"},
8b089c5e
JS
81 \param{int*}{ attribList = 0}, \param{const wxPalette\&}{ palette = wxNullPalette}}
82
b636c599
MR
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"},
8b089c5e
JS
86 \param{int*}{ attribList = 0}, \param{const wxPalette\&}{ palette = wxNullPalette}}
87
b636c599
MR
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"},
8b089c5e
JS
91 \param{int*}{ attribList = 0}, \param{const wxPalette\&}{ palette = wxNullPalette}}
92
418ab1e7 93\func{void}{wxGLCanvas}{\param{wxWindow* }{parent}, \param{wxWindowID}{ id = wxID\_ANY},
b7ea712c
RR
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
99Constructors.
100The first three constructors implicitly create an instance of \helpref{wxGLContext}{wxglcontext}.
101The fourth constructur is identical to the first, except for the fact that it does \emph{not}
102create such an implicit rendering context, which means that you have to create an explicit instance
103of \helpref{wxGLContext}{wxglcontext} yourself (highly recommended for future compatibility with wxWidgets
104and the flexibility of your own program!).
105
106Note that if you used one of the first three constructors, \helpref{wxGLCanvas::GetContext}{wxglcanvasgetcontext}
107returns the pointer to the implicitly created instance, and the \helpref{wxGLCanvas::SetCurrent}{wxglcanvassetcurrent}
108method \emph{without} the parameter should be used.
109If however you used the fourth constructor, \helpref{wxGLCanvas::GetContext}{wxglcanvasgetcontext} always returns NULL
418ab1e7 110and the \helpref{wxGLCanvas::SetCurrent}{wxglcanvassetcurrentrc} method \emph{with} the parameter must be used!
8b089c5e 111
dd27a3bd
JS
112\docparam{parent}{Pointer to a parent window.}
113
b636c599
MR
114\docparam{sharedContext}{Context to share object resources with.}
115
116%TODO document sharedCanvas meaning
01168e95 117
dd27a3bd
JS
118\docparam{id}{Window identifier. If -1, will automatically create an identifier.}
119
fc2171bd 120\docparam{pos}{Window position. wxDefaultPosition is (-1, -1) which indicates that wxWidgets
dd27a3bd
JS
121should generate a default position for the window.}
122
fc2171bd 123\docparam{size}{Window size. wxDefaultSize is (-1, -1) which indicates that wxWidgets should
dd27a3bd
JS
124generate 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.
131This array is zero-terminated: it should be set up with constants described in the table above.
132If a constant should be followed by a value, put it in the next array position.
133For example, the WX\_GL\_DEPTH\_SIZE should be followed by the value that indicates the number of
e119d049 134bits for the depth buffer, so:}
dd27a3bd
JS
135
136\begin{verbatim}
137attribList[index]= WX_GL_DEPTH_SIZE;
138attribList[index+1]=32;
139and so on.
140\end{verbatim}
dd27a3bd
JS
141
142\docparam{palette}{If the window has the palette, it should by pass this value.
143Note: palette and WX\_GL\_RGBA are mutually exclusive.}
144
2d918775 145
01168e95
RN
146\membersection{wxGLCanvas::GetContext}\label{wxglcanvasgetcontext}
147
148\func{wxGLContext*}{GetContext}{\void}
149
b7ea712c
RR
150Obtains the context that is associated with this canvas if one was implicitly created (by use of one of the first three constructors).
151Always returns NULL if the canvas was constructed with the fourth constructor.
01168e95 152
2d918775 153
8b089c5e
JS
154\membersection{wxGLCanvas::SetCurrent}\label{wxglcanvassetcurrent}
155
156\func{void}{SetCurrent}{\void}
157
b7ea712c
RR
158If this canvas was created with one of the first three constructors,
159a call to this method makes the implicit rendering context of this canvas current with this canvas,
160so that subsequent OpenGL calls modify the OpenGL state of the implicit rendering context.
161
162If this canvas was created with the fourth constructor, this method should not be called
163(use the SetCurrent method below with the parameter instead)!
8b089c5e 164
b7ea712c
RR
165Note that this function may only be called \emph{after} the window has been shown.
166
167
418ab1e7 168\membersection{wxGLCanvas::SetCurrent}\label{wxglcanvassetcurrentrc}
b7ea712c
RR
169
170\func{void}{SetCurrent}{ \param{const wxGLContext&}{ RC} }
171
172If this canvas was created with one of the first three constructors,
173this method should not be called (use the SetCurrent above without the parameter instead)!
174
175If this canvas was created with the fourth constructor, a call to this method
176makes the OpenGL state that is represented by the OpenGL rendering context { \it RC } current with this canvas,
177and if { \it win } is an object of type wxGLCanvas, the statements { \it win.SetCurrent(RC); } and { \it RC.SetCurrent(win); } are equivalent,
178see \helpref{wxGLContext::SetCurrent}{wxglcontextsetcurrent}.
179
180Note that this function may only be called \emph{after} the window has been shown.
2d918775
VZ
181
182
8b089c5e
JS
183\membersection{wxGLCanvas::SetColour}\label{wxglcanvassetcolour}
184
185\func{void}{SetColour}{\param{const char*}{ colour}}
186
fc2171bd 187Sets the current colour for this window, using the wxWidgets colour database to find a named colour.
8b089c5e 188
2d918775 189
8b089c5e
JS
190\membersection{wxGLCanvas::SwapBuffers}\label{wxglcanvasswapbuffers}
191
192\func{void}{SwapBuffers}{\void}
193
b7ea712c
RR
194Swaps the double-buffer of this window, making the back-buffer the front-buffer and vice versa,
195so that the output of the previous OpenGL commands is displayed on the window.
b67a86d5 196