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: https://svn.code.sf.net/p/freeglut/code/trunk@332 7f0cb862-5218-0410-a997-914c9d46530a
This commit is contained in:
rkrolib 2003-11-10 16:01:05 +00:00
parent 9623350767
commit 6829d65fb3
6 changed files with 197 additions and 7 deletions

2
.gitattributes vendored
View File

@ -34,6 +34,8 @@ freeglut/freeglut/include/Makefile.am svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/install-sh svn_keywords=Author+Date+Id+Revision freeglut/freeglut/install-sh svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/mkinstalldirs svn_keywords=Author+Date+Id+Revision freeglut/freeglut/mkinstalldirs svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/progs/Makefile.am svn_keywords=Author+Date+Id+Revision freeglut/freeglut/progs/Makefile.am svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/progs/demos/CallbackMaker/CallbackMaker.c svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/progs/demos/CallbackMaker/Makefile.am svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/progs/demos/Fractals/Fractals.dsp svn_keywords=Author+Date+Id+Revision freeglut/freeglut/progs/demos/Fractals/Fractals.dsp svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/progs/demos/Fractals/Makefile.am svn_keywords=Author+Date+Id+Revision freeglut/freeglut/progs/demos/Fractals/Makefile.am svn_keywords=Author+Date+Id+Revision
freeglut/freeglut/progs/demos/Fractals/fractals.c svn_keywords=Author+Date+Id+Revision freeglut/freeglut/progs/demos/Fractals/fractals.c svn_keywords=Author+Date+Id+Revision

View File

@ -55,6 +55,7 @@ AC_OUTPUT(\
doc/Makefile \ doc/Makefile \
progs/Makefile \ progs/Makefile \
progs/demos/Makefile \ progs/demos/Makefile \
progs/demos/CallbackMaker/Makefile \
progs/demos/Fractals/Makefile \ progs/demos/Fractals/Makefile \
progs/demos/Fractals_random/Makefile \ progs/demos/Fractals_random/Makefile \
progs/demos/Lorenz/Makefile \ progs/demos/Lorenz/Makefile \

View File

@ -0,0 +1,185 @@
/* CallbackMaker.c */
/*
* Program to invoke all the callbacks that "freeglut" supports
*/
#include <GL/freeglut.h>
#include <stdio.h>
#include <stdlib.h>
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. */
}

View File

@ -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)

View File

@ -63,12 +63,9 @@ static void draw_level ( int num, double m00, double m01, double m10, double m11
for ( i = 0; i < 10; i++ ) for ( i = 0; i < 10; i++ )
{ {
int random = rand( ); int random = ( rand( ) >> 10 ) % num_trans;
double new_x; double new_x = affine[random].a00 * current_x + affine[random].a01 * current_y + affine[random].b0 ;
double new_y; double new_y = affine[random].a10 * current_x + affine[random].a11 * current_y + affine[random].b1 ;
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 ;
glVertex2d ( new_x, new_y ) ; glVertex2d ( new_x, new_y ) ;
current_x = new_x ; current_x = new_x ;

View File

@ -1,2 +1,2 @@
EXTRA_DIST = demos.dsw EXTRA_DIST = demos.dsw
SUBDIRS = Fractals Fractals_random Lorenz One SUBDIRS = CallbackMaker Fractals Fractals_random Lorenz One