IUP::CanvasGL - [GUI element] 2D canvas based on OpenGL (co-operates with OpenGL module)
Creates an OpenGL canvas (drawing area for OpenGL).
IMPORTANT: For using IUP::CanvasGL you also need to have module OpenGL installed.
Example:
use IUP ':all'; use OpenGL ':all';
Callback handler prototype:
sub action_callback { my ($self, $x, $y) = @_; $self->GLMakeCurrent(); glViewport(0, 0, 300, 300); glClearColor(1.0, 1.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(1.0,0.0,0.0); glBegin(GL_QUADS); glVertex2f( 0.9, 0.9); glVertex2f( 0.9, -0.9); glVertex2f(-0.9, -0.9); glVertex2f(-0.9, 0.9); glEnd(); $self->GLSwapBuffers(); return IUP_DEFAULT; } my $dlg = IUP::Dialog->new( TITLE=>"Example", MINSIZE=>"300x300", child=>IUP::CanvasGL->new( BUFFER=>"DOUBLE", RASTERSIZE=>"300x300", ACTION=>\&action_callback ), ); $dlg->Show(); IUP->MainLoop();
my $canvas_gl = IUP::CanvaGL->new( BUFFER=>"DOUBLE", RASTERSIZE=>"300x300" );
Returns: the identifier of the created element, or undef if an error occurs.
undef
NOTE: You can pass to new() other ATTRIBUTE=>'value' or CALLBACKNAME=>\&func pairs relevant to this element - see IUP::Manual::02_Elements.
new()
ATTRIBUTE=>'value'
CALLBACKNAME=>\&func
For more info about concept of attributes (setting/getting values etc.) see IUP::Manual::03_Attributes. Attributes specific to this element:
The IUP::CanvasGL element handles all attributes defined for a conventional canvas, see IUP::Canvas.
Apart from these attributes, IUP::CanvasGL handles specific attributes used to define the kind of buffer to be instanced. Such attributes are all creation only attributes and must be set before the element is mapped on the native system. After the mapping, specifying these special attributes has no effect.
Indicate the number of bits for representing the color components in the accumulation buffer. Value 0 means the accumulation buffer is not necessary. Default is 0.
Indicates the number of bits for representing each colors alpha component (valid only for RGBA and for hardware that store the alpha component). Default is "0".
Indicates if the buffer will be single "SINGLE" or double "DOUBLE". Default is "SINGLE".
Indicates the number of bits for representing the color indices (valid only for INDEX). The system default is 8 (256-color palette).
Indicates the color model to be adopted: "INDEX" or "RGBA". Default is "RGBA".
(read-only)
Returns "Colormap" in UNIX and "HPALETTE" in Win32, if COLOR=INDEX.
Returns "GLXContext" in UNIX and "HGLRC" in Win32.
Indicates the number of bits for representing the z coordinate in the z-buffer. Value 0 means the z-buffer is not necessary.
If an error is found, returns a string containing a description of the error in English.
Indicate the number of bits for representing each color component (valid only for RGBA). The system default is usually 8 for each component (True Color support).
Action attribute to refresh the internal device context when it is not owned by the window class. The IUP::Canvas of the Win32 driver will always create a window with an owned DC, but GTK in Windows will not.
Indicates the number of bits in the stencil buffer. Value 0 means the stencil buffer is not necessary. Default is 0.
Creates a stereo GL canvas (special glasses are required to visualize it correctly). Possible values: "YES" or "NO". Default: "NO".
Name of another IUP::GLCanvas that will share its display lists and textures. That canvas must be mapped before this canvas.
Returns "XVisualInfo*" in UNIX and "HDC" in Win32.
For more info about concept of callbacks (setting callback handlers etc.) see IUP::Manual::04_Callbacks. Callbacks specific to this element:
The IUP::CanvasGL element understands all callbacks defined for a conventional canvas, see IUP::Canvas section callbacks.
Additionally:
sub resize_cb_handler { my ($self, $width, $heght) = @_; #... }
By default the resize callback sets:
glViewport(0,0,$width,height);
These are auxiliary functions based on the WGL and XGL extensions. Check the respective documentations for more information.
$canvas_gl->GLMakeCurrent();
Activates the given canvas as the current OpenGL context. All subsequent OpenGL commands are directed to such canvas.
$canvas_gl->GLIsCurrent();
Returns a non zero value if the given canvas is the current OpenGL context.
$canvas_gl->GLSwapBuffers();
Makes the BACK buffer visible. This function is necessary when a double buffer is used.
$canvas_gl->GLPalette($index, $r, $g, $b);
Defines a color in the color palette. This function is necessary when INDEX color is used.
$canvas_gl->GLUseFont($first, $count, $list_base);
Creates a bitmap display list from the current FONT attribute. See the documentation of the wglUseFontBitmaps and glXUseXFont functions.
$canvas_gl->GLWait($gl);
If gl is non zero it will call glFinish or glXWaitGL, else will call GdiFlush or glXWaitX.
In Windows XP, if the COMPOSITED attribute on the the main dialog (IUP::Dialog) is enabled then the hardware acceleration will be disabled.
The IUP::CanvasGL works with the GTK base driver in UNIX (X-Windows).
The element IUP::CanvasGL is used in the following sample scripts:
0-basic/glcanvas1.pl - IUP::CanvasGL example
0-basic/glcanvas2.pl - IUP::CanvasGL example
IUP::Canvas
The original doc: iupcanvasgl.html
To install IUP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm IUP
CPAN shell
perl -MCPAN -e shell install IUP
For more information on module installation, please visit the detailed CPAN module installation guide.