From 0ccd74e0bf59a5a4dd55721198c88e53c5362850 Mon Sep 17 00:00:00 2001 From: Richard Rauch Date: Mon, 10 Nov 2003 16:01:05 +0000 Subject: [PATCH] New demo from John: CallbackMaker. This demo shows the use of every callback that you can register with freeglut, and also generates event reports so that you can see what is happening to the program as it runs. Not much to look at, but both utilitarian and a practical example. Please double-check that I updated everything that needs to be updated. I reran autogen.sh and ./configure, and it built okay for me. (^& git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@332 7f0cb862-5218-0410-a997-914c9d46530a --- configure.in | 1 + progs/demos/CallbackMaker/CallbackMaker.c | 185 +++++++++++++++++++++++++ progs/demos/CallbackMaker/Makefile.am | 5 + progs/demos/Fractals_random/fractals_random.c | 9 +- progs/demos/Makefile.am | 2 +- 5 files changed, 195 insertions(+), 7 deletions(-) create mode 100644 progs/demos/CallbackMaker/CallbackMaker.c create mode 100644 progs/demos/CallbackMaker/Makefile.am diff --git a/configure.in b/configure.in index b9e8577..f23725e 100644 --- a/configure.in +++ b/configure.in @@ -55,6 +55,7 @@ AC_OUTPUT(\ doc/Makefile \ progs/Makefile \ progs/demos/Makefile \ + progs/demos/CallbackMaker/Makefile \ progs/demos/Fractals/Makefile \ progs/demos/Fractals_random/Makefile \ progs/demos/Lorenz/Makefile \ diff --git a/progs/demos/CallbackMaker/CallbackMaker.c b/progs/demos/CallbackMaker/CallbackMaker.c new file mode 100644 index 0000000..3aede72 --- /dev/null +++ b/progs/demos/CallbackMaker/CallbackMaker.c @@ -0,0 +1,185 @@ +/* CallbackMaker.c */ +/* + * Program to invoke all the callbacks that "freeglut" supports + */ + + +#include +#include +#include + +static int sequence_number = 0 ; + +static void +Display(void) +{ + int window = glutGetWindow () ; + glClear( GL_COLOR_BUFFER_BIT ); + + printf ( "%6d Window %d Display Callback\n", + ++sequence_number, window ) ; + glutSwapBuffers(); +} + +static void +Reshape(int width, int height) +{ + int window = glutGetWindow () ; + printf ( "%6d Window %d Reshape Callback: %d %d\n", + ++sequence_number, window, width, height ) ; +} + +static void +Key(unsigned char key, int x, int y) +{ + int window = glutGetWindow () ; + printf ( "%6d Window %d Keyboard Callback: %d %d %d\n", + ++sequence_number, window, key, x, y ) ; +} + +static void +Special(int key, int x, int y) +{ + int window = glutGetWindow () ; + printf ( "%6d Window %d Special Key Callback: %d %d %d\n", + ++sequence_number, window, key, x, y ) ; +} + +static void +Visibility(int vis) +{ + int window = glutGetWindow () ; + printf ( "%6d Window %d Visibility Callback: %d\n", + ++sequence_number, window, vis ) ; +} + +static void +KeyUp(unsigned char key, int x, int y) +{ + int window = glutGetWindow () ; + printf ( "%6d Window %d Key Release Callback: %d %d %d\n", + ++sequence_number, window, key, x, y ) ; +} + +static void +SpecialUp(int key, int x, int y) +{ + int window = glutGetWindow () ; + printf ( "%6d Window %d Special Key Release Callback: %d %d %d\n", + ++sequence_number, window, key, x, y ) ; +} + +static void +Joystick( unsigned int a, int b, int c, int d) +{ + int window = glutGetWindow () ; + printf ( "%6d Window %d Joystick Callback: %d %d %d %d\n", + ++sequence_number, window, a, b, c, d ) ; +} + +static void +Mouse(int button, int updown, int x, int y) +{ + int window = glutGetWindow () ; + printf ( "%6d Window %d Mouse Click Callback: %d %d %d %d\n", + ++sequence_number, window, button, updown, x, y ) ; +} + +static void +MouseWheel(int wheel_number, int direction, int x, int y) +{ + int window = glutGetWindow () ; + printf ( "%6d Window %d Mouse Wheel Callback: %d %d %d %d\n", + ++sequence_number, window, wheel_number, direction, x, y ) ; +} + +static void +Motion(int x, int y) +{ + int window = glutGetWindow () ; + printf ( "%6d Window %d Mouse Motion Callback: %d %d\n", + ++sequence_number, window, x, y ) ; +} + +static void +PassiveMotion(int x, int y) +{ + int window = glutGetWindow () ; + printf ( "%6d Window %d Mouse Passive Motion Callback: %d %d\n", + ++sequence_number, window, x, y ) ; +} + +static void +Entry(int state) +{ + int window = glutGetWindow () ; + printf ( "%6d Window %d Entry Callback: %d\n", + ++sequence_number, window, state ) ; +} + +static void +Close(void) +{ + int window = glutGetWindow () ; + printf ( "%6d Window %d Close Callback\n", + ++sequence_number, window ) ; +} + + + +int +main(int argc, char *argv[]) +{ + int freeglut_window, aux_window ; + + glutInitWindowSize(500, 250); + glutInitWindowPosition ( 140, 140 ); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE ); + glutInit(&argc, argv); + + freeglut_window = glutCreateWindow( "Callback Demo" ); + printf ( "Creating window %d as 'Callback Demo'\n", freeglut_window ) ; + + glClearColor(1.0, 1.0, 1.0, 1.0); + + glutDisplayFunc( Display ); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( Special ); + glutVisibilityFunc( Visibility ); + glutKeyboardUpFunc( KeyUp ); + glutSpecialUpFunc( SpecialUp ); +// glutJoystickFunc( Joystick, 10 ); + glutMouseFunc ( Mouse ) ; + glutMouseWheelFunc ( MouseWheel ) ; + glutMotionFunc ( Motion ) ; + glutPassiveMotionFunc ( PassiveMotion ) ; + glutEntryFunc ( Entry ) ; + glutCloseFunc ( Close ) ; + + aux_window = glutCreateWindow( "Second Window" ); + printf ( "Creating window %d as 'Second Window'\n", aux_window ) ; + + glClearColor(1.0, 1.0, 1.0, 1.0); + + glutDisplayFunc( Display ); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( Special ); + glutVisibilityFunc( Visibility ); + glutKeyboardUpFunc( KeyUp ); + glutSpecialUpFunc( SpecialUp ); +// glutJoystickFunc( Joystick, 10 ); + glutMouseFunc ( Mouse ) ; + glutMouseWheelFunc ( MouseWheel ) ; + glutMotionFunc ( Motion ) ; + glutPassiveMotionFunc ( PassiveMotion ) ; + glutEntryFunc ( Entry ) ; + glutCloseFunc ( Close ) ; + + glutMainLoop(); + + printf ( "Back from the 'freeglut' main loop\n" ) ; + + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/demos/CallbackMaker/Makefile.am b/progs/demos/CallbackMaker/Makefile.am new file mode 100644 index 0000000..a516e0d --- /dev/null +++ b/progs/demos/CallbackMaker/Makefile.am @@ -0,0 +1,5 @@ +EXTRA_DIST = CallbackMaker.c +noinst_PROGRAMS = CallbackMaker +CallbackMaker_SOURCES = CallbackMaker.c +CallbackMaker_LDFLAGS = -export-dynamic ../../../src/lib@LIBRARY@.la +CallbackMaker_CFLAGS = -I$(top_srcdir)/include $(X_CFLAGS) diff --git a/progs/demos/Fractals_random/fractals_random.c b/progs/demos/Fractals_random/fractals_random.c index 9c4575f..f0ea3e0 100644 --- a/progs/demos/Fractals_random/fractals_random.c +++ b/progs/demos/Fractals_random/fractals_random.c @@ -63,12 +63,9 @@ static void draw_level ( int num, double m00, double m01, double m10, double m11 for ( i = 0; i < 10; i++ ) { - int random = rand( ); - double new_x; - double new_y; - random = (((random >> 10)) & 2) + (((random >> 20) ) & 1); - new_x = affine[random].a00 * current_x + affine[random].a01 * current_y + affine[random].b0 ; - new_y = affine[random].a10 * current_x + affine[random].a11 * current_y + affine[random].b1 ; + int random = ( rand( ) >> 10 ) % num_trans; + double new_x = affine[random].a00 * current_x + affine[random].a01 * current_y + affine[random].b0 ; + double new_y = affine[random].a10 * current_x + affine[random].a11 * current_y + affine[random].b1 ; glVertex2d ( new_x, new_y ) ; current_x = new_x ; diff --git a/progs/demos/Makefile.am b/progs/demos/Makefile.am index 6fc9380..3a501d4 100644 --- a/progs/demos/Makefile.am +++ b/progs/demos/Makefile.am @@ -1,2 +1,2 @@ EXTRA_DIST = demos.dsw -SUBDIRS = Fractals Fractals_random Lorenz One +SUBDIRS = CallbackMaker Fractals Fractals_random Lorenz One -- 1.7.10.4