SHARE
TWEET

asdf

gerys May 21st, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma comment(lib,"opengl32.lib")
  2. #pragma comment(lib,"glu32.lib")
  3.  
  4. #include <windows.h>
  5. #include <math.h>
  6. #include <GL/gl.h>
  7. #include <GL/glu.h>
  8.  
  9. #include "cone.h"
  10. #include "car.h"
  11. #include "car_notire.h"
  12. #include "rodafix.h"
  13.  
  14. /* Windows globals, defines, and prototypes */
  15. CHAR szAppName[]="Win OpenGL";
  16. HWND  ghWnd;
  17. HDC   ghDC;
  18. HGLRC ghRC;
  19.  
  20. #define SWAPBUFFERS SwapBuffers(ghDC)
  21. #define BLACK_INDEX     0
  22. #define RED_INDEX       13
  23. #define GREEN_INDEX     14
  24. #define BLUE_INDEX      16
  25. #define WIDTH           600
  26. #define HEIGHT          600
  27.  
  28. LONG WINAPI MainWndProc (HWND, UINT, WPARAM, LPARAM);
  29. BOOL bSetupPixelFormat(HDC);
  30.  
  31. /* OpenGL globals, defines, and prototypes */
  32. GLfloat latitude, longitude, latinc, longinc;
  33. GLdouble radius;
  34.  
  35. #define GLOBE    1
  36. #define CYLINDER 2
  37. #define CONE     3
  38.  
  39.  
  40. void DrawScene();
  41. void SetupScene();
  42. void UpdateScene();
  43. void resize( int width, int height );
  44. void MouseMove(HWND h);
  45. void Up();
  46. void Back();
  47. void left();
  48. void right();
  49.  
  50. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  51. {
  52.     MSG        msg;
  53.     WNDCLASS   wndclass;
  54.  
  55.     /* Register the frame class */
  56.     wndclass.style         = 0;
  57.     wndclass.lpfnWndProc   = (WNDPROC)MainWndProc;
  58.     wndclass.cbClsExtra    = 0;
  59.     wndclass.cbWndExtra    = 0;
  60.     wndclass.hInstance     = hInstance;
  61.     wndclass.hIcon         = LoadIcon (hInstance, szAppName);
  62.     wndclass.hCursor       = LoadCursor (NULL,IDC_ARROW);
  63.     wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  64.     wndclass.lpszMenuName  = szAppName;
  65.     wndclass.lpszClassName = szAppName;
  66.  
  67.     if (!RegisterClass (&wndclass) )
  68.         return FALSE;
  69.  
  70.     /* Create the frame */
  71.     ghWnd = CreateWindow (szAppName,
  72.              "OpenGL",
  73.          WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
  74.              CW_USEDEFAULT,
  75.              CW_USEDEFAULT,
  76.              WIDTH,
  77.              HEIGHT,
  78.              NULL,
  79.              NULL,
  80.              hInstance,
  81.              NULL);
  82.  
  83.     /* make sure window was created */
  84.     if (!ghWnd)
  85.         return FALSE;
  86.  
  87.     /* show and update main window */
  88.     ShowWindow (ghWnd, nCmdShow);
  89.  
  90.     UpdateWindow (ghWnd);
  91.  
  92.     /* animation loop */
  93.     while (1) {
  94.         /*
  95.          *  Process all pending messages
  96.          */
  97.  
  98.         while (PeekMessage(&msg, NULL, 1, 1, PM_NOREMOVE) == TRUE)
  99.         {
  100.             if (GetMessage(&msg, NULL, 1,1) )
  101.             {
  102.                 TranslateMessage(&msg);
  103.                 DispatchMessage(&msg);
  104.             } else {
  105.                 return TRUE;
  106.             }
  107.         }
  108.         DrawScene();
  109.         UpdateScene();
  110.     }
  111. }
  112.  
  113. /* main window procedure */
  114. RECT rect, wrect;
  115. POINT oldpos;
  116.  
  117. LONG WINAPI MainWndProc (
  118.     HWND    hWnd,
  119.     UINT    uMsg,
  120.     WPARAM  wParam,
  121.     LPARAM  lParam)
  122. {
  123.     LONG    lRet = 1;
  124.     PAINTSTRUCT    ps;
  125.  
  126.     switch (uMsg) {
  127.  
  128.     case WM_CREATE:
  129.         ghDC = GetDC(hWnd);
  130.         if (!bSetupPixelFormat(ghDC))
  131.             PostQuitMessage (0);
  132.         ghRC = wglCreateContext(ghDC);
  133.         wglMakeCurrent(ghDC, ghRC);
  134.         GetWindowRect(hWnd, &wrect);
  135.         SetupScene();
  136.         break;
  137.  
  138.     case WM_PAINT:
  139.         BeginPaint(hWnd, &ps);
  140.         EndPaint(hWnd, &ps);
  141.         break;
  142.  
  143.      case WM_CLOSE:
  144.         if (ghRC)
  145.             wglDeleteContext(ghRC);
  146.         if (ghDC)
  147.             ReleaseDC(hWnd, ghDC);
  148.         ghRC = 0;
  149.         ghDC = 0;
  150.  
  151.         DestroyWindow (hWnd);
  152.         break;
  153.  
  154.     case WM_DESTROY:
  155.         if (ghRC)
  156.             wglDeleteContext(ghRC);
  157.         if (ghDC)
  158.             ReleaseDC(hWnd, ghDC);
  159.  
  160.         PostQuitMessage (0);
  161.         break;
  162.      
  163.     case WM_SIZE:
  164.         GetClientRect(hWnd, &rect);
  165.         resize(rect.right, rect.bottom);
  166.         GetWindowRect(hWnd, &wrect);
  167.         break;
  168.  
  169.     case WM_KEYDOWN:
  170.         switch (wParam) {
  171.         case VK_ESCAPE:
  172.             exit(0);
  173.             break;
  174.         case VK_UP:
  175.             Up();
  176.             break;
  177.         case UINT('W'):
  178.             Up();
  179.             break;
  180.         case UINT('S'):
  181.             Back();
  182.             break;
  183.         case UINT('D'):
  184.             right();
  185.             break;
  186.         case UINT('A'):
  187.             left();
  188.             break;
  189.  
  190.         }
  191.  
  192.     case WM_MOUSEMOVE:
  193.         MouseMove(hWnd);
  194.         break;
  195.  
  196.     default:
  197.         lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
  198.         break;
  199.     }
  200.  
  201.     return lRet;
  202. }
  203.  
  204. BOOL bSetupPixelFormat(HDC hdc)
  205. {
  206.     PIXELFORMATDESCRIPTOR pfd, *ppfd;
  207.     int pixelformat;
  208.  
  209.     ppfd = &pfd;
  210.  
  211.     ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
  212.     ppfd->nVersion = 1;
  213.     ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |  
  214.                         PFD_DOUBLEBUFFER;
  215.     ppfd->dwLayerMask = PFD_MAIN_PLANE;
  216.     ppfd->iPixelType = PFD_TYPE_COLORINDEX;
  217.     ppfd->cColorBits = 8;
  218.     ppfd->cDepthBits = 16;
  219.     ppfd->cAccumBits = 0;
  220.     ppfd->cStencilBits = 0;
  221.  
  222.     pixelformat = ChoosePixelFormat(hdc, ppfd);
  223.  
  224.     if ( (pixelformat = ChoosePixelFormat(hdc, ppfd)) == 0 )
  225.     {
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top