ndktest

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/app.c	Thu Apr 23 20:54:02 2015 +0300
     1.3 @@ -0,0 +1,80 @@
     1.4 +#include <stdio.h>
     1.5 +#include <sys/time.h>
     1.6 +#include <GLES/gl.h>
     1.7 +#include "app.h"
     1.8 +
     1.9 +static unsigned int get_msec(void);
    1.10 +
    1.11 +int app_init(void)
    1.12 +{
    1.13 +	printf("app_init called\n");
    1.14 +
    1.15 +	return 0;
    1.16 +}
    1.17 +
    1.18 +void app_cleanup(void)
    1.19 +{
    1.20 +	printf("app_cleanup called\n");
    1.21 +}
    1.22 +
    1.23 +static float vert_col[] = { 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1 };
    1.24 +static float vert_pos[] = { 0.0, 0.6, 0.0, -0.6, -0.4, 0.0, 0.6, -0.4, 0.0 };
    1.25 +
    1.26 +void app_display(void)
    1.27 +{
    1.28 +	unsigned int msec = get_msec();
    1.29 +
    1.30 +	glClearColor(0.1, 0.1, 0.1, 1);
    1.31 +	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    1.32 +
    1.33 +	glMatrixMode(GL_MODELVIEW);
    1.34 +	glLoadIdentity();
    1.35 +	glRotatef(msec / 10.0, 0, 0, 1);
    1.36 +
    1.37 +	glEnableClientState(GL_VERTEX_ARRAY);
    1.38 +	glEnableClientState(GL_COLOR_ARRAY);
    1.39 +	glVertexPointer(3, GL_FLOAT, 0, vert_pos);
    1.40 +	glColorPointer(4, GL_FLOAT, 0, vert_col);
    1.41 +
    1.42 +	glDrawArrays(GL_TRIANGLES, 0, 3);
    1.43 +
    1.44 +	glDisableClientState(GL_VERTEX_ARRAY);
    1.45 +	glDisableClientState(GL_COLOR_ARRAY);
    1.46 +
    1.47 +	eglSwapBuffers(dpy, surf);
    1.48 +}
    1.49 +
    1.50 +void app_resize(int x, int y)
    1.51 +{
    1.52 +	printf("app_resize: %dx%d\n", x, y);
    1.53 +	glViewport(0, 0, x, y);
    1.54 +
    1.55 +	float aspect = (float)x / (float)y;
    1.56 +	glMatrixMode(GL_PROJECTION);
    1.57 +	glLoadIdentity();
    1.58 +	glScalef(1, aspect, 1);
    1.59 +}
    1.60 +
    1.61 +void app_touch(int id, int press, int x, int y)
    1.62 +{
    1.63 +	printf("app_touch: %s, id: %d, pos: %d %d\n", press ? "press" : "release", id, x, y);
    1.64 +}
    1.65 +
    1.66 +void app_drag(int id, int x, int y)
    1.67 +{
    1.68 +	printf("app_drag id: %d, pos: %d %d\n", id, x, y);
    1.69 +}
    1.70 +
    1.71 +static unsigned int get_msec(void)
    1.72 +{
    1.73 +	static struct timeval tv0;
    1.74 +	struct timeval tv;
    1.75 +
    1.76 +	gettimeofday(&tv, 0);
    1.77 +
    1.78 +	if(tv0.tv_sec == 0 && tv0.tv_usec == 0) {
    1.79 +		tv0 = tv;
    1.80 +		return 0;
    1.81 +	}
    1.82 +	return (tv.tv_sec - tv0.tv_sec) * 1000 + (tv.tv_usec - tv0.tv_usec) / 1000;
    1.83 +}