dsys2

diff test.c @ 8:4ad7a01c4ff5

ha
author John Tsiombikas <nuclear@siggraph.org>
date Fri, 02 Sep 2011 10:48:24 +0300
parents 3258d163cfbc
children 66d4fe7a8613
line diff
     1.1 --- a/test.c	Fri Sep 02 08:14:40 2011 +0300
     1.2 +++ b/test.c	Fri Sep 02 10:48:24 2011 +0300
     1.3 @@ -1,5 +1,6 @@
     1.4  #include <stdio.h>
     1.5  #include <stdlib.h>
     1.6 +#include <math.h>
     1.7  #include <time.h>
     1.8  #include <sys/time.h>
     1.9  
    1.10 @@ -14,6 +15,7 @@
    1.11  void disp(void);
    1.12  void draw_progress(float p);
    1.13  void draw_teapot(float sec);
    1.14 +void flash_callback(struct dsys_event *ev, void *cls);
    1.15  void reshape(int x, int y);
    1.16  void keyb(unsigned char key, int x, int y);
    1.17  void skeyb(int key, int x, int y);
    1.18 @@ -21,6 +23,13 @@
    1.19  
    1.20  struct dsys_demo *demo;
    1.21  
    1.22 +struct dsys_event *evfoo, *evfoolong, *evfooshort;
    1.23 +
    1.24 +float teapot_color[][4] = {
    1.25 +	{0.9, 0.5, 0.3, 1.0},
    1.26 +	{0.3, 0.4, 0.8, 1.0}
    1.27 +};
    1.28 +
    1.29  int main(int argc, char **argv)
    1.30  {
    1.31  	float lpos[] = {-100, 100, 100, 1};
    1.32 @@ -47,6 +56,12 @@
    1.33  		return 1;
    1.34  	}
    1.35  
    1.36 +	evfoo = dsys_event(demo, "foo");
    1.37 +	evfoolong = dsys_event(demo, "foolong");
    1.38 +	evfooshort = dsys_event(demo, "fooshort");
    1.39 +
    1.40 +	dsys_event_callback(evfooshort, flash_callback, 0);
    1.41 +
    1.42  	glutMainLoop();
    1.43  	return 0;
    1.44  }
    1.45 @@ -54,7 +69,9 @@
    1.46  
    1.47  void disp(void)
    1.48  {
    1.49 +	int i;
    1.50  	float sec;
    1.51 +	static const float trans[][2] = {{-3, 0}, {3, 0}, {0, -3}, {0, 3}};
    1.52  
    1.53  	dsys_update(demo, dsys_msec_to_dtime(get_ticks()));
    1.54  	sec = dsys_dtime_to_sec(dsys_time(demo));
    1.55 @@ -68,6 +85,19 @@
    1.56  
    1.57  	draw_teapot(sec);
    1.58  
    1.59 +	glEnable(GL_BLEND);
    1.60 +	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    1.61 +
    1.62 +	for(i=0; i<4; i++) {
    1.63 +		glPushMatrix();
    1.64 +		glRotatef(-sec * 100.0, 0, 1, 0);
    1.65 +		glTranslatef(trans[i][0], 0, trans[i][1]);
    1.66 +		glScalef(0.7, 0.7, 0.7);
    1.67 +		draw_teapot(sec);
    1.68 +		glPopMatrix();
    1.69 +	}
    1.70 +	glDisable(GL_BLEND);
    1.71 +
    1.72  	draw_progress(dsys_progress(demo));
    1.73  
    1.74  	glutSwapBuffers();
    1.75 @@ -113,10 +143,18 @@
    1.76  	glPopMatrix();
    1.77  }
    1.78  
    1.79 +#define LERP(a, b, t)	((a) + ((b) - (a)) * (t))
    1.80 +
    1.81  void draw_teapot(float sec)
    1.82  {
    1.83 -	float dcol[] = {0.2, 0.4, 0.8, 1.0};
    1.84 +	float dcol[4];
    1.85  	float scol[] = {0.8, 0.8, 0.8, 1.0};
    1.86 +	float t = dsys_event_value(evfoo);
    1.87 +
    1.88 +	dcol[0] = LERP(teapot_color[0][0], teapot_color[1][0], t);
    1.89 +	dcol[1] = LERP(teapot_color[0][1], teapot_color[1][1], t);
    1.90 +	dcol[2] = LERP(teapot_color[0][2], teapot_color[1][2], t);
    1.91 +	dcol[3] = dsys_event_value(evfoolong);
    1.92  
    1.93  	glPushMatrix();
    1.94  	glRotatef(sec * 100.0, 0, 1, 0);
    1.95 @@ -132,6 +170,13 @@
    1.96  	glPopMatrix();
    1.97  }
    1.98  
    1.99 +void flash_callback(struct dsys_event *ev, void *cls)
   1.100 +{
   1.101 +	float t = sin(dsys_event_value(ev) * M_PI);
   1.102 +
   1.103 +	glClearColor(t, t, t, 1.0);
   1.104 +}
   1.105 +
   1.106  void reshape(int x, int y)
   1.107  {
   1.108  	glViewport(0, 0, x, y);