Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma comment(lib,"opengl32.lib")
- #pragma comment(lib,"glu32.lib")
- #include <windows.h>
- #include <math.h>
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include "cone.h"
- #include "car.h"
- #include "car_notire.h"
- #include "rodafix.h"
- /* Windows globals, defines, and prototypes */
- CHAR szAppName[]="Win OpenGL";
- HWND ghWnd;
- HDC ghDC;
- HGLRC ghRC;
- #define SWAPBUFFERS SwapBuffers(ghDC)
- #define BLACK_INDEX 0
- #define RED_INDEX 13
- #define GREEN_INDEX 14
- #define BLUE_INDEX 16
- #define WIDTH 600
- #define HEIGHT 600
- LONG WINAPI MainWndProc (HWND, UINT, WPARAM, LPARAM);
- BOOL bSetupPixelFormat(HDC);
- /* OpenGL globals, defines, and prototypes */
- GLfloat latitude, longitude, latinc, longinc;
- GLdouble radius;
- #define GLOBE 1
- #define CYLINDER 2
- #define CONE 3
- void DrawScene();
- void SetupScene();
- void UpdateScene();
- void resize( int width, int height );
- void MouseMove(HWND h);
- void Up();
- void Back();
- void left();
- void right();
- int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- MSG msg;
- WNDCLASS wndclass;
- /* Register the frame class */
- wndclass.style = 0;
- wndclass.lpfnWndProc = (WNDPROC)MainWndProc;
- wndclass.cbClsExtra = 0;
- wndclass.cbWndExtra = 0;
- wndclass.hInstance = hInstance;
- wndclass.hIcon = LoadIcon (hInstance, szAppName);
- wndclass.hCursor = LoadCursor (NULL,IDC_ARROW);
- wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wndclass.lpszMenuName = szAppName;
- wndclass.lpszClassName = szAppName;
- if (!RegisterClass (&wndclass) )
- return FALSE;
- /* Create the frame */
- ghWnd = CreateWindow (szAppName,
- "OpenGL",
- WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
- CW_USEDEFAULT,
- CW_USEDEFAULT,
- WIDTH,
- HEIGHT,
- NULL,
- NULL,
- hInstance,
- NULL);
- /* make sure window was created */
- if (!ghWnd)
- return FALSE;
- /* show and update main window */
- ShowWindow (ghWnd, nCmdShow);
- UpdateWindow (ghWnd);
- /* animation loop */
- while (1) {
- /*
- * Process all pending messages
- */
- while (PeekMessage(&msg, NULL, 1, 1, PM_NOREMOVE) == TRUE)
- {
- if (GetMessage(&msg, NULL, 1,1) )
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- } else {
- return TRUE;
- }
- }
- DrawScene();
- UpdateScene();
- }
- }
- /* main window procedure */
- RECT rect, wrect;
- POINT oldpos;
- LONG WINAPI MainWndProc (
- HWND hWnd,
- UINT uMsg,
- WPARAM wParam,
- LPARAM lParam)
- {
- LONG lRet = 1;
- PAINTSTRUCT ps;
- switch (uMsg) {
- case WM_CREATE:
- ghDC = GetDC(hWnd);
- if (!bSetupPixelFormat(ghDC))
- PostQuitMessage (0);
- ghRC = wglCreateContext(ghDC);
- wglMakeCurrent(ghDC, ghRC);
- GetWindowRect(hWnd, &wrect);
- SetupScene();
- break;
- case WM_PAINT:
- BeginPaint(hWnd, &ps);
- EndPaint(hWnd, &ps);
- break;
- case WM_CLOSE:
- if (ghRC)
- wglDeleteContext(ghRC);
- if (ghDC)
- ReleaseDC(hWnd, ghDC);
- ghRC = 0;
- ghDC = 0;
- DestroyWindow (hWnd);
- break;
- case WM_DESTROY:
- if (ghRC)
- wglDeleteContext(ghRC);
- if (ghDC)
- ReleaseDC(hWnd, ghDC);
- PostQuitMessage (0);
- break;
- case WM_SIZE:
- GetClientRect(hWnd, &rect);
- resize(rect.right, rect.bottom);
- GetWindowRect(hWnd, &wrect);
- break;
- case WM_KEYDOWN:
- switch (wParam) {
- case VK_ESCAPE:
- exit(0);
- break;
- case VK_UP:
- Up();
- break;
- case UINT('W'):
- Up();
- break;
- case UINT('S'):
- Back();
- break;
- case UINT('D'):
- right();
- break;
- case UINT('A'):
- left();
- break;
- }
- case WM_MOUSEMOVE:
- MouseMove(hWnd);
- break;
- default:
- lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
- break;
- }
- return lRet;
- }
- BOOL bSetupPixelFormat(HDC hdc)
- {
- PIXELFORMATDESCRIPTOR pfd, *ppfd;
- int pixelformat;
- ppfd = &pfd;
- ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
- ppfd->nVersion = 1;
- ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
- PFD_DOUBLEBUFFER;
- ppfd->dwLayerMask = PFD_MAIN_PLANE;
- ppfd->iPixelType = PFD_TYPE_COLORINDEX;
- ppfd->cColorBits = 8;
- ppfd->cDepthBits = 16;
- ppfd->cAccumBits = 0;
- ppfd->cStencilBits = 0;
- pixelformat = ChoosePixelFormat(hdc, ppfd);
- if ( (pixelformat = ChoosePixelFormat(hdc, ppfd)) == 0 )
- {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement