#include </home/zeitlin/src/wx/github/interface/wx/glcanvas.h>
wxGLCanvas is a class for displaying OpenGL graphics.
It is always used in conjunction with wxGLContext as the context can only be made current (i.e. active for the OpenGL commands) when it is associated to a wxGLCanvas.
More precisely, you first need to create a wxGLCanvas window and then create an instance of a wxGLContext that is initialized with this wxGLCanvas and then later use either SetCurrent() with the instance of the wxGLContext or wxGLContext::SetCurrent() with the instance of the wxGLCanvas (which might be not the same as was used for the creation of the context) to bind the OpenGL state that is represented by the rendering context to the canvas, and then finally call SwapBuffers() to swap the buffers of the OpenGL canvas and thus show your current output.
Notice that versions of wxWidgets previous to 2.9 used to implicitly create a wxGLContext inside wxGLCanvas itself. This is still supported in the current version but is deprecated now and will be removed in the future, please update your code to create the rendering contexts explicitly.
To set up the attributes for the canvas (number of bits for the depth buffer, number of bits for the stencil buffer and so on) you should set up the correct values of the attribList parameter. The values that should be set up and their meanings will be described below.
setup.h
file and set wxUSE_GLCANVAS
to 1
and then also pass USE_OPENGL=1
to the make utility. You may also need to add opengl32.lib
and glu32.lib
to the list of the libraries your program is linked with.Public Member Functions | |
wxGLCanvas (wxWindow *parent, wxWindowID id=wxID_ANY, const int *attribList=NULL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name="GLCanvas", const wxPalette &palette=wxNullPalette) | |
Creates a window with the given parameters. | |
bool | SetColour (const wxString &colour) |
Sets the current colour for this window (using glcolor3f() ), using the wxWidgets colour database to find a named colour. | |
bool | SetCurrent (const wxGLContext &context) const |
Makes the OpenGL state that is represented by the OpenGL rendering context context current, i.e. | |
virtual bool | SwapBuffers () |
Swaps the double-buffer of this window, making the back-buffer the front-buffer and vice versa, so that the output of the previous OpenGL commands is displayed on the window. | |
Static Public Member Functions | |
static bool | IsDisplaySupported (const int *attribList) |
Determines if a canvas having the specified attributes is available. | |
static bool | IsExtensionSupported (const char *extension) |
Returns true if the extension with given name is supported. |
wxGLCanvas::wxGLCanvas | ( | wxWindow * | parent, |
wxWindowID | id = wxID_ANY , |
||
const int * | attribList = NULL , |
||
const wxPoint & | pos = wxDefaultPosition , |
||
const wxSize & | size = wxDefaultSize , |
||
long | style = 0 , |
||
const wxString & | name = "GLCanvas" , |
||
const wxPalette & | palette = wxNullPalette |
||
) |
Creates a window with the given parameters.
Notice that you need to create and use a wxGLContext to output to this window.
If attribList is not specified, double buffered RGBA mode is used.
parent | Pointer to a parent window. |
id | Window identifier. If -1, will automatically create an identifier. |
pos | Window position. wxDefaultPosition is (-1, -1) which indicates that wxWidgets should generate a default position for the window. |
size | Window size. wxDefaultSize is (-1, -1) which indicates that wxWidgets should 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. |
style | Window style. |
name | Window name. |
attribList | Array of integers. With this parameter you can set the device context attributes associated to this window. This array is zero-terminated: it should be set up using wxGL_FLAGS constants. If a constant should be followed by a value, put it in the next array position. For example, WX_GL_DEPTH_SIZE should be followed by the value that indicates the number of bits for the depth buffer, e.g.: attribList[n++] = WX_GL_DEPTH_SIZE; attribList[n++] = 32; attribList[n] = 0; // terminate the list |
palette | Palette for indexed colour (i.e. non WX_GL_RGBA) mode. Ignored under most platforms. |
static bool wxGLCanvas::IsDisplaySupported | ( | const int * | attribList | ) | [static] |
Determines if a canvas having the specified attributes is available.
attribList | See attribList for wxGLCanvas(). |
static bool wxGLCanvas::IsExtensionSupported | ( | const char * | extension | ) | [static] |
Returns true if the extension with given name is supported.
Notice that while this function is implemented for all of GLX, WGL and AGL the extensions names are usually not the same for different platforms and so the code using it still usually uses conditional compilation.
bool wxGLCanvas::SetColour | ( | const wxString & | colour | ) |
Sets the current colour for this window (using glcolor3f()
), using the wxWidgets colour database to find a named colour.
bool wxGLCanvas::SetCurrent | ( | const wxGLContext & | context | ) | const |
Makes the OpenGL state that is represented by the OpenGL rendering context context current, i.e.
it will be used by all subsequent OpenGL calls.
This is equivalent to wxGLContext::SetCurrent() called with this window as parameter.
virtual bool wxGLCanvas::SwapBuffers | ( | ) | [virtual] |
Swaps the double-buffer of this window, making the back-buffer the front-buffer and vice versa, so that the output of the previous OpenGL commands is displayed on the window.