added the timer demo
git-svn-id: https://svn.code.sf.net/p/freeglut/code/trunk@1100 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
parent
0c5025cc85
commit
cf7613066d
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -126,6 +126,7 @@ freeglut/freeglut/progs/demos/subwin/Makefile.am -text
|
||||
freeglut/freeglut/progs/demos/subwin/subwin.c -text
|
||||
freeglut/freeglut/progs/demos/subwin/subwin.dsp -text
|
||||
freeglut/freeglut/progs/demos/subwin/subwinStatic.dsp -text
|
||||
freeglut/freeglut/progs/demos/timer/timer.c -text
|
||||
freeglut/freeglut/src/Common/freeglut_callbacks.c svn_keywords=Author+Date+Id+Revision
|
||||
freeglut/freeglut/src/Common/freeglut_cursor.c svn_keywords=Author+Date+Id+Revision
|
||||
freeglut/freeglut/src/Common/freeglut_display.c svn_keywords=Author+Date+Id+Revision
|
||||
|
@ -219,5 +219,4 @@ ADD_DEMO(spaceball progs/demos/spaceball/spaceball.c
|
||||
progs/demos/spaceball/vmath.c
|
||||
progs/demos/spaceball/vmath.h)
|
||||
ADD_DEMO(subwin progs/demos/subwin/subwin.c)
|
||||
|
||||
|
||||
ADD_DEMO(timer progs/demos/timer/timer.c)
|
||||
|
53
freeglut/freeglut/progs/demos/timer/timer.c
Normal file
53
freeglut/freeglut/progs/demos/timer/timer.c
Normal file
@ -0,0 +1,53 @@
|
||||
/* Timer demo
|
||||
*
|
||||
* Written by John Tsiombikas <nuclear@member.fsf.org>
|
||||
*
|
||||
* Demonstrate the use of glutTimerFunc, by changing the color of the
|
||||
* framebuffer every (approximately) 1 sec.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <GL/glut.h>
|
||||
|
||||
void disp(void);
|
||||
void timer_func(int unused);
|
||||
|
||||
/* color index will be advanced every time the timer expires */
|
||||
int cidx;
|
||||
float color[][3] = {
|
||||
{1, 0, 0},
|
||||
{0, 1, 0},
|
||||
{0, 0, 1},
|
||||
{1, 1, 0},
|
||||
{0, 1, 1},
|
||||
{1, 0, 1}
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
glutInit(&argc, argv);
|
||||
glutInitWindowSize(128, 128);
|
||||
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
|
||||
glutCreateWindow("timer test");
|
||||
|
||||
glutDisplayFunc(disp);
|
||||
|
||||
glutMainLoop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void disp(void)
|
||||
{
|
||||
glClearColor(color[cidx][0], color[cidx][1], color[cidx][2], 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
/* set the timer callback and ask glut to call it in 1 second */
|
||||
glutTimerFunc(1000, timer_func, 0);
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
void timer_func(int unused)
|
||||
{
|
||||
/* advance the color index and trigger a redisplay */
|
||||
cidx = (cidx + 1) % (sizeof color / sizeof *color);
|
||||
glutPostRedisplay();
|
||||
}
|
Reference in New Issue
Block a user