/* * Copyright (c) 1996-1999 Silicon Graphics, Inc. All rights reserved. * * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. * * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE * POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* window.c - open a window in a specified position */ #include #include /* Segue il prototipo della funzione di rendering che verrą registrata con la callback glutDisplayFunc() */ GLvoid drawScene( GLvoid ); /* Segue il prototipo della funzione di rendering che verrą registrata con la callback glutIdleFunc() */ GLvoid countFrames( GLvoid ); /* Seguono le variabili globali */ /* Le seguenti andranno a contenere le dimensioni dello schermo */ GLsizei width, height; /* Il seguente contatore serve per mostrare quando la funzione di renderign viene evocata. Esso viene inizializzato a 0 e, ad ogni chiamata, viene visualizzato e poi incrementato. Si noti come al variare dell'aspetto a video della finestra (si provi per esempio a occluderla parzialmente) il contatore aumenti. */ GLint count = 0; /* Memorizza il tempo in millisecondi all'avvio del programma. Serve per memorizzare i frame medi al secondo */ GLint initialTime; // Divisione di due numeri interi const int divide(const int divisor, const int dividend); void main( int argc, char *argv[] ) { /* Inizializziamo le GLUT */ glutInit( &argc, argv ); /* Mostriamo sulla shell la dimensione in pixel del monitor */ width = glutGet( GLUT_SCREEN_WIDTH ); height = glutGet( GLUT_SCREEN_HEIGHT ); printf("dimensioni schermo: %d %d \n",width,height); /* create a window that is 1/4 the size of the screen, * and position it in the middle of the screen. */ glutInitWindowPosition( width / 4, height / 4 ); glutInitWindowSize( width / 2, height / 2 ); glutInitDisplayMode(GLUT_DOUBLE|GLUT_STENCIL|GLUT_DEPTH|GLUT_ALPHA); glutCreateWindow( argv[0] ); /* Registriamo la funzione di rendering */ glutDisplayFunc( drawScene ); glutIdleFunc( countFrames ); // Memorizza il tempo attuale initialTime = glutGet(GLUT_ELAPSED_TIME); /* Abbia inizio il loop principale dell'applicazione */ glutMainLoop(); } GLvoid drawScene( GLvoid ) { /* cancelliamo il buffer video e lo z buffer */ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glFlush(); } // Conta i frame quando siamo in stato idle GLvoid countFrames( GLvoid ){ printf("Chiamata numero: %d Frames per second: %d Seconds per frame: %d \r", count, divide(count, divide(glutGet(GLUT_ELAPSED_TIME) - initialTime, 60)), divide(divide(glutGet(GLUT_ELAPSED_TIME) - initialTime, 60), count) ); count++; } // Divisione di due numeri interi const int divide(const int divisor, const int dividend) { return( divisor/dividend ); }