******************** wx.glcanvas.GLCanvas ******************** Inheritance diagram for `wx.glcanvas.GLCanvas`: | .. inheritance-diagram:: wx.glcanvas.GLCanvas | Description =========== `wx.glcanvas.GLCanvas` is a class for displaying OpenGL graphics. There are two ways to use this class: 1. For the older (before wxPython 2.7.x) and simpler method, create a `wx.glcanvas.GLCanvas` window using one of the three constructors that implicitly create a rendering context, call `SetCurrent <#SetCurrent>`_ to direct normal OpenGL commands to the window, and then call `SwapBuffers <#SwapBuffers>`_ to show the OpenGL buffer on the window. 2. For the newer (wxPython 2.7.x+) method, create a `wx.glcanvas.GLCanvas` window using the constructor that does **not** create an implicit rendering context, (the only one present in this documentation) create an explicit instance of a `wx.glcanvas.GLContext `_ that is initialized with the `wx.glcanvas.GLCanvas` yourself, then use either `SetCurrent <#SetCurrent>`_ with the instance of the `wx.glcanvas.GLContext` or `wx.glcanvas.GLContext.SetCurrent `_ with the instance of the `wx.glcanvas.GLCanvas` to bind the OpenGL state that is represented by the rendering context to the canvas, and then call `SwapBuffers <#SwapBuffers>`_ to swap the buffers of the OpenGL canvas and thus show your current output. 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. To switch on `wx.glcanvas.GLCanvas` support on under Windows, edit setup.h and set ``wx.USE_GLCANVAS`` to 1. You may also need to have to add ``opengl32.lib`` to the list of libraries your program is linked with. On Unix, pass ``--with-opengl`` to configure to compile using OpenGL or Mesa. .. seealso:: `wx.glcanvas.GLContext `_ Constants ^^^^^^^^^ The generic GL implementation doesn't support many of these options, such as stereo, auxiliary buffers, alpha channel, and accum buffer. Other implementations may support them. ========================================= ================================== Constant Description ========================================= ================================== ``wx.glcanvas.WX_GL_RGBA`` Use true colour ``wx.glcanvas.WX_GL_BUFFER_SIZE`` Bits for buffer if not ``wx.glcanvas.WX_GL_RGBA`` ``wx.glcanvas.WX_GL_LEVEL`` 0 for main buffer, >0 for overlay, <0 for underlay ``wx.glcanvas.WX_GL_DOUBLEBUFFER`` Use doublebuffer ``wx.glcanvas.WX_GL_STEREO`` Use stereoscopic display ``wx.glcanvas.WX_GL_AUX_BUFFERS`` Number of auxiliary buffers (not all implementation support this option) ``wx.glcanvas.WX_GL_MIN_RED`` Use red buffer with most bits (> ``MIN_RED`` bits) ``wx.glcanvas.WX_GL_MIN_GREEN`` Use green buffer with most bits (> ``MIN_GREEN`` bits) ``wx.glcanvas.WX_GL_MIN_BLUE`` Use blue buffer with most bits (> ``MIN_BLUE`` bits) ``wx.glcanvas.WX_GL_MIN_ALPHA`` Use alpha buffer with most bits (> ``MIN_ALPHA`` bits) ``wx.glcanvas.WX_GL_DEPTH_SIZE`` Bits for Z-buffer (0, 16, 32) ``wx.glcanvas.WX_GL_STENCIL_SIZE`` Bits for stencil buffer ``wx.glcanvas.WX_GL_MIN_ACCUM_RED`` Use red accum buffer with most bits (> ``MIN_ACCUM_RED`` bits) ``wx.glcanvas.WX_GL_MIN_ACCUM_GREEN`` Use green buffer with most bits (> ``MIN_ACCUM_GREEN`` bits) ``wx.glcanvas.WX_GL_MIN_ACCUM_BLUE`` Use blue buffer with most bits (> ``MIN_ACCUM_BLUE`` bits) ``wx.glcanvas.WX_GL_MIN_ACCUM_ALPHA`` Use blue buffer with most bits (> ``MIN_ACCUM_ALPHA`` bits) ========================================= ================================== Derived From ^^^^^^^^^^^^^ * `wx.Window <../Widgets/wx.Window.html>`_ * `wx.EvtHandler <../Widgets/wx.EvtHandler.html>`_ * `wx.Object <../Widgets/wx.Object.html>`_ Methods Summary ^^^^^^^^^^^^^^^ * `__init__ <#__init__>`_ * `CreateDefaultPalette <#CreateDefaultPalette>`_ * `GetContext <#GetContext>`_ * `GetPalette <#GetPalette>`_ * `SetColour <#SetColour>`_ * `SetCurrent <#SetCurrent>`_ * `SetupPalette <#SetupPalette>`_ * `SetupPixelFormat <#SetupPixelFormat>`_ * `SwapBuffers <#SwapBuffers>`_ Properties Summary ^^^^^^^^^^^^^^^^^^ * `Context <#Context>`_ Class API ========= Methods ^^^^^^^ .. method:: __init__(parent, id=-1, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0, name="glcanvas", attribList=None, palette=wx.NullPalette) Constructor. **Parameters:** * `parent` (`wx.Window <../Widgets/wx.Window.html>`_): Pointer to a parent window. * `id` (int): Window identifier. If -1, will automatically create an identifier. * `pos` (`wx.Point <../Widgets/wx.Point.html>`_): Window position. `wx.DefaultPosition` is (-1, -1) which indicates that wxPython should generate a default position for the window. * `size` (`wx.Size <../Widgets/wx.Size.html>`_): Window size. `wx.DefaultSize` is (-1, -1) which indicates that wxPython 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` (long): Window style. * `name` (string): Window name. * `attribList` (list 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 with constants described in the table above. If a constant should be followed by a value, put it in the next array position. For example, the ``wx.glcanvas.WX_GL_DEPTH_SIZE`` should be followed by the value that indicates the number of bits for the depth buffer, so:: attribList[index]= wx.glcanvas.WX_GL_DEPTH_SIZE attribList[index+1] = 32 and so on. * `palette` (`wx.Palette <../Widgets/wx.Palette.html>`_) | **Returns:** `wx.glcanvas.GLCanvas `_ -------- .. method:: CreateDefaultPalette() `No docstrings available for this method.` -------- .. method:: GetContext() Obtains the context that is associated with this canvas if one was implicitly created (by use of one of the first three constructors). Always returns ``None`` if the canvas was constructed with the fourth constructor. | **Returns:** `wx.glcanvas.GLContext `_ -------- .. method:: GetPalette() `No docstrings available for this method.` -------- .. method:: SetColour(colour) Sets the current colour for this window, using the wxPython colour database to find a named colour. **Parameters:** * `colour` (string) -------- .. method:: SetCurrent(RC) A call to this method makes the OpenGL state that is represented by the OpenGL rendering context `RC` current with this canvas, and if `win` is an object of type `wx.glcanvas.GLCanvas`, the statements:: win.SetCurrent(RC) and:: RC.SetCurrent(win) are equivalent. **Parameters:** * `RC` (`wx.glcanvas.GLContext `_): The rendering context. .. note:: Note that this function may only be called **after** the window has been shown. .. seealso:: `wx.glcanvas.GLContext.SetCurrent `_ -------- .. method:: SetupPalette(palette) | **Parameters:** * `palette` (`wx.Palette <../Widgets/wx.Palette.html>`_) -------- .. method:: SetupPixelFormat(attribList=None) | **Parameters:** * `attribList` (list of integers) -------- .. method:: 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. -------- Properties ^^^^^^^^^^ .. attribute:: Context See `GetContext <#GetContext>`_