System.cpp
上传用户:sz83729876
上传日期:2013-03-07
资源大小:4140k
文件大小:3k
源码类别:

OpenGL

开发平台:

Windows_Unix

  1. //
  2. // a64ki
  3. // Copyright (c) 2002 Henrik Carlgren
  4. // http://ziruz.cjb.net
  5. // ziruz@hotpop.com
  6. //
  7. //
  8. // INCLUDE FILES
  9. //
  10. #include "system.h"
  11. #include "config.h"
  12. //
  13. // GLOBAL VARIABLES
  14. //
  15. extern HINSTANCE applicationInstance;
  16. extern HWND windowHandle;
  17. extern HDC deviceContext;
  18. extern HGLRC renderContext;
  19. extern bool running;
  20. //
  21. // FUNCTION: systemStartup
  22. //
  23. void systemStartup(void)
  24. {
  25. WNDCLASS wndClass;
  26. DWORD style;
  27. PIXELFORMATDESCRIPTOR pixelFormatDescriptor;
  28. int i;
  29. //
  30. // Win32
  31. //
  32. for(i = 0; i < sizeof(wndClass); i++)
  33. {
  34. *(((char *)&wndClass)+i) = 0;
  35. }
  36. wndClass.lpfnWndProc = windowProcess;
  37. wndClass.hInstance = applicationInstance;
  38. wndClass.lpszClassName = "window";
  39. RegisterClass(&wndClass);
  40. #ifdef FULLSCREEN
  41. DEVMODE screenSettings;
  42. ZeroMemory(&screenSettings, sizeof(screenSettings));
  43. screenSettings.dmSize = sizeof(screenSettings);
  44. screenSettings.dmPelsWidth = 800;
  45. screenSettings.dmPelsHeight = 600;
  46. screenSettings.dmBitsPerPel = 32;
  47. screenSettings.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT|DM_DISPLAYFREQUENCY;
  48. ChangeDisplaySettings(&screenSettings, CDS_FULLSCREEN);
  49. style = WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_POPUP;
  50. ShowCursor(FALSE);
  51. #else // FULLSCREEN
  52. style = WS_CAPTION|WS_POPUPWINDOW|WS_VISIBLE;
  53. #endif // FULLSCREEN
  54. windowHandle = CreateWindowEx(
  55. WS_EX_APPWINDOW,
  56. "window", "a64ki",
  57. style,0, 0, 800, 600,
  58. NULL, NULL, applicationInstance, NULL);
  59. ShowWindow(windowHandle, SW_SHOW);
  60. SetForegroundWindow(windowHandle);
  61. SetFocus(windowHandle);
  62. //
  63. // OpenGL
  64. //
  65. deviceContext = GetDC(windowHandle);
  66. for(i = 0; i < sizeof(wndClass); i++)
  67. {
  68. *(((char *)&pixelFormatDescriptor)+i) = 0;
  69. }
  70. pixelFormatDescriptor.nSize = sizeof(pixelFormatDescriptor);
  71. pixelFormatDescriptor.dwFlags = PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER;
  72. pixelFormatDescriptor.cColorBits = 32;
  73. pixelFormatDescriptor.cDepthBits = 16;
  74. pixelFormatDescriptor.cStencilBits = 8;
  75. SetPixelFormat(deviceContext, ChoosePixelFormat(deviceContext, &pixelFormatDescriptor), &pixelFormatDescriptor);
  76. renderContext = wglCreateContext(deviceContext);
  77. wglMakeCurrent(deviceContext, renderContext);
  78. }
  79. //
  80. // FUNCTION: systemCleanup
  81. //
  82. void systemCleanup(void)
  83. {
  84. //
  85. // OpenGL
  86. //
  87. wglMakeCurrent(NULL, NULL);
  88. wglDeleteContext(renderContext);
  89. //
  90. // Win32
  91. //
  92. DestroyWindow(windowHandle);
  93. UnregisterClass("window", applicationInstance);
  94. ChangeDisplaySettings(NULL, 0);
  95. ShowCursor(TRUE);
  96. }
  97. //
  98. // FUNCTION: systemCycle
  99. //
  100. void systemCycle(void)
  101. {
  102. MSG message;
  103. while(PeekMessage(&message, NULL, 0, 0, PM_REMOVE))
  104. {
  105. TranslateMessage(&message);
  106. DispatchMessage(&message);
  107. }
  108. }
  109. //
  110. // FUNCTION: windowProcess
  111. //
  112. LRESULT APIENTRY windowProcess(HWND windowHandle, UINT message, WPARAM wParam, LPARAM lParam)
  113. {
  114. switch(message)
  115. {
  116. case WM_CLOSE:
  117. running = false;
  118. break;
  119. case WM_QUIT:
  120. running = false;
  121. break;
  122. case WM_KEYDOWN:
  123. if(LOWORD(wParam) == VK_ESCAPE)
  124. running = false;
  125. break;
  126. default:
  127. return DefWindowProc(windowHandle, message, wParam, lParam);
  128. }
  129. return 0;
  130. }