home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 February / Chip_2001-02_cd1.bin / bonus / demos / CS / exp / SOURCES / DEMO / MAIN.CPP < prev    next >
C/C++ Source or Header  |  2000-08-20  |  5KB  |  225 lines

  1. #include <windows.h>
  2. #include <mmsystem.h>
  3. #include <cstdlib>
  4. #include <cstdio>
  5. #include <conio.h>
  6. #include <cmath>
  7. #include <iostream>
  8. #include <fcntl.h>
  9. #include <string.h>
  10.  
  11. #include "bass.h"
  12. #include "timer.h"
  13. #include "demo.h"
  14. #include "api3ds.h"
  15. #include "syncname.h"
  16. #include "efekt.h"
  17.  
  18. /*
  19.  * ak je premenna prepisovatelna zvonka, mala by byt deklarovana ako volatile.
  20.  * tym je prekladac upozorneny, ze nema jej ulozenie/pracu s nou optimalizovat.
  21.  * spominam si, ze toto bol znamy zdroj bugov pri starsich verziach midasu.
  22.  */
  23. volatile BOOL clear_zbuffer=TRUE;  // aby mohol efekt vypnut mazanie obrazovky
  24. volatile BOOL clear_cbuffer=TRUE;  // nastavi si extern...
  25. volatile BOOL usefog;
  26.  
  27. Texture3DS *loading;
  28. bool showlogo=true;
  29.  
  30. Textures3DS *EFEKT::texture_library=0;
  31.  
  32. /*
  33.  * config
  34.  */
  35. int       resx, resy, bpp;
  36. BOOL      fullscreen;
  37.  
  38. /*
  39.  * path to music stream
  40.  */
  41. #define module_name_na_fest "data\\mp3\\expiration.mp3"
  42. char module_name[40];
  43. int na_fest=0;
  44.  
  45. char*     className = "Peon demo";
  46. char*     windowName= "Expiration";
  47.  
  48. HDC             hDC=NULL;               // Private GDI Device Context
  49. HGLRC           hRC=NULL;               // Permanent Rendering Context
  50. HWND            hWnd=NULL;              // Holds Our Window Handle
  51. HINSTANCE       hInstance;              // Holds The Instance Of The Application
  52.  
  53. void display(void)
  54. {
  55.    glFlush();
  56.    glFinish();
  57.    SwapBuffers(hDC);
  58.    if (clear_zbuffer&&clear_cbuffer)
  59.      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  60.    else {
  61.      if (clear_zbuffer) glClear(GL_DEPTH_BUFFER_BIT);
  62.      if (clear_cbuffer) glClear(GL_COLOR_BUFFER_BIT);
  63.      }
  64. }
  65.  
  66. int InitGL(GLvoid)
  67. {
  68.   InitOpenGLExtensions();
  69.   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
  70.   glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
  71.   return TRUE;
  72. }
  73.  
  74. #include "init_win.h"
  75. #include "init_bas.h"
  76.  
  77. void drawlogo()
  78. {
  79.   glClearColor(0.0,0.0,0.0,1.0);
  80.  
  81.   loading->GL();
  82.   glMatrixMode(GL_PROJECTION);
  83.   glLoadIdentity();
  84.   glMatrixMode(GL_MODELVIEW);
  85.   glLoadIdentity();
  86.   glEnable(GL_TEXTURE_2D);
  87.   glDisable(GL_LIGHTING);
  88.   glDisable(GL_CULL_FACE);
  89.   glDisable(GL_BLEND);
  90.   glDisable(GL_DEPTH_TEST);
  91.  
  92.   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  93.   glBegin(GL_QUADS);
  94.     glColor3f(1.0,1.0,1.0);
  95.     glTexCoord2f( 1.0, 1.0);
  96.     glVertex2f  (-0.5,-0.8);
  97.     glTexCoord2f( 1.0, 0.0);
  98.     glVertex2f  (-0.5,-1.0); 
  99.     glTexCoord2f( 0.0, 0.0);
  100.     glVertex2f  (-0.9,-1.0);
  101.     glTexCoord2f( 0.0, 1.0);
  102.     glVertex2f  (-0.9,-0.8);
  103.   glEnd();
  104.  
  105. }
  106.  
  107. int APIENTRY
  108. WinMain(
  109.     HINSTANCE hCurrentInst,
  110.     HINSTANCE hPreviousInst,
  111.     LPSTR lpszCmdLine,
  112.     int nCmdShow)
  113. {
  114.  
  115.   //create texture library
  116.   EFEKT::texture_library=new Textures3DS;
  117.   Loader3DS::buffer=new char[1024*1024];
  118.  
  119.   // random generator init
  120.   __int64  t;
  121.   QueryPerformanceCounter((LARGE_INTEGER*)&t);
  122.   t=-627438984;//3667528312
  123.   srand((int)t);
  124.  
  125.  
  126.   if(!DialogBox(hCurrentInst,MAKEINTRESOURCE(1000),0,&dialogproc)) return 0;
  127.  
  128.   float demo_start;
  129.   DWORD hudba_start;
  130.  
  131.   FILE *stream=fopen("demo.cfg","r");
  132.   if (stream) 
  133.     {
  134.     fscanf(stream,"hudba start   %i\n",&hudba_start);
  135.     fscanf(stream,"demo  start   %f\n",&demo_start);
  136.     fclose(stream);
  137.     }
  138.    else
  139.     {
  140.     hudba_start=0;
  141.     demo_start=0.0;
  142.     }
  143.  
  144.   stream=fopen("music.cfg","r");
  145.   if (stream) 
  146.     {
  147.     fscanf(stream,"%s\n",module_name);
  148.     fclose(stream);
  149.     }
  150.   else na_fest=1;
  151.  
  152.   if (!CreateGLWindow(windowName,resx,resy,bpp,fullscreen))
  153.   {
  154.     cout<<"createwindow failed"<<endl;
  155.     return 0;
  156.   }
  157.  
  158.   Textures3DS *texlib=EFEKT::texture_library;
  159.   loading=texlib->GetOrCreate("LOADING.JPG");
  160.   drawlogo();
  161.   glFlush();
  162.   glFinish();
  163.   SwapBuffers(hDC);
  164.  
  165.  
  166.   BOOL progress=demo_init();
  167.   BOOL nomusic=0;  // nastavi sa na 1 ak nedoslo k spusteniu hudby
  168.  
  169.  
  170.   if (!progress) {
  171.     MessageBox(NULL,"DemoInit failed!","ERROR",MB_OK|MB_ICONEXCLAMATION);
  172.     nomusic=1;
  173.     }
  174.    else
  175.     if (!za_malo_penazi_vela_muziky()) {
  176.       MessageBox(NULL,"MusicInit failed!","ERROR",MB_OK|MB_ICONEXCLAMATION);
  177.       nomusic=1;
  178.     }
  179.  
  180.   MSG msg;
  181.   PTIMER timer;
  182.   cout << endl << endl << endl << "DEMO:" << endl << endl;
  183.   BASS_ChannelSetPosition((unsigned int)str,hudba_start);
  184.   timer.reset(demo_start);
  185.   bool space_pressed=false;
  186.   while (progress) {
  187.      while (progress&&(PeekMessage(&msg, hWnd, 0, 0, PM_NOREMOVE) == FALSE))
  188.        {
  189.        if (key[VK_SPACE]&&!space_pressed)
  190.          {
  191.          cout << "hudba start   "<< BASS_ChannelGetPosition((unsigned int)str) << endl;
  192.          cout << "demo  start   " << timer.time() << endl;
  193.          space_pressed=true;
  194.          }
  195.        if (!key[VK_SPACE]) space_pressed=false;
  196.  
  197.        progress=demo_go(timer.time());
  198.        if (key[VK_ESCAPE]) progress=0;
  199.        if (progress)
  200.          {
  201.          if (showlogo) drawlogo();
  202.          display();
  203.          }
  204.       }
  205.      if (!progress) SendMessage(hWnd,WM_CLOSE,0,0);
  206.      if (GetMessage(&msg, hWnd, 0, 0) != TRUE) break;
  207.      TranslateMessage(&msg);
  208.      DispatchMessage(&msg);
  209.      }
  210.  
  211.   KillGLWindow();
  212.   if (!nomusic)
  213.     {
  214.     for (int a=100;a>=0;a-=1)
  215.       {
  216.       BASS_SetVolume(a);
  217.       Sleep(5);
  218.       }
  219.     BASS_Free();
  220.     }
  221.   cout << "Random seed: " << (int)t << endl;
  222. //  delete EFEKT::texture_library;
  223.   return (msg.wParam);
  224. }
  225.