wxGLCanvas(3)

πŸ“¦
version 29.0.6 Β· 3 versions
, in ubuntu stonking

✨ wxGLCanvas ✨

okay bestie, so this is the Erlang module definition for wxGLCanvas β€” one of those classic C-ish manual pages but make it cute. it's a class for displaying OpenGL graphics, and it's about to be your whole personality for the next hour. πŸ’…


πŸŽ€ NAME πŸŽ€

wxGLCanvas β€” a class for displaying OpenGL graphics. that's it, that's the girl. πŸ’–


🌸 DESCRIPTION 🌸

okay so the tea: wxGLCanvas is always used together with wxGLContext, no exceptions. like, the context can only be made current (aka active for the OpenGL commands) when it's associated with a wxGLCanvas. they're a package deal, fr fr. 🫢

more precisely β€” and stick with me here, this is the whole flow β€” first you create a wxGLCanvas window, then you create an instance of a wxGLContext that's initialized with this wxGLCanvas. after that, you later use either setCurrent/2 with the instance of the wxGLContext, or wxGLContext:setCurrent/2 with the instance of the wxGLCanvas (which might not be the same one that was used to create the context) β€” all of that just to bind the OpenGL state represented by the rendering context to the canvas. and then, finally, you call swapBuffers/1 to swap the buffers of the OpenGL canvas and thus show your current output. it's giving pipeline. ✨

πŸ‘‘ important note: wxGLContext always uses physical pixels, even on the platforms where wxWindow uses logical pixels (which get affected by coordinate scaling on high DPI displays). so if you want to set the OpenGL viewport to the size of the 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. do not skip this step, i am begging. 😭

also, history lesson: 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 it's deprecated now and will be removed in the future. so please, please update your code to create the rendering contexts explicitly. no more old-head behavior. πŸ’€

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 from before 3.1.0 (setting up the correct values of the attribList parameter) but it's discouraged. like, it's fine, but it's not fine. πŸ™ˆ

🌈 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

this class is derived, and can use functions, from:

  • wxWindow
  • wxEvtHandler

wxWidgets docs: wxGLCanvas


πŸ¦‹ DATA TYPES πŸ¦‹

wxGLCanvas() :: wx:wx_object().

πŸ’– FUNCTIONS πŸ’–

createSurface(This) -> boolean() when This :: wxGLCanvas().

yep, that's the whole thing, bestie. no extra lore. πŸ“

destroy(This :: wxGLCanvas()) -> ok.

Destroys the object. bye girl, it was iconic. πŸ‘‹

isDisplaySupported(AttribList) -> boolean() when AttribList :: [integer()].

Determines if a canvas having the specified attributes is available. vibe check on your attributes. βœ…

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.

new(Parent, [Option]) -> wxGLCanvas() when Parent :: wxWindow:wxWindow(), and Option is one of:

{id, integer()} |
{attribList, [integer()]} |
{pos, {X :: integer(), Y :: integer()}} |
{size, {W :: integer(), H :: integer()}} |
{style, integer()} |
{name, unicode:chardata()} |
{palette, wxPalette:wxPalette()}.

This constructor is still available only for compatibility reasons. it's the legacy era, we don't gatekeep but we do gently judge. 😌

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). defaults always got your back. πŸ’œ

setCurrent(This, Context) -> boolean() when 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. main character energy for real. πŸ‘‘

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. patience, babe.

Return: false if an error occurred.

swapBuffers(This) -> boolean() when 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. you flip it, you show it, you ate. πŸ”₯

Return: false if an error occurred.


that's the whole page, bestie β€” brought to you by Ericsson AB, wx 2.6, dated wxGLCanvas(3). go make something pretty with it, ily, mwah πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from