#include <windows.h>
#include "shared.h"
#include "general.h"
#include "vector.h"
#include "vertex.h"
#include "quat.h"
#include "matrix.h"
#include "texture.h"
#include "locmath.h"
#include "polygon.h"
#include "mmgr.h"
#include "resource.rh"
Go to the source code of this file.
Defines | |
#define | IDI_MYICON 101 |
Functions | |
void | InitGL (int Width, int Height) |
void | ReSizeGLScene (int Width, int Height) |
void | DrawGLScene (void) |
LRESULT CALLBACK | WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
int WINAPI | WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) |
Variables | |
HGLRC | hRC |
HDC | hDC |
HWND | hWnd |
RECT | screen |
PAINTSTRUCT | ps |
bool | key [256] |
bool | released_key [256] |
float | pi = 3.141592 |
float | radian = pi / 180 |
TEXTURE * | texture = new TEXTURE[1] |
POLYGON * | polygon = new POLYGON[12] |
|
|
|
Definition at line 54 of file main.cpp. References DrawCone(), DrawCube(), DrawGrid(), and DrawSphere(). Referenced by WinMain().
|
|
Definition at line 39 of file main.cpp. References SetGLLighting(), SetGLMaterial(), SetGLProperties(), SetGLScene(), SetGLTexture(), and SetGLView(). Referenced by WndProc().
00040 { 00041 SetGLProperties(); 00042 SetGLMaterial(); 00043 SetGLLighting(); 00044 SetGLView(Width, Height); 00045 SetGLScene(polygon); 00046 SetGLTexture(texture); 00047 } |
|
Definition at line 49 of file main.cpp. References SetGLView(). Referenced by WndProc().
00050 { 00051 SetGLView(Width, Height); 00052 } |
|
Definition at line 181 of file main.cpp. References DrawGLScene(), hDC, hRC, hWnd, key, screen, and WndProc().
00185 { 00186 MSG msg; // Windows Message Structure 00187 WNDCLASSEX wc; // Windows Class Structure Used To Set Up The Type Of Window 00188 00189 GetWindowRect(GetDesktopWindow(), &screen); 00190 wc.cbSize = sizeof(WNDCLASSEX); 00191 wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_SAVEBITS; 00192 wc.lpfnWndProc = (WNDPROC) WndProc; 00193 wc.cbClsExtra = 0; 00194 wc.cbWndExtra = 0; 00195 wc.hInstance = hInstance; 00196 wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON)); 00197 wc.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON)); 00198 wc.hCursor = LoadCursor(NULL, IDC_ARROW); 00199 wc.hbrBackground = NULL; 00200 wc.lpszMenuName = NULL; 00201 wc.lpszClassName = "OpenGL WinClass"; 00202 00203 00204 if(!RegisterClassEx(&wc)) 00205 { 00206 MessageBox(0,"Failed To Register The Window Class.","Error",MB_OK|MB_ICONERROR); 00207 return FALSE; 00208 } 00209 00210 hWnd = CreateWindowEx( 00211 WS_EX_LEFT, 00212 "OpenGL WinClass", 00213 "OpenGL & Win32 Tutorial No.1", // Title Appearing At The Top Of The Window 00214 00215 WS_MAXIMIZE | 00216 WS_CLIPCHILDREN | 00217 WS_CLIPSIBLINGS | 00218 WS_POPUPWINDOW | 00219 WS_VISIBLE, 00220 0, 0, // The Position Of The Window On The Screen 00221 screen.right, screen.bottom, // The Width And Height Of The WIndow 00222 NULL, 00223 NULL, 00224 hInstance, 00225 NULL); 00226 00227 if(!hWnd) 00228 { 00229 MessageBox(0,"Window Creation Error.","Error",MB_OK|MB_ICONERROR); 00230 return FALSE; 00231 } 00232 00233 DEVMODE dmScreenSettings; // Developer Mode 00234 00235 memset(&dmScreenSettings, 0, sizeof(DEVMODE)); // Clear Room To Store Settings 00236 dmScreenSettings.dmSize = sizeof(DEVMODE); // Size Of The Devmode Structure 00237 dmScreenSettings.dmPelsWidth = screen.right; // Screen Width 00238 dmScreenSettings.dmPelsHeight = screen.bottom; // Screen Height 00239 dmScreenSettings.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT; // Pixel Mode 00240 ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN); // Switch To Full Screen 00241 00242 ShowWindow(hWnd, SW_SHOW); 00243 UpdateWindow(hWnd); 00244 SetFocus(hWnd); 00245 wglMakeCurrent(hDC,hRC); 00246 00247 while (1) 00248 { 00249 // Process All Messages 00250 while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) 00251 { 00252 if (GetMessage(&msg, NULL, 0, 0)) 00253 { 00254 TranslateMessage(&msg); 00255 DispatchMessage(&msg); 00256 } 00257 else 00258 { 00259 return TRUE; 00260 } 00261 } 00262 00263 DrawGLScene(); // Draw The Scene 00264 glFlush(); // Block the program until cached rendering commands are complete 00265 SwapBuffers(hDC); // Swap Screen Buffers 00266 00267 if (key[VK_ESCAPE]) 00268 SendMessage(hWnd,WM_CLOSE,0,0); 00269 } 00270 } |
|
Definition at line 63 of file main.cpp. References hDC, hRC, hWnd, InitGL(), key, ReSizeGLScene(), and screen. Referenced by WinMain().
00067 { 00068 GLuint PixelFormat; 00069 static PIXELFORMATDESCRIPTOR pfd= 00070 { 00071 sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 00072 1, // Version Number (?) 00073 PFD_DRAW_TO_WINDOW | // Format Must Support Window 00074 PFD_SUPPORT_OPENGL | // Format Must Support OpenGL 00075 PFD_DOUBLEBUFFER, // Must Support Double Buffering 00076 PFD_TYPE_RGBA, // Request An RGBA Format 00077 16, // Select A 16Bit Color Depth 00078 0, 0, 0, 0, 0, 0, // Color Bits Ignored (?) 00079 0, // No Alpha Buffer 00080 0, // Shift Bit Ignored (?) 00081 0, // No Accumulation Buffer 00082 0, 0, 0, 0, // Accumulation Bits Ignored (?) 00083 16, // 16Bit Z-Buffer (Depth Buffer) 00084 0, // No Stencil Buffer 00085 0, // No Auxiliary Buffer (?) 00086 PFD_MAIN_PLANE, // Main Drawing Layer 00087 0, // Reserved (?) 00088 0, 0, 0 // Layer Masks Ignored (?) 00089 }; 00090 00091 00092 switch (message) // Tells Windows We Want To Check The Message 00093 { 00094 case WM_CREATE: 00095 hDC = GetDC(hWnd); // Gets A Device Context For The Window 00096 00097 PixelFormat = ChoosePixelFormat(hDC, &pfd); // Finds The Closest Match To The Pixel Format We Set Above 00098 00099 if (!PixelFormat) 00100 { 00101 MessageBox(0,"Can't Find A Suitable PixelFormat.","Error",MB_OK|MB_ICONERROR); 00102 PostQuitMessage(0); // This Sends A 'Message' Telling The Program To Quit 00103 break; // Prevents The Rest Of The Code From Running 00104 } 00105 00106 if(!SetPixelFormat(hDC,PixelFormat,&pfd)) 00107 { 00108 MessageBox(0,"Can't Set The PixelFormat.","Error",MB_OK|MB_ICONERROR); 00109 PostQuitMessage(0); 00110 break; 00111 } 00112 00113 hRC = wglCreateContext(hDC); 00114 if(!hRC) 00115 { 00116 MessageBox(0,"Can't Create A GL Rendering Context.","Error",MB_OK|MB_ICONERROR); 00117 PostQuitMessage(0); 00118 break; 00119 } 00120 00121 if(!wglMakeCurrent(hDC, hRC)) 00122 { 00123 MessageBox(0,"Can't activate GLRC.","Error",MB_OK|MB_ICONERROR); 00124 PostQuitMessage(0); 00125 break; 00126 } 00127 InitGL(screen.right, screen.bottom); 00128 break; 00129 00130 case WM_SYSCOMMAND: // Intercept System Commands 00131 { 00132 switch (wParam) // Check System Calls 00133 { 00134 case SC_SCREENSAVE: // Screensaver Trying To Start? 00135 case SC_MONITORPOWER: // Monitor Trying To Enter Powersave? 00136 return 0; // Prevent From Happening 00137 } 00138 break; // Exit 00139 } 00140 00141 // This WM_PAINT msg handler will be required when dialog windows are used 00142 /* 00143 case WM_PAINT: 00144 BeginPaint(hWnd,&ps); 00145 DrawGLScene(); 00146 glFlush(); 00147 SwapBuffers(hDC); 00148 EndPaint(hWnd,&ps); 00149 break; 00150 */ 00151 case WM_DESTROY: 00152 case WM_CLOSE: 00153 delete[] texture; 00154 delete[] polygon; 00155 00156 ChangeDisplaySettings(NULL, 0); 00157 wglMakeCurrent(hDC,NULL); 00158 wglDeleteContext(hRC); 00159 ReleaseDC(hWnd,hDC); 00160 PostQuitMessage(0); 00161 break; 00162 00163 case WM_KEYDOWN: 00164 key[wParam] = TRUE; 00165 break; 00166 00167 case WM_KEYUP: 00168 key[wParam] = FALSE; 00169 break; 00170 00171 case WM_SIZE: 00172 ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); 00173 break; 00174 00175 default: 00176 return (DefWindowProc(hWnd, message, wParam, lParam)); 00177 } 00178 return (0); 00179 } |
|
|
|
|
|
|
|
|
|
|
|
Definition at line 37 of file main.cpp. Referenced by DrawCube(), and SetGLScene(). |
|
|
|
|
|
|
|
|
|
Definition at line 34 of file main.cpp. Referenced by DrawCube(), and SetGLTexture(). |