code_junkie

opengl problem under vista

Nov 11th, 2011
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. #include<windows.h>
  2. #include<glgl.h>
  3. #include<glglu.h>
  4. #pragma comment(lib, "opengl32.lib")
  5. #pragma comment(lib, "glu32.lib")
  6.  
  7. void InitGL(void)
  8. {
  9. glClearColor(1,0.3f,0.3f,0.3f);
  10. }
  11.  
  12. void DrawGLScene(void)
  13. {
  14. /* code removed */
  15. }
  16.  
  17. HGLRC hRC = NULL;
  18. HDC hDC = NULL;
  19. HWND hWnd = NULL;
  20. HINSTANCE hInstance = NULL;
  21. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  22.  
  23. bool CreateGLWindow(char* title, int width, int height)
  24. {
  25. GLuint PixelFormat;
  26. WNDCLASS wc;
  27. RECT WindowRect;
  28. WindowRect.left = (long)0;
  29. WindowRect.right = (long)width;
  30. WindowRect.top = (long)0;
  31. WindowRect.bottom = (long)height;
  32. LPCSTR nazwa = TEXT("Start");
  33.  
  34. hInstance = GetModuleHandle(NULL);
  35. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  36. wc.lpfnWndProc = (WNDPROC)WndProc;
  37. wc.cbClsExtra = 0;
  38. wc.cbWndExtra = 0;
  39. wc.hInstance = hInstance;
  40. wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
  41. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  42. wc.hbrBackground = NULL;
  43. wc.lpszMenuName = NULL;
  44. wc.lpszClassName = nazwa;
  45.  
  46. RegisterClass(&wc);
  47.  
  48. hWnd = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, nazwa,
  49. nazwa,
  50. WS_SYSMENU |
  51. WS_CLIPSIBLINGS |
  52. WS_CLIPCHILDREN,
  53. 0,0,
  54. width,
  55. height,
  56. NULL,
  57. NULL,
  58. hInstance,
  59. NULL);
  60.  
  61. static PIXELFORMATDESCRIPTOR pfd =
  62. {
  63. sizeof(PIXELFORMATDESCRIPTOR),
  64. 1,
  65. PFD_DRAW_TO_WINDOW |
  66. PFD_SUPPORT_OPENGL |
  67. PFD_DOUBLEBUFFER,
  68. PFD_TYPE_RGBA,
  69. 32,
  70. 0,0,0,0,0,0,
  71. 0,
  72. 0,
  73. 0,
  74. 0,0,0,0,
  75. 16,
  76. 0,
  77. 0,
  78. PFD_MAIN_PLANE,
  79. 0,
  80. 0,0,0
  81. };
  82.  
  83. hDC = GetDC(hWnd);
  84. PixelFormat = ChoosePixelFormat(hDC, &pfd);
  85. HRESULT rez = SetPixelFormat(hDC, PixelFormat, &pfd);
  86. hRC = wglCreateContext(hDC);
  87. wglMakeCurrent(hDC, hRC);
  88. ShowWindow(hWnd, SW_SHOW);
  89. InitGL();
  90. return true;
  91.  
  92. }
  93.  
  94. LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  95. {
  96. switch(uMsg)
  97. {
  98. case WM_ACTIVATE:
  99. {
  100. return 0;
  101. }
  102. case WM_CLOSE:
  103. {
  104. PostQuitMessage(0);
  105. return 0;
  106. }
  107. }
  108.  
  109. return DefWindowProc(hWnd, uMsg, wParam, lParam);
  110. }
  111.  
  112. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
  113. int nCmdShow)
  114. {
  115. MSG msg;
  116. bool done = false;
  117.  
  118. if (!CreateGLWindow(NULL, 800,600))
  119. {
  120. return 0;
  121. }
  122.  
  123. while(!done)
  124. {
  125. if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
  126. {
  127. if (!GetMessage(&msg, 0, 0, 0)) done = true;
  128. else {
  129. TranslateMessage(&msg);
  130. DispatchMessage(&msg);
  131. }
  132. }
  133. else
  134. {
  135. DrawGLScene();
  136. SwapBuffers(hDC);
  137. }
  138. }
  139.  
  140. return (msg.wParam);
  141. }
Add Comment
Please, Sign In to add comment