Previous: Canvas Attributes, Up: Canvas Object [Contents][Index]
Deriving specialized canvases from the general canvas object is possible. See the next subsection for general approaches how this is done. The following routines work for OpenGL (under X) as well as Mesa, a free OpenGL clone.
To add an OpenGL canvas to a form, use the following routine
FL_OBJECT *fl_add_glcanvas(int type, FL_Coord x, FL_Coord y, FL_Coord w, FL_Coord h, const char *label);
where type
is the same as for a normal canvas. A "glcanvas"
created this way will have the following attributes by default
GLX_RGBA, GLX_DEPTH_SIZE: 1, GLX_RED_SIZE: 1, GLX_GREEN_SIZE: 1, GLX_BLUE_SIZE: 1, GLX_DOUBLEBUFFER
The application program can modify these defaults using the following routine (before the creation of glcanvases)
void fl_set_glcanvas_defaults(const int *attributes);
See glXChooseVisual()
for a list of valid attributes.
To get the current defaults use
void fl_get_glcanvas_defaults(int *attributes);
It is also possible to change the attributes on a canvas by canvas basis by utilizing the following routine:
void fl_set_glcanvas_attributes(FL_OBJECT *obj, const int *attributes);
Note that this routine can be used to change a glcanvas attributes on the fly even if the canvas is already visible and active.
To obtain the attributes of a particular canvas, use the following routine
void fl_get_glcanvas_attributes(FL_OBJECT *obj, int attributes[]);
The caller must supply the space for the attribute values.
To obtain the the glx context (for whatever purposes), use
GLXContext fl_get_glcanvas_context(FL_OBJECT *obj);
Note that by default the rendering context created by a glcanvas uses direct rendering (i.e., by-passing the Xserver). To change this default, i.e., to always render through the Xserver, use the following routine:
void fl_set_glcanvas_direct(FL_OBJECT *obj, int yes_no);
with the argument yes_no
set to false (0).
Remember that OpenGL drawing routines always draw into the window the current context is bound to. For application with a single canvas, this is not a problem. In case of multiple canvases, the canvas driver takes care of setting the proper context before invoking the expose handler. In some cases, the application may want to draw into canvases actively. In this case, explicit drawing context switching may be required. To this end, use the following routine
void fl_activate_glcanvas(FL_OBJECT *obj);
before drawing into glcanvas object.
Finally there is a routine that can be used to obtain the XVisual
information that is used to create the context
XVisualInfo *fl_get_glcanvas_xvisualinfo(FL_OBJECT *obj);
See demo program gl.c
for an example use of a glcanvas.
Previous: Canvas Attributes, Up: Canvas Object [Contents][Index]