[Clean] Tab formatting cleanup.. again......

This commit is contained in:
Rtch90 2012-04-07 01:23:17 +01:00
parent d557c1ae30
commit 8834fcc762

View File

@ -10,75 +10,75 @@ typedef HGLRC(APIENTRYP PFNWGLCREATECONTEXTATTRIBSARBPROC)(HDC, HGLRC, const int
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = NULL; PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = NULL;
GLWindow::GLWindow(HINSTANCE hInstance) : GLWindow::GLWindow(HINSTANCE hInstance) :
_isRunning(false), _isRunning(false),
_game(NULL), _game(NULL),
_hinstance(hInstance), _hinstance(hInstance),
_lastTime(0) _lastTime(0)
{} {}
bool GLWindow::Create(int width, int height, int bpp, bool fullscreen) { bool GLWindow::Create(int width, int height, int bpp, bool fullscreen) {
DWORD dwExStyle; // Window extended style. DWORD dwExStyle; // Window extended style.
DWORD dwStyle; // Window style. DWORD dwStyle; // Window style.
_isFullscreen = fullscreen; // Store the fullscreen flag. _isFullscreen = fullscreen; // Store the fullscreen flag.
_windowRect.left = (long)0; // Set left value to zero. _windowRect.left = (long)0; // Set left value to zero.
_windowRect.right = (long)width; // Set right value to the requested width. _windowRect.right = (long)width; // Set right value to the requested width.
_windowRect.top = (long)0; // Set top value to zero. _windowRect.top = (long)0; // Set top value to zero.
_windowRect.bottom = (long)height; // Set bottom value to the requested height. _windowRect.bottom = (long)height; // Set bottom value to the requested height.
// Fill out the class structure. // Fill out the class structure.
_windowClass.cbSize = sizeof(WNDCLASSEX); _windowClass.cbSize = sizeof(WNDCLASSEX);
_windowClass.style = CS_HREDRAW | CS_VREDRAW; _windowClass.style = CS_HREDRAW | CS_VREDRAW;
_windowClass.lpfnWndProc = GLWindow::StaticWNDProc; // Set out static method as the next event. _windowClass.lpfnWndProc = GLWindow::StaticWNDProc; // Set out static method as the next event.
_windowClass.cbClsExtra = 0; _windowClass.cbClsExtra = 0;
_windowClass.cbWndExtra = 0; _windowClass.cbWndExtra = 0;
_windowClass.hInstance = _hinstance; _windowClass.hInstance = _hinstance;
_windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); // Default icon. _windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); // Default icon.
_windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); // Default arrow. _windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); // Default arrow.
_windowClass.hbrBackground = NULL; // Don't need a background. _windowClass.hbrBackgroun = NULL; // Don't need a background.
_windowClass.lpszMenuName = NULL; // No menu. _windowClass.lpszMenuName = NULL; // No menu.
_windowClass.lpszClassName = "LibD"; _windowClass.lpszClassName = "LibD";
_windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO); // Windows logo, small icon. _windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO); // Windows logo, small icon.
// Register the window class. // Register the window class.
if(!RegisterClassEx(&_windowClass)) { if(!RegisterClassEx(&_windowClass)) {
return false; return false;
} }
if(_isFullscreen) { if(_isFullscreen) {
// Then we need to change the display mode. // Then we need to change the display mode.
DEVMODE dmScreenSettings; // Device mode. DEVMODE dmScreenSettings; // Device mode.
memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
dmScreenSettings.dmSize = sizeof(dmScreenSettings); dmScreenSettings.dmSize = sizeof(dmScreenSettings);
dmScreenSettings.dmPellsWidth = width; // Screen width. dmScreenSettings.dmPellsWidth = width; // Screen width.
dmScreenSettings.dmPellsHeight = height; // Screen height. dmScreenSettings.dmPellsHeight = height; // Screen height.
dmScreenSettings.dmBitsPerPel = bpp; // Bits per pixel. dmScreenSettings.dmBitsPerPel = bpp; // Bits per pixel.
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
if(ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { if(ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) {
// Setting the display mode failed, so switch to windowed mode. // Setting the display mode failed, so switch to windowed mode.
MessageBox(NULL, "Display mode failed", NULL, MB_OK); MessageBox(NULL, "Display mode failed", NULL, MB_OK);
_isFullscreen = false; _isFullscreen = false;
} }
} }
// Are we still in fullscreen mode? // Are we still in fullscreen mode?
if(_isFullscreen) { if(_isFullscreen) {
dwExStyle = WS_EX_APPWINDOW; // Window extended style. dwExStyle = WS_EX_APPWINDOW; // Window extended style.
dwStyle = WS_POPUP; // Windows style. dwStyle = WS_POPUP; // Windows style.
ShowCursor(false); // Might as well hide the mouse cursor. ShowCursor(false); // Might as well hide the mouse cursor.
} else { } else {
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window extended style. dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window extended style.
dwStyle = WS_OVERLAPPEDWINDOW; // Windows style. dwStyle = WS_OVERLAPPEDWINDOW; // Windows style.
} }
AdjustWindowRectEx(&_windowRect, dwStyle, false, dwExStyle); // Adjust window to true requested size. AdjustWindowRectEx(&_windowRect, dwStyle, false, dwExStyle); // Adjust window to true requested size.
// The class is registered, so now we can create our window. // The class is registered, so now we can create our window.
_hwnd = CreateWindowEx(NULL, "GLClass", "LibD", dwStyle, | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, _hwnd = CreateWindowEx(NULL, "GLClass", "LibD", dwStyle, | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
0, 0, _windowRect.right - _windowRect.left, 0, 0, _windowRect.right - _windowRect.left,
_windowRect.bottom - _windowRect.top, NULL, NULL, _hinstance, this); _windowRect.bottom - _windowRect.top, NULL, NULL, _hinstance, this);
// Check if the window creation failed - hwnd would be NULL. // Check if the window creation failed - hwnd would be NULL.
if(!_hwnd) if(!_hwnd)
@ -86,10 +86,10 @@ bool GLWindow::Create(int width, int height, int bpp, bool fullscreen) {
_hdc = GetDC(_hwnd); _hdc = GetDC(_hwnd);
ShowWindow(_hwnd, SW_SHOW); // Display the window. ShowWindow(_hwnd, SW_SHOW); // Display the window.
UpdateWindow(_hwnd); // Update the window. UpdateWindow(_hwnd); // Update the window.
_lastTime = GetTickCount() / 1000.0f; // Initialize the time. _lastTime = GetTickCount() / 1000.0f; // Initialize the time.
return true; return true;
} }
@ -97,7 +97,7 @@ void GLWindow::Destroy(void) {
if(_isFullscreen) { if(_isFullscreen) {
// Change back to the desktop. // Change back to the desktop.
ChangeDisplaySettings(NULL, 0); ChangeDisplaySettings(NULL, 0);
ShowCursor(true); // Show us the mouse cursor again. ShowCursor(true); // Show us the mouse cursor again.
} }
} }
@ -116,24 +116,24 @@ void GLWindow::SetPixelFormat(void) {
int pixelFormat; int pixelFormat;
PIXELFORMATDESCRIPTOR fpd = { PIXELFORMATDESCRIPTOR fpd = {
sizeof(PIXELFORMATDESCRIPTOR), // Size. sizeof(PIXELFORMATDESCRIPTOR), // Size.
1, // Version. 1, // Version.
PFD_SUPPORT_OPENGL | // OpenGL window. PFD_SUPPORT_OPENGL | // OpenGL window.
PFD_DRAW_TO_WINDOW | // Render to window. PFD_DRAW_TO_WINDOW | // Render to window.
PFD_DOUBLEBUFFER, // Support double-buffering. PFD_DOUBLEBUFFER, // Support double-buffering.
PFD_TYPE_RGBA, // Color type. PFD_TYPE_RGBA, // Color type.
32, // Prefered color depth. 32, // Prefered color depth.
0, 0, 0, 0, 0, 0, // Color bits (ignored). 0, 0, 0, 0, 0, 0, // Color bits (ignored).
0, // No alpha buffer. 0, // No alpha buffer.
0, // Alpha bits (ignored). 0, // Alpha bits (ignored).
0, // No accumulation buffer. 0, // No accumulation buffer.
0, 0, 0, 0, // Accumulation bits (ignored). 0, 0, 0, 0, // Accumulation bits (ignored).
16, // Depth buffer. 16, // Depth buffer.
0, // No stencil buffer. 0, // No stencil buffer.
0, // No auxiliary buffers. 0, // No auxiliary buffers.
PFD_MAIN_PLANE, // Main layer. PFD_MAIN_PLANE, // Main layer.
0, // Reserverd. 0, // Reserverd.
0, 0, 0, // No layer, visibility, damage masks. 0, 0, 0, // No layer, visibility, damage masks.
}; };
pixelFormat = ChoosePixelFormat(&_hdc, pixelFormat, &pfd); pixelFormat = ChoosePixelFormat(&_hdc, pixelFormat, &pfd);
@ -142,7 +142,7 @@ void GLWindow::SetPixelFormat(void) {
LRESULT GLWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { LRESULT GLWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch uMsg) { switch uMsg) {
case WM_CREATE: { // Window creation. case WM_CREATE: { // Window creation.
_hdc = GetDC(hWnd); _hdc = GetDC(hWnd);
SetupPixelFormat(); SetupPixelFormat();
@ -172,21 +172,21 @@ LRESULT GLWindow::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
} }
// Make the GL3 context current. // Make the GL3 context current.
wglMakeCurrent(_hdc, _hglrc); wglMakeCurrent(_hdc, _hglrc);
_isRunning = true; // Mark our window as running now. _isRunning = true; // Mark our window as running now.
} }
break; break;
case WM_DESTROY: // Destroy window. case WM_DESTROY: // Destroy window.
case WM_CLOSE: // Windows is closing. case WM_CLOSE: // Windows is closing.
wglMakeCurrent(_hdc, NULL); wglMakeCurrent(_hdc, NULL);
wglDeleteContext(_hglrc); wglDeleteContext(_hglrc);
_isRunning = false; // Stop the main loop. _isRunning = false; // Stop the main loop.
PostQuitMessage(0); // Send a WM_QUIT message. PostQuitMessage(0); // Send a WM_QUIT message.
return 0; return 0;
break; break;
case WM_SIZE: { case WM_SIZE: {
int height = HIWORD(lParam); // Retrieve width and height. int height = HIWORD(lParam); // Retrieve width and height.
int width = LOWORD(lParam); int width = LOWORD(lParam);
GetAttachedGame()->OnResize(width, height); // Call the games resize method. GetAttachedGame()->OnResize(width, height); // Call the games resize method.
} }
break; break;
case WM_KEYDOWN: case WM_KEYDOWN: