home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / OpenGL 1.0 SDK / Source / Examples / aux / backtrace / main.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  3.9 KB  |  151 lines  |  [TEXT/CWIE]

  1. /*
  2.  * (c) Copyright 1993, 1994, 1995, 1996 Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED 
  4.  * Permission to use, copy, modify, and distribute this software for 
  5.  * any purpose and without fee is hereby granted, provided that the above
  6.  * copyright notice appear in all copies and that both the copyright notice
  7.  * and this permission notice appear in supporting documentation, and that 
  8.  * the name of Silicon Graphics, Inc. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission. 
  11.  *
  12.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  16.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  21.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  * 
  25.  * US Government Users Restricted Rights 
  26.  * Use, duplication, or disclosure by the Government is subject to
  27.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29.  * clause at DFARS 252.227-7013 and/or in similar or successor
  30.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  31.  * Unpublished-- rights reserved under the copyright laws of the
  32.  * United States.  Contractor/manufacturer is Silicon Graphics,
  33.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  34.  *
  35.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  36.  */
  37. #include "gl.h"
  38. #include "glu.h"
  39. #include "agl.h"
  40. #include "tk.h"
  41. #include "aux.h"
  42.  
  43. #include <math.h>
  44. #include <stdio.h>
  45. #include <stdlib.h>
  46.  
  47. #include <time.h>
  48.  
  49. #if defined(__MWERKS__) || defined(__SC__)
  50.     #include <console.h>            /* ccommand */
  51. #endif
  52.  
  53. #include "scene.h"
  54.  
  55. void Draw(void);
  56. void Reshape(int w, int h);
  57. float rand_s(float min, float max) ;
  58.  
  59. static float dtheta[nlights];
  60. static int texture_available = 0;
  61.  
  62. float rand_s(float min, float max) 
  63. {
  64.     double r;
  65.     r = (double)rand() / (double)RAND_MAX;
  66.     return min + r * (max - min);
  67. }
  68.  
  69. void Draw(void)
  70. {
  71.     int i;
  72.     
  73.     for (i = 0; i < nlights; i++)
  74.         dtheta[i] = rand_s(-90, 90);
  75.     
  76.     for (i = 0; i < nlights; i++)
  77.         scene_move(name_lights + i, 0, 0, dtheta[i] * 0.01, 1);
  78.  
  79.     scene_draw();
  80.     
  81.     auxSwapBuffers();
  82. }
  83.  
  84. void Reshape(int w, int h)
  85. {
  86.     glViewport(0, 0, w, h);
  87.     aspect = (GLfloat) w / (GLfloat) h;
  88. }
  89.  
  90. static GLenum KeyDown(int key, GLenum mask)
  91. {
  92.     switch (key)
  93.     {
  94.         case TK_1:
  95.             draw_texture = (texture_available ? !draw_texture : draw_texture);
  96.         break;
  97.         case TK_2:
  98.             draw_square = !draw_square;
  99.         break;
  100.         case TK_3:
  101.             draw_shadows = !draw_shadows;
  102.         break;
  103.         case TK_4:
  104.             draw_refraction = !draw_refraction;
  105.         break;
  106.         case TK_5:
  107.             draw_sphere = !draw_sphere;
  108.         break;
  109.         case TK_6:
  110.             draw_lights = !draw_lights;
  111.         break;
  112.         default:
  113.             return GL_FALSE;
  114.     }
  115.     
  116.     return GL_TRUE;
  117. }
  118.  
  119. void main(int argc, char **argv)
  120. {
  121.     #if defined(__MWERKS__) || defined(__SC__)
  122.         argc = ccommand(&argv);
  123.     #endif
  124.     
  125.     if(argc > 1) scene_load_texture(argv[1]);
  126.     
  127.     auxInitDisplayMode (AUX_DOUBLE | AUX_RGB | AUX_DEPTH | AUX_STENCIL);
  128.     auxInitPosition (30, 60, 400, 400);
  129.     auxInitWindow ("Backtrace");
  130.  
  131.     srand(clock());
  132.     
  133.     scene_init();
  134.  
  135.     texture_available = (argc > 1);
  136.     draw_texture    = texture_available;
  137.     draw_square     = 1;
  138.     draw_shadows    = 1;
  139.     draw_refraction = 1;
  140.     draw_sphere     = 1;
  141.     draw_lights     = 1;
  142.     
  143.     /*glDisable(GL_DITHER);*/
  144.  
  145.     auxReshapeFunc(Reshape);
  146.     auxExposeFunc(Reshape);
  147.     tkKeyDownFunc(KeyDown);
  148.     auxIdleFunc(Draw);
  149.     auxMainLoop(Draw);
  150. }
  151.