wxGLCanvas(3erl)

✨ wxGLCanvas β€” Erlang Module Definition (3erl) ✨

🌸 NAME 🌸

wxGLCanvas β€” functions for the wxGLCanvas class, periodt. That's the name section, and yes, this is the wxGLCanvas(3erl) manual page, bestie.

✨ DESCRIPTION ✨

wxGLCanvas is the class for displaying OpenGL graphics. It is always used in conjunction with wxGLContext, because the context can only be made current (i.e. active for the OpenGL commands) when it is associated to a wxGLCanvas.

More precisely, the whole sequence is: you first need to create a wxGLCanvas window, then create an instance of a wxGLContext that is initialized with this wxGLCanvas. Later, use either setCurrent/2 with the instance of the wxGLContext, or wxGLContext:setCurrent/2 with the instance of the wxGLCanvas (and yeah, that might be not the same canvas as was used for the creation of the context) to bind the OpenGL state that is represented by the rendering context to the canvas. Then finally call swapBuffers/1 to swap the buffers of the OpenGL canvas and thus show your current output. Iconic little pipeline, no cap.

Please note that wxGLContext always uses physical pixels, even on the platforms where wxWindow uses logical pixels, affected by the coordinate scaling, on high DPI displays. Thus, if you want to set the OpenGL view port to the size of entire window, you must multiply the result returned by wxWindow:getClientSize/1 by wxWindow:getContentScaleFactor/1 before passing it to glViewport(). Same considerations apply to other OpenGL functions and other coordinates, notably those retrieved from wxMouseEvent in the event handlers. The high-DPI math is giving main character energy β€” don't skip it.

Notice: 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. Deprecated is deprecated, bestie β€” future-you will thank you.

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 pass them in the constructor using a wxGLAttributes (not implemented in wx) instance. You can still use the way before 3.1.0 (setting up the correct values of the attribList parameter) but it's discouraged. It's giving legacy path β€” technically there, but not the vibe.

Note: On those platforms which use a configure script (e.g. Linux and macOS) 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 for old OpenGL versions) to the list of the libraries your program is linked with.

See: wxGLContext, wxGLAttributes (not implemented in wx), wxGLContextAttrs (not implemented in wx)

This class is derived (and can use functions) from: wxWindow wxEvtHandler

wxWidgets docs: wxGLCanvas


πŸŽ€ DATA TYPES πŸŽ€

wxGLCanvas() = wx:wx_object()

πŸ”₯ EXPORTS πŸ”₯

πŸ’– new(Parent) -> wxGLCanvas() πŸ’–

Types:

Parent = wxWindow:wxWindow()

πŸŽ€ new(Parent, Options :: [Option]) -> wxGLCanvas() πŸŽ€

Types:

Parent = wxWindow:wxWindow()
Option =
    {id, integer()} |
    {attribList, [integer()]} |
    {pos, {X :: integer(), Y :: integer()}} |
    {size, {W :: integer(), H :: integer()}} |
    {style, integer()} |
    {name, unicode:chardata()} |
    {palette, wxPalette:wxPalette()}
  • {id, integer()} β€” the id option, typed as an integer().
  • {attribList, [integer()]} β€” the attribList option, typed as [integer()].
  • {pos, {X :: integer(), Y :: integer()}} β€” the pos option, typed as {X :: integer(), Y :: integer()}.
  • {size, {W :: integer(), H :: integer()}} β€” the size option, typed as {W :: integer(), H :: integer()}.
  • {style, integer()} β€” the style option, typed as an integer().
  • {name, unicode:chardata()} β€” the name option, typed as unicode:chardata().
  • {palette, wxPalette:wxPalette()} β€” the palette option, typed as wxPalette:wxPalette().

This constructor is still available only for compatibility reasons. Read: it's the legacy path, bestie.

Please use the constructor with wxGLAttributes (not implemented in wx) instead.

If attribList is not specified, wxGLAttributes::PlatformDefaults() (not implemented in wx) is used, plus some other attributes (see below).

πŸ’… setCurrent(This, Context) -> boolean() πŸ’…

Types:

This = wxGLCanvas()
Context = wxGLContext:wxGLContext()

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/2 called with this window as parameter.

Note: 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. Timing is everything, fr fr.

Return: false if an error occurred.

πŸ¦‹ createSurface(This) -> boolean() πŸ¦‹

Types:

This = wxGLCanvas()

🌈 isDisplaySupported(AttribList) -> boolean() 🌈

Types:

AttribList = [integer()]

Determines if a canvas having the specified attributes is available.

This only applies for visual attributes, not rendering context attributes. Please, use the new form of this method, using wxGLAttributes (not implemented in wx).

Return: true if attributes are supported.

πŸ”₯ swapBuffers(This) -> boolean() πŸ”₯

Types:

This = wxGLCanvas()

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. Buffer swap slay β€” that's how the pixels make it to the screen.

Return: false if an error occurred.

πŸ’€ destroy(This :: wxGLCanvas()) -> ok πŸ’€

Destroys the object. Bye bye, canvas.


mwah πŸ’‹ footer energy: big shoutout to the wxWidgets team β€” this is the wxGLCanvas(3erl) page, version wx 2.2.2.1, and that's the footer info I've got (no separate date in the source, so no invented date, periodt). 🫢

πŸ“¦ where this page comes from