GLView
This feature is supported in mobile applications only.
The GLView component renders OpenGL in an elementary object, which hides Evas GL complexity. For more information, see OpenGL ES.
Figure: GLView gears example
Figure: GLView hierarchy
Adding a GLView Component
Create a GLView component with the elm_glview_add() function.
Evas_Object *glview, *parent; glview = elm_glview_add(parent);
In this example, the size of the GLView is set to 200x200 pixels.
elm_glview_size_set(glview, 200, 200);
Using the GLView API
You can configure the GLView rendering mode by activating the following rendering modes:
- ELM_GLVIEW_ALPHA: Alpha channel rendering mode
- ELM_GLVIEW_DEPTH: Depth buffer rendering mode
- ELM_GLVIEW_STENCIL: Stencil buffer rendering mode
- ELM_GLVIEW_DIRECT: Direct rendering mode
- ELM_GLVIEW_CLIENT_SIDE_ROTATION: The client handles the GL view rotation if direct rendering is enabled
In the following example, the alpha channel and depth buffer rendering mode are enabled.
elm_glview_mode_set(glview, ELM_GLVIEW_ALPHA | ELM_GLVIEW_DEPTH);
The following example shows how to decide what to do with the GL surface when the GLView component is resized.
elm_glview_resize_policy_set(glview, ELM_GLVIEW_RESIZE_POLICY_RECREATE);
The GL surface is destroyed and recreated to the new size (default function). The resize policy can also be set to ELM_GLVIEW_RESIZE_POLICY_SCALE. In that case, only the image object is scaled, not the underlying GL surface.
The following example shows how to set the GLView rendering policy.
elm_glview_render_policy_set(glview, ELM_GLVIEW_RENDER_POLICY_ALWAYS);
The GLView object is always redrawn during the rendering loop. It can also be set to ELM_GLVIEW_RENDER_POLICY_ON_DEMAND (default function), where the GLView component is redrawn only when it is visible.
Register the callbacks:
elm_glview_init_func_set(glview, _init_gl_cb); elm_glview_del_func_set(glview, _del_gl_cb); elm_glview_resize_func_set(glview, _resize_gl_cb); elm_glview_render_func_set(glview, _draw_gl_cb);
- elm_glview_init_func_set() registers an init callback that is called at the GLView object creation.
- elm_glview_del_func_set() registers a del function that is called when the GLView object is deleted.
- elm_glview_resize_func_set() registers the resize function that is called during the rendering loop when the GLView object is resized.
- elm_glview_render_func_set() registers the render function that is called when the GLView object must be redrawn.
Using GLView Callbacks
The GLView component emits the following signals:
- focused: The Glview component is focused. The event_info parameter points at an object of the type Elm_Focus_Info.
- unfocused: The GLView object is unfocused.
To register a callback:
{ evas_object_smart_callback_add(glview, "focused", focused_cb, data); } // Callback function for the "focused" signal // This callback is called when the GLView is focused void focused_cb(void *data, Evas_Object *obj, void *event_info) { Elm_Focus_Info *fi = event_info; dlog_print(DLOG_INFO, LOG_TAG, "GLView is focused\n"); }