Version: 2.9.4
Public Member Functions | Static Public Member Functions
wxGLCanvas Class Reference

#include </home/zeitlin/src/wx/github/interface/wx/glcanvas.h>

Inheritance diagram for wxGLCanvas:

Detailed Description

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.

注:
On those platforms which use a configure script (e.g. Linux and Mac OS) OpenGL support is automatically enabled if the relative headers and libraries are found. To switch it on under the other platforms (e.g. Windows), you need to edit the 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.

Library:  wxGL
Category:  OpenGL
参照:
wxGLContext

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.

List of all members.


Constructor & Destructor Documentation

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.

Parameters:
parentPointer to a parent window.
idWindow identifier. If -1, will automatically create an identifier.
posWindow position. wxDefaultPosition is (-1, -1) which indicates that wxWidgets should generate a default position for the window.
sizeWindow 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.
styleWindow style.
nameWindow name.
attribListArray 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
If the attribute list is not specified at all, i.e. if this parameter is NULL, the default attributes including WX_GL_RGBA and WX_GL_DOUBLEBUFFER are used. But notice that if you do specify some attributes you also need to explicitly include these two default attributes in the list if you need them.
palettePalette for indexed colour (i.e. non WX_GL_RGBA) mode. Ignored under most platforms.

Member Function Documentation

static bool wxGLCanvas::IsDisplaySupported ( const int *  attribList) [static]

Determines if a canvas having the specified attributes is available.

Parameters:
attribListSee attribList for wxGLCanvas().
Returns:
true if attributes are supported.
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.

注:
This function may only be called when the window is shown on screen, in particular it can't usually be called from the constructor as the window isn't yet shown at this moment.
Returns:
false if an error occurred.
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.

Returns:
false if an error occurred.
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines