Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.06 KB | None | 0 0
  1. #include <windows.h>
  2. #include <tchar.h>
  3. #include <cmath> // sin()
  4. #include <cstdlib> // rand(), srand()
  5. #include <ctime> // time()
  6. #include "resource.h" // menu
  7. // OpenGL
  8. #include <gl\GL.h>
  9. #include <gl\GLU.h>
  10. #pragma comment (lib,"opengl32.lib")
  11. #pragma comment (lib,"glu32.lib")
  12.  
  13. // НОХЯЮМХЕ НАПЮАНРВХЙЮ
  14. LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  15.  
  16. // global variables
  17. #define PI 3.14159265358979323846
  18. HWND hWnd;
  19. HDC hDC;
  20. HGLRC hRC;
  21. int index = 0;
  22. float mouse_x, mouse_y;
  23. int winWidth = 800, winHeight = 500; // ДКХМЮ, БШЯНРЮ
  24.  
  25. void InitPixel(HDC hDC)
  26. {
  27. int PixelFormat;
  28. PIXELFORMATDESCRIPTOR pfd;
  29. memset(&pfd,0,sizeof(PIXELFORMATDESCRIPTOR));
  30. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  31. PixelFormat = ChoosePixelFormat(hDC, &pfd);
  32. SetPixelFormat(hDC, PixelFormat, &pfd);
  33. }
  34.  
  35. int random(int min, int max) // [min, max]
  36. {
  37. //srand((unsigned) time(NULL));
  38. return rand() % (max - min + 1) + min;
  39. }
  40.  
  41. void DRAW_sin()
  42. {
  43. int p = 4;
  44. float h = 0.01;
  45. int k = p * 2 * PI / h;
  46. glPointSize(2);
  47. glColor3f(0.5, 0.5, 0.5);
  48. glBegin(GL_POINTS);
  49. for (int i = 0; i < k; i++) {
  50. float x = i * h / p / PI - 1;
  51. float y = sin(i * h) * 0.5;
  52. glVertex2f(x, y);
  53. }
  54. glEnd();
  55. }
  56.  
  57. void DRAW_tringle()
  58. {
  59. glBegin(GL_TRIANGLE_STRIP);
  60. glVertex2f(0, 0);
  61. for (int i = 0; i < 19; i++)
  62. {
  63. float x = (float) rand() / (RAND_MAX + 1) * (winWidth - 0) + 0 + 0.5;
  64. float y = (float) rand() / (RAND_MAX + 1) * (winHeight - 0) + 0 + 0.5;
  65.  
  66. x = (x - ((float) winWidth / 2)) / ((float) winWidth / 2);
  67. y = (((float) winHeight / 2) - y) / ((float) winHeight / 2);
  68.  
  69. glColor3f((float) rand() / RAND_MAX, (float) rand() / RAND_MAX, (float) rand() / RAND_MAX);
  70. glVertex2f(x, y);
  71. }
  72. glEnd();
  73. }
  74.  
  75. void DRAW_fire()
  76. {
  77. glEnable(GL_LINE_STIPPLE);
  78.  
  79. int k = random(20, 200);
  80.  
  81. for (int i = 0; i < k; i++)
  82. {
  83. glLineWidth(random(1, 5));
  84. glLineStipple(random(1, 4), random(0x0000, 0xFFFF));
  85. glBegin(GL_LINES);
  86.  
  87. float x = (mouse_x - ((float) winWidth / 2)) / ((float) winWidth / 2);
  88. float y = (((float) winHeight / 2) - mouse_y) / ((float) winHeight / 2);
  89. float x1 = x, y1 = y;
  90.  
  91. glColor3f((float) rand() / RAND_MAX, (float) rand() / RAND_MAX, (float) rand() / RAND_MAX);
  92. glVertex2f(x, y); // mouse pos.
  93.  
  94. //x = (float) rand() / (RAND_MAX + 1) * (winWidth - 0) + 0 + 0.5;
  95. //y = (float) rand() / (RAND_MAX + 1) * (winHeight - 0) + 0 + 0.5;
  96. x = random(0, winWidth);
  97. y = random(0, winHeight);
  98. x = (x - ((float) winWidth / 2)) / ((float) winWidth / 2);
  99. y = (((float) winHeight / 2) - y) / ((float) winHeight / 2);
  100.  
  101. x = x1 + 0.5 * (x * sin(random(0, 360)));
  102. y = y1 + 0.8 * (y * cos(random(0, 360)));
  103.  
  104.  
  105.  
  106. glColor3f((float) rand() / RAND_MAX, (float) rand() / RAND_MAX, (float) rand() / RAND_MAX);
  107. glVertex2f(x, y);
  108.  
  109. glEnd();
  110. }
  111. glDisable(GL_LINE_STIPPLE);
  112. }
  113.  
  114. void DRAW()
  115. {
  116. glClear(GL_COLOR_BUFFER_BIT);
  117. glClear(GL_DEPTH_BUFFER_BIT);
  118. if (index == 0)
  119. DRAW_sin();
  120. else if (index == 1)
  121. DRAW_tringle();
  122. else if (index == 2)
  123. DRAW_fire();
  124. SwapBuffers(hDC);
  125. }
  126.  
  127. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  128. {
  129. // хМХЖХЮКХГЮЖХЪ НЙМЮ
  130. WNDCLASSEX win;
  131. win.cbSize = sizeof(WNDCLASSEX);
  132. win.style = CS_HREDRAW | CS_VREDRAW;
  133. win.lpfnWndProc = WndProc;
  134. win.cbClsExtra = 0;
  135. win.cbWndExtra = 0;
  136. win.hInstance = hInstance;
  137. win.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
  138. win.hCursor = LoadCursor(NULL, IDC_ARROW);
  139. win.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  140. win.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
  141. win.lpszClassName = "MyClassName";
  142. win.hIconSm = LoadIcon(win.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
  143.  
  144. // пЕЦХЯРПЮЖХЪ НЙМЮ
  145. if (!RegisterClassEx(&win))
  146. {
  147. MessageBox(NULL, "нЬХАЙЮ ПЕЦХЯРПЮЖХХ!", "нЬХАЙЮ", NULL);
  148. return 1;
  149. }
  150.  
  151. // яНГДЮМХЕ НЙМЮ
  152. hWnd = CreateWindow(
  153. "MyClassName",
  154. "MyTitle",
  155. WS_OVERLAPPEDWINDOW,
  156. CW_USEDEFAULT, CW_USEDEFAULT, // ОНГХЖХЪ НЙМЮ: x, y
  157. winWidth, winHeight, // ПЮГЛЕПШ НЙМЮ: ЬХПХМЮ, БШЯНРЮ
  158. NULL,
  159. NULL,
  160. hInstance,
  161. NULL
  162. );
  163.  
  164. if (!hWnd)
  165. {
  166. MessageBox(NULL, "нЬХАЙЮ ОПХ ЯНГДЮМХХ НЙМЮ!", "нЬХАЙЮ", NULL);
  167. return 1;
  168. }
  169.  
  170. ShowWindow(hWnd, nCmdShow);
  171. UpdateWindow(hWnd);
  172.  
  173. MSG msg;
  174. while (GetMessage(&msg, NULL, 0, 0))
  175. {
  176. TranslateMessage(&msg);
  177. DispatchMessage(&msg);
  178. }
  179.  
  180. return 0;
  181. }
  182.  
  183. // НАПЮАНРВХЙ
  184. LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
  185. {
  186. switch (message)
  187. {
  188. case WM_CREATE:
  189. hDC = GetDC(hWnd);
  190. hRC = wglCreateContext(hDC);
  191. InitPixel(hDC);
  192. hRC = wglCreateContext(hDC);
  193. wglMakeCurrent(hDC,hRC);
  194. glClearColor(0.1, 0.1, 0.1, 1.0);
  195. break;
  196. //case WM_PAINT:
  197. // glViewport(0, 0, winWidth, winHeight);
  198. // glClear(GL_COLOR_BUFFER_BIT);
  199. // glClear(GL_DEPTH_BUFFER_BIT);
  200. // DRAW();
  201. // SwapBuffers(hDC);
  202. // break;
  203. case WM_KEYDOWN:
  204. if (wParam == VK_ESCAPE)
  205. DestroyWindow(hWnd);
  206. break;
  207. case WM_MOUSEMOVE:
  208. DRAW();
  209. mouse_x = LOWORD(lParam);
  210. mouse_y = HIWORD(lParam);
  211. break;
  212. case WM_COMMAND:
  213. switch (LOWORD(wParam))
  214. {
  215. case ID_SIN:
  216. index = 0;
  217. DRAW();
  218. break;
  219. case ID_TRINGLE:
  220. index = 1;
  221. DRAW();
  222. break;
  223. case ID_FIRE:
  224. index = 2;
  225. DRAW();
  226. break;
  227. }
  228. break;
  229. case WM_SIZE:
  230. winWidth = LOWORD(lParam);
  231. winHeight = HIWORD(lParam);
  232. glViewport(0, 0, winWidth, winHeight);
  233. DRAW();
  234. break;
  235. case WM_DESTROY:
  236. PostQuitMessage(0);
  237. wglMakeCurrent(0, 0);
  238. wglDeleteContext(hRC);
  239. ReleaseDC(hWnd, hDC);
  240. DeleteDC(hDC);
  241. break;
  242. default:
  243. return DefWindowProc(hWnd, message, wParam, lParam);
  244. break;
  245. }
  246.  
  247. return 0;
  248. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement