ndktest

view src/app.c @ 0:1310df7cdf25

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 23 Apr 2015 20:54:02 +0300
parents
children
line source
1 #include <stdio.h>
2 #include <sys/time.h>
3 #include <GLES/gl.h>
4 #include "app.h"
6 static unsigned int get_msec(void);
8 int app_init(void)
9 {
10 printf("app_init called\n");
12 return 0;
13 }
15 void app_cleanup(void)
16 {
17 printf("app_cleanup called\n");
18 }
20 static float vert_col[] = { 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1 };
21 static float vert_pos[] = { 0.0, 0.6, 0.0, -0.6, -0.4, 0.0, 0.6, -0.4, 0.0 };
23 void app_display(void)
24 {
25 unsigned int msec = get_msec();
27 glClearColor(0.1, 0.1, 0.1, 1);
28 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
30 glMatrixMode(GL_MODELVIEW);
31 glLoadIdentity();
32 glRotatef(msec / 10.0, 0, 0, 1);
34 glEnableClientState(GL_VERTEX_ARRAY);
35 glEnableClientState(GL_COLOR_ARRAY);
36 glVertexPointer(3, GL_FLOAT, 0, vert_pos);
37 glColorPointer(4, GL_FLOAT, 0, vert_col);
39 glDrawArrays(GL_TRIANGLES, 0, 3);
41 glDisableClientState(GL_VERTEX_ARRAY);
42 glDisableClientState(GL_COLOR_ARRAY);
44 eglSwapBuffers(dpy, surf);
45 }
47 void app_resize(int x, int y)
48 {
49 printf("app_resize: %dx%d\n", x, y);
50 glViewport(0, 0, x, y);
52 float aspect = (float)x / (float)y;
53 glMatrixMode(GL_PROJECTION);
54 glLoadIdentity();
55 glScalef(1, aspect, 1);
56 }
58 void app_touch(int id, int press, int x, int y)
59 {
60 printf("app_touch: %s, id: %d, pos: %d %d\n", press ? "press" : "release", id, x, y);
61 }
63 void app_drag(int id, int x, int y)
64 {
65 printf("app_drag id: %d, pos: %d %d\n", id, x, y);
66 }
68 static unsigned int get_msec(void)
69 {
70 static struct timeval tv0;
71 struct timeval tv;
73 gettimeofday(&tv, 0);
75 if(tv0.tv_sec == 0 && tv0.tv_usec == 0) {
76 tv0 = tv;
77 return 0;
78 }
79 return (tv.tv_sec - tv0.tv_sec) * 1000 + (tv.tv_usec - tv0.tv_usec) / 1000;
80 }