home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / egltk22.zip / sample.c < prev    next >
Text File  |  1998-02-21  |  5KB  |  120 lines

  1. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Sample Escape GL Custom Screen Saver
  4. //    Copyright (c) 1997, Snow Storm Software
  5. //    All Rights Reserved
  6. //
  7. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  8.  
  9. #include "custom.h"
  10. #include <glut.h>
  11. #include <tk.h>
  12.  
  13. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  14. //
  15. // general instructions:
  16. //   - copy this file to another name eg. cool.c
  17. //   - modify all functions examples to provide the processing you desire
  18. //   - add your project to the 'TARGETS =' part of 'MAKEFILE.' eg. 'TARGETS = sample.egl wave.egl cool.egl'
  19. //   - make sure the 'TOP =' part of 'MAKEFILE' correctly identifies the location of your opengl base directory
  20. //      eg. 'TOP = \opengl'
  21. //   - build your project using 'nmake'
  22. //   - copy your new screen saver module 'cool.egl' to any Escape GL sub-directory
  23. //   - reload Escape GL
  24. //
  25. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  26.  
  27. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  28. //
  29. // global variables
  30. //   define any variables you require
  31. //
  32. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  33.  
  34. GLfloat rotation = 0;
  35.  
  36. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  37. //
  38. // eglDesc
  39. //   defines the name of the module as it will appear in the drop down module list
  40. //   this name must be unique and not match any existing modules, nor custom modules
  41. //
  42. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  43.  
  44. char * APIENTRY eglDesc()
  45. {
  46.    return( "Cube Sample" );
  47. }
  48.  
  49. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  50. //
  51. // eglInit
  52. //   initializes the opengl module you wish to display and is called once before the model is animated
  53. //   this function is called once to setup the module
  54. //
  55. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  56.  
  57. void APIENTRY eglInit( GLint quality )
  58. {
  59.    glClearColor( 0.0, 0.0, 0.0, 0.0 );
  60.    glShadeModel( GL_FLAT );
  61. }
  62.  
  63. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  64. //
  65. // eglIdle
  66. //   animates and displays the module
  67. //   the parameter 'step' simply defines the time in seconds between time steps, use this to control the animation speed
  68. //    the size of the step is based on the speed of the target system and the complexity of the module, slower modules
  69. //    will take larger steps
  70. //
  71. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  72.  
  73. void APIENTRY eglIdle( GLfloat step )
  74. {
  75.    glClear( GL_COLOR_BUFFER_BIT );
  76.    glColor3f( 1.0, 1.0, 1.0 );
  77.  
  78.    glLoadIdentity();             /* clear the matrix */
  79.  
  80.    /* viewing transformation  */
  81.    gluLookAt( 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 );
  82.  
  83.    /* rotate */
  84.    rotation += step * 270.;                                    // rotate at 30 deg per second
  85.    if ( rotation > 360.0 )
  86.       rotation -= 360.;
  87.    glRotatef( rotation, 0, 1, 0 );
  88.    glutWireCube( 1.0 );
  89.  
  90.    // NOTE: swapping of the buffers is done automatically by Escape GL and should not be added here.
  91. }
  92.  
  93. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  94. //
  95. // eglReshape
  96. //   resizes the window
  97. //   use this function to define the viewport and projection transformations based on the window size
  98. //
  99. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  100.  
  101. void APIENTRY eglReshape( GLint w, GLint h )
  102. {
  103.    glViewport( 0, 0, w, h );
  104.    glMatrixMode( GL_PROJECTION );
  105.    glLoadIdentity();
  106.    glFrustum( -1.0, 1.0, -1.0, 1.0, 1.5, 20.0 );
  107.    glMatrixMode( GL_MODELVIEW );
  108. }
  109.  
  110. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  111. //
  112. // eglDestroy
  113. //   destroy display lists, objects etc. when the module has ended
  114. //
  115. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  116.  
  117. void APIENTRY eglDestroy()
  118. {
  119. }
  120.