home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sstoolkt.zip / demo.c < prev    next >
Text File  |  1996-10-24  |  3KB  |  132 lines

  1. #define INCL_WIN
  2. #define INCL_GPI
  3. #define VERTICES 4
  4.  
  5. #include <os2.h>
  6. #include <stdlib.h>
  7. #include "savers.h"
  8. #include "demo.h"
  9.  
  10. HAB habProgram;
  11. int cxMax, cyMax;
  12.  
  13. #include <gl.h>
  14. #include <glu.h>
  15. #include <math.h>
  16. #include <stdio.h>
  17. #include "aux.h"
  18.  
  19. GLint fogMode;
  20. PVISUALCONFIG PVisConfig;
  21. int AttrList[] = {PGL_RGBA, PGL_DOUBLEBUFFER, None};
  22. HGC HglContext;
  23. BOOL Init = TRUE;
  24. float t=0.0;
  25.  
  26. void Setup()
  27. {
  28.   glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
  29.   glDepthMask(GL_FALSE);
  30.   glEnable(GL_CULL_FACE);
  31. }
  32.  
  33. float verts[][3] = {
  34.   { 0.0, 0.0, (1.0/1.4142)},
  35.   { 0.5, 0.5, 0.0},
  36.   {-0.5, 0.5, 0.0},
  37.   {-0.5,-0.5, 0.0},
  38.   { 0.5,-0.5, 0.0},
  39.   { 0.0, 0.0, -(1.0/1.4142)}
  40. };
  41.  
  42. float colors[][3] = {
  43.   {1.0, 1.0, 1.0},
  44.   {1.0, 0.0, 0.0},
  45.   {0.0, 1.0, 0.0},
  46.   {0.0, 0.0, 1.0},
  47.   {1.0, 0.0, 1.0},
  48.   {0.0, 1.0, 1.0},
  49. };
  50.  
  51. MRESULT EXPENTRY __export SaverProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  52. {
  53.     HPS hps;
  54.     static PFNWP OldSaverProc;
  55.  
  56.     switch(msg)
  57.     {
  58.         case UM_INIT_SAVER:
  59.             OldSaverProc = (PFNWP)mp2;
  60.             habProgram =WinQueryAnchorBlock(hwnd);
  61.             cxMax = SHORT1FROMMP(mp1);
  62.             cyMax = SHORT2FROMMP(mp1);
  63.  
  64.             if(PVisConfig = pglChooseConfig(habProgram, AttrList))
  65.             {   
  66.                 HglContext = pglCreateContext(habProgram, PVisConfig, NULL, TRUE);
  67.                 pglMakeCurrent(habProgram, HglContext, hwnd);
  68.                 Setup();
  69.             }
  70.         return((MRESULT)SHAREWARE);                                                                               
  71.  
  72.         case WM_PAINT:
  73.             if(Init)
  74.             {
  75.                       glViewport(0, 0, cxMax, cyMax);
  76.                     --Init;
  77.             }
  78.             /* This is what is done for every frame of the animation        */
  79.             t += 1.0;
  80.             glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  81.             glPushMatrix();
  82.             glRotatef(t, 1.0, 1.0, 1.0);
  83.             glBegin(GL_TRIANGLE_FAN);
  84.                 glColor3fv(colors[0]);
  85.                 glVertex3fv(verts[0]);
  86.                 glColor3fv(colors[1]);
  87.                 glVertex3fv(verts[1]);
  88.                 glColor3fv(colors[2]);
  89.                 glVertex3fv(verts[2]);
  90.                 glColor3fv(colors[3]);
  91.                 glVertex3fv(verts[3]);
  92.                 glColor3fv(colors[4]);
  93.                 glVertex3fv(verts[4]);
  94.                 glColor3fv(colors[1]);
  95.                 glVertex3fv(verts[1]);
  96.             glEnd();
  97.             glBegin(GL_TRIANGLE_FAN);
  98.                 glColor3fv(colors[5]);
  99.                 glVertex3fv(verts[5]);
  100.                 glColor3fv(colors[1]);
  101.                 glVertex3fv(verts[1]);
  102.                 glColor3fv(colors[4]);
  103.                 glVertex3fv(verts[4]);
  104.                 glColor3fv(colors[3]);
  105.                 glVertex3fv(verts[3]);
  106.                 glColor3fv(colors[2]);
  107.                 glVertex3fv(verts[2]);
  108.                   glVertex3fv(verts[1]);
  109.             glEnd();
  110.             glPopMatrix();
  111.             pglSwapBuffers(habProgram, hwnd);
  112.         return(0);
  113.  
  114.         
  115.         case UM_KILL_SAVER:
  116.             pglMakeCurrent(habProgram, NULL, None);
  117.             pglDestroyContext(habProgram, HglContext);
  118.             free(PVisConfig);
  119.         return(0);
  120.     }
  121.     return OldSaverProc(hwnd, msg, mp1, mp2);
  122. }
  123.  
  124.  
  125. MRESULT EXPENTRY __export SetupProc(HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  126. {
  127.     WinMessageBox(HWND_DESKTOP, hwnd, "There is nothing to set for this module", "WPSaver", 0, MB_OK|MB_ICONEXCLAMATION);
  128.         if(!WinQueryWindowPtr(hwnd, 0))
  129.             exit(0);
  130.     return WinDefDlgProc(hwnd, msg, mp1, mp2);
  131. }
  132.