#include <Elementary.h>
#include <Evas_GL.h>
#include <stdio.h>
typedef struct _GLData GLData;
struct _GLData
{
GLuint program;
GLuint vtx_shader;
GLuint fgmt_shader;
GLuint vbo;
int initialized : 1;
};
static float red = 1.0;
static GLuint
load_shader( GLData *gld, GLenum type, const char *shader_src )
{
GLuint shader;
GLint compiled;
shader = gl->
glCreateShader(type);
if (shader==0)
return 0;
gl->
glShaderSource(shader, 1, &shader_src, NULL);
gl->
glCompileShader(shader);
gl->
glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
if (!compiled)
{
GLint info_len = 0;
gl->glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &info_len);
if (info_len > 1)
{
char* info_log = malloc(sizeof(char) * info_len);
gl->
glGetShaderInfoLog(shader, info_len, NULL, info_log);
printf("Error compiling shader:\n%s\n======\n%s\n======\n", info_log, shader_src );
free(info_log);
}
gl->
glDeleteShader(shader);
return 0;
}
return shader;
}
static int
init_shaders(GLData *gld)
{
GLbyte vShaderStr[] =
"attribute vec4 vPosition; \n"
"void main() \n"
"{ \n"
" gl_Position = vPosition; \n"
"} \n";
GLbyte fShaderStr[] =
"#ifdef GL_ES \n"
"precision mediump float; \n"
"#endif \n"
"void main() \n"
"{ \n"
" gl_FragColor = vec4 ( 1.0, 0.0, 0.0, 1.0 );\n"
"} \n";
GLint linked;
gld->vtx_shader = load_shader(gld, GL_VERTEX_SHADER, (const char*)vShaderStr);
gld->fgmt_shader = load_shader(gld, GL_FRAGMENT_SHADER, (const char*)fShaderStr);
gld->program = gl->
glCreateProgram( );
if (gld->program==0)
return 0;
gl->
glAttachShader(gld->program, gld->vtx_shader);
gl->glAttachShader(gld->program, gld->fgmt_shader);
gl->
glBindAttribLocation(gld->program, 0,
"vPosition");
gl->
glLinkProgram(gld->program);
gl->
glGetProgramiv(gld->program, GL_LINK_STATUS, &linked);
if (!linked)
{
GLint info_len = 0;
gl->glGetProgramiv(gld->program, GL_INFO_LOG_LENGTH, &info_len);
if (info_len > 1)
{
char* info_log = malloc(sizeof(char) * info_len);
gl->
glGetProgramInfoLog(gld->program, info_len, NULL, info_log);
printf("Error linking program:\n%s\n", info_log);
free(info_log);
}
gl->
glDeleteProgram(gld->program);
return 0;
}
return 1;
}
static void
{
GLfloat vVertices[] = {
0.0f, 0.5f, 0.0f,
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f };
if (!init_shaders(gld))
{
printf("Error Initializing Shaders\n");
return;
}
gl->
glGenBuffers(1, &gld->vbo);
gl->
glBindBuffer(GL_ARRAY_BUFFER, gld->vbo);
gl->
glBufferData(GL_ARRAY_BUFFER, 3 * 3 * 4, vVertices, GL_STATIC_DRAW);
}
static void
{
if (!gld)
{
printf("Unable to get GLData. \n");
return;
}
gl->glDeleteShader(gld->vtx_shader);
gl->glDeleteShader(gld->fgmt_shader);
gl->glDeleteProgram(gld->program);
gl->
glDeleteBuffers(1, &gld->vbo);
free(gld);
}
static void
{
int w, h;
gl->
glViewport(0, 0, w, h);
}
static void
{
if (!gld) return;
int w, h;
gl->glViewport(0, 0, w, h);
gl->
glClearColor(red,0.8,0.3,1);
gl->
glClear(GL_COLOR_BUFFER_BIT);
gl->
glUseProgram(gld->program);
gl->glBindBuffer(GL_ARRAY_BUFFER, gld->vbo);
gl->
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,
0, 0);
gl->
glEnableVertexAttribArray(0);
gl->
glDrawArrays(GL_TRIANGLES, 0, 3);
red -= 0.1;
if (red < 0.0) red = 1.0;
}
_anim(void *data)
{
}
static void
{
}
static void
{
}
EAPI_MAIN int
{
GLData *gld = NULL;
if (!(gld = calloc(1, sizeof(GLData)))) return 1;
elm_glview_init_func_set(gl, _init_gl);
elm_object_text_set(bt, "OK");
return 0;
}
#define EVAS_HINT_EXPAND
Use with evas_object_size_hint_weight_set(), evas_object_size_hint_weight_get(), evas_object_size_hin...
Definition: Evas_Common.h:297
@ EVAS_CALLBACK_DEL
Object Being Deleted (called before Free)
Definition: Evas_Common.h:439
#define EVAS_HINT_FILL
Use with evas_object_size_hint_align_set(), evas_object_size_hint_align_get(), evas_object_size_hint_...
Definition: Evas_Common.h:298
Ecore_Animator * ecore_animator_add(Ecore_Task_Cb func, const void *data)
Adds an animator to call func at every animation tick during main loop execution.
Definition: ecore_anim.c:537
void * ecore_animator_del(Ecore_Animator *animator)
Deletes the specified animator from the animator list.
Definition: ecore_anim.c:846
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition: eina_types.h:539
unsigned char Eina_Bool
Type to mimic a boolean.
Definition: eina_types.h:527
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339
Evas_Object * elm_box_add(Evas_Object *parent)
Add a new box to the parent.
Definition: elm_box.c:363
void elm_box_pack_end(Elm_Box *obj, Efl_Canvas_Object *subobj)
Add an object at the end of the pack list.
Definition: elm_box_eo.legacy.c:57
void elm_object_focus_set(Evas_Object *obj, Eina_Bool focus)
Set/unset focus to a given Elementary object.
Definition: elm_focus_legacy.c:374
#define ELM_MAIN()
macro to be used after the elm_main() function
Definition: elm_general.h:556
Eina_Bool elm_policy_set(unsigned int policy, int value)
Set a new policy's value (for a given policy group/identifier).
Definition: elm_main.c:1380
void elm_exit(void)
Ask to exit Elementary's main loop.
Definition: elm_main.c:1373
void elm_run(void)
Run Elementary's main loop.
Definition: elm_main.c:1357
@ ELM_POLICY_QUIT_LAST_WINDOW_CLOSED
quit when the application's last window is closed
Definition: elm_general.h:248
@ ELM_POLICY_QUIT
under which circumstances the application should quit automatically.
Definition: elm_general.h:227
Evas_Object * elm_glview_add(Evas_Object *parent)
Add a new glview to the parent.
Definition: elm_glview.c:335
void elm_glview_render_func_set(Elm_Glview *obj, Elm_GLView_Func_Cb func)
Set the render function that runs in the main loop.
Definition: elm_glview.c:615
void elm_glview_changed_set(Evas_Object *obj)
Notifies that there has been changes in the GLView.
Definition: elm_glview.c:564
void elm_glview_resize_func_set(Elm_Glview *obj, Elm_GLView_Func_Cb func)
Set the resize function that gets called when resize happens.
Definition: elm_glview.c:606
void elm_glview_size_get(const Elm_Glview *obj, int *w, int *h)
Gets the size of the GLView.
Definition: elm_glview.c:572
Eina_Bool elm_glview_mode_set(Elm_Glview *obj, Elm_GLView_Mode mode)
Set the mode of the GLView.
Definition: elm_glview_eo.legacy.c:15
Evas_GL_API * elm_glview_gl_api_get(const Elm_Glview *obj)
Get the gl api struct for gl rendering.
Definition: elm_glview_eo.legacy.c:21
void elm_glview_del_func_set(Elm_Glview *obj, Elm_GLView_Func_Cb func)
Set the delete function that runs in the main loop.
Definition: elm_glview.c:597
Eina_Bool elm_glview_resize_policy_set(Elm_Glview *obj, Elm_GLView_Resize_Policy policy)
Set the resize policy for the glview object.
Definition: elm_glview_eo.legacy.c:3
Eina_Bool elm_glview_render_policy_set(Elm_Glview *obj, Elm_GLView_Render_Policy policy)
Set the render policy for the glview object.
Definition: elm_glview_eo.legacy.c:9
@ ELM_GLVIEW_ALPHA
Alpha channel enabled rendering mode.
Definition: elm_glview_eo.h:34
@ ELM_GLVIEW_DEPTH
Depth buffer enabled rendering mode (24 bits by default)
Definition: elm_glview_eo.h:36
Evas_Object * elm_win_util_standard_add(const char *name, const char *title)
Adds a window object with standard setup.
Definition: efl_ui_win.c:9582
void elm_win_resize_object_add(Eo *obj, Evas_Object *subobj)
Add subobj as a resize object of window obj.
Definition: efl_ui_win.c:8997
void elm_win_autodel_set(Eo *obj, Eina_Bool autodel)
Set the window's autodel state.
Definition: efl_ui_win.c:6194
Eo Evas
An opaque handle to an Evas canvas.
Definition: Evas_Common.h:163
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
EVAS_API void evas_object_del(Evas_Object *obj)
Marks the given Evas object for deletion (when Evas will free its memory).
Definition: evas_object_main.c:928
EVAS_API void evas_object_event_callback_add(Evas_Object *eo_obj, Evas_Callback_Type type, Evas_Object_Event_Cb func, const void *data)
Add (register) a callback function to a given Evas object event.
Definition: evas_callbacks.c:478
EVAS_API void evas_object_size_hint_weight_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's weight.
Definition: evas_object_main.c:2638
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition: Evas_Common.h:185
EVAS_API void evas_object_size_hint_align_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's alignment.
Definition: evas_object_main.c:2650
EVAS_API void evas_object_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
Changes the size of the given Evas object.
Definition: evas_object_main.c:1236
EVAS_API void evas_object_smart_callback_add(Evas_Object *eo_obj, const char *event, Evas_Smart_Cb func, const void *data)
Add (register) a callback function to the smart event specified by event on the smart object obj.
Definition: evas_object_smart.c:1040
Opaque handle to manage Ecore Animator objects.
The Evas GL API This structure contains function pointers to the available GL functions.
Definition: Evas_GL.h:5130