X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=progs%2Fdemos%2FLorenz%2Florenz.c;h=a3a61dbe5aa20242b90f47e36f10c712facb1594;hb=369e02f3912ca0f768d98e49fb1198e80f44e078;hp=4f0afc1ef24ce491c7788a763b5c9e35ffe9eb9f;hpb=e150e05bf1baf832de450b3141d8fac59cfc09fb;p=freeglut diff --git a/progs/demos/Lorenz/lorenz.c b/progs/demos/Lorenz/lorenz.c index 4f0afc1..a3a61db 100644 --- a/progs/demos/Lorenz/lorenz.c +++ b/progs/demos/Lorenz/lorenz.c @@ -29,10 +29,14 @@ /* Include Files */ #include #include +#include #include #include -#include #include +#ifdef _MSC_VER +/* DUMP MEMORY LEAKS */ +#include +#endif /************************************** Defined Constants ***************************************/ @@ -104,12 +108,24 @@ void advance_in_time ( double time_step, double position[3], double new_position ( deriv0[i] + 2.0 * ( deriv1[i] + deriv2[i] ) + deriv3[i] ) ; } +static void +checkedFGets ( char *s, int size, FILE *stream ) +{ + if ( fgets ( s, size, stream ) == NULL ) { + fprintf ( stderr, "fgets failed\n"); + exit ( EXIT_FAILURE ); + } +} + + /* GLUT callbacks */ +#define INPUT_LINE_LENGTH 80 + void key_cb ( unsigned char key, int x, int y ) { int i ; - char inputline [ 80 ] ; + char inputline [ INPUT_LINE_LENGTH ] ; switch ( key ) { @@ -136,16 +152,16 @@ void key_cb ( unsigned char key, int x, int y ) break ; case 'm' : case 'M' : /* Modify the Lorenz parameters */ - printf ( "Please enter new value for (default %lf, currently %lf): ", s0, sigma ) ; - fgets ( inputline, 79, stdin ) ; + printf ( "Please enter new value for (default %f, currently %f): ", s0, sigma ) ; + checkedFGets ( inputline, sizeof ( inputline ), stdin ) ; sscanf ( inputline, "%lf", &sigma ) ; - printf ( "Please enter new value for (default %lf, currently %lf): ", b0, b ) ; - fgets ( inputline, 79, stdin ) ; + printf ( "Please enter new value for (default %f, currently %f): ", b0, b ) ; + checkedFGets ( inputline, sizeof ( inputline ), stdin ) ; sscanf ( inputline, "%lf", &b ) ; - printf ( "Please enter new value for (default %lf, currently %lf): ", r0, r ) ; - fgets ( inputline, 79, stdin ) ; + printf ( "Please enter new value for (default %f, currently %f): ", r0, r ) ; + checkedFGets ( inputline, sizeof ( inputline ), stdin ) ; sscanf ( inputline, "%lf", &r ) ; break ; @@ -204,8 +220,10 @@ void mouse_cb ( int button, int updown, int x, int y ) { if ( updown == GLUT_DOWN ) { - double dist = 1.0e20 ; /* A very large number */ - (void) dist; /* what's this all about? */ + /*double dist = 1.0e20 ; A very large number */ + /* The idea here is that we go into "pick" mode and pick the nearest point + to the mouse click position. Unfortunately I don't have the time to implement + it at the moment. */ } } @@ -224,10 +242,23 @@ void draw_curve ( int index, double position [ NUM_POINTS ][3] ) glEnd () ; } -void display_cb ( void ) +void bitmapPrintf (const char *fmt, ...) { - char string [ 80 ] ; + static char buf[256]; + va_list args; + + va_start(args, fmt); +#if defined(WIN32) && !defined(__CYGWIN__) + (void) _vsnprintf (buf, sizeof(buf), fmt, args); +#else + (void) vsnprintf (buf, sizeof(buf), fmt, args); +#endif + va_end(args); + glutBitmapString ( GLUT_BITMAP_HELVETICA_12, (unsigned char*)buf ) ; +} +void display_cb ( void ) +{ glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ; glColor3d ( 1.0, 1.0, 1.0 ) ; /* White */ @@ -249,9 +280,8 @@ void display_cb ( void ) /* Print the distance between the two points */ glColor3d ( 1.0, 1.0, 1.0 ) ; /* White */ - sprintf ( string, "Distance: %10.6lf", distance ) ; - glRasterPos2i ( 10, 10 ) ; - glutBitmapString ( GLUT_BITMAP_HELVETICA_12, string ) ; + glRasterPos2i ( 1, 1 ) ; + bitmapPrintf ( "Distance: %10.6f", distance ) ; glutSwapBuffers(); } @@ -312,7 +342,6 @@ int main ( int argc, char *argv[] ) srand ( 1023 ) ; /* Set up the OpenGL parameters */ - /* glDrawBuffer ( GL_BACK ) ;*/ glEnable ( GL_DEPTH_TEST ) ; glClearColor ( 0.0, 0.0, 0.0, 0.0 ) ; glClearDepth ( 1.0 ) ; @@ -339,6 +368,11 @@ int main ( int argc, char *argv[] ) /* Enter the GLUT main loop */ glutMainLoop () ; - return 0; +#ifdef _MSC_VER + /* DUMP MEMORY LEAK INFORMATION */ + _CrtDumpMemoryLeaks () ; +#endif + + return 0 ; }