1#include <stdio.h>
2#include <VG/openvg.h>
3#include <EGL/egl.h>
4
5#include "lion-render.h"
6#include "eglut.h"
7
8static VGint width, height;
9struct lion *lion = 0;
10VGfloat angle = 0;
11
12static void
13draw(void)
14{
15   static double t0 = -1.0;
16   static int num_frames;
17   double now;
18
19   vgClear(0, 0, width, height);
20
21   vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
22   vgLoadIdentity();
23   vgTranslate(width/2, height/2);
24   vgRotate(angle);
25   vgTranslate(-width/2, -height/2);
26
27   lion_render(lion);
28   vgFlush();
29   num_frames++;
30
31   if (t0 < 0.0) {
32      t0 = eglutGet(EGLUT_ELAPSED_TIME) / 1000.0;
33      num_frames = 0;
34   }
35
36   now = eglutGet(EGLUT_ELAPSED_TIME) / 1000.0;
37   if (now - t0 > 5.0) {
38      /* just a rough estimate */
39      printf("%d frames in %3.1f seconds = %6.3f FPS\n",
40            num_frames, now - t0, num_frames / (now - t0));
41
42      t0 = now;
43      num_frames = 0;
44   }
45
46   ++angle;
47   eglutPostRedisplay();
48}
49
50
51/* new window size or exposure */
52static void
53reshape(int w, int h)
54{
55   width  = w;
56   height = h;
57}
58
59
60static void
61init(void)
62{
63   float clear_color[4] = {1.0, 1.0, 1.0, 1.0};
64   vgSetfv(VG_CLEAR_COLOR, 4, clear_color);
65
66   lion = lion_create();
67}
68
69
70int
71main(int argc, char *argv[])
72{
73   eglutInitWindowSize(350, 450);
74   eglutInitAPIMask(EGLUT_OPENVG_BIT);
75   eglutInit(argc, argv);
76
77   eglutCreateWindow("Lion Example");
78
79   eglutReshapeFunc(reshape);
80   eglutDisplayFunc(draw);
81
82   init();
83
84   eglutMainLoop();
85
86   return 0;
87}
88