Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <tchar.h>
- #include <cmath> // sin()
- #include <cstdlib> // rand(), srand()
- #include <ctime> // time()
- #include "resource.h" // menu
- // OpenGL
- #include <gl\GL.h>
- #include <gl\GLU.h>
- #pragma comment (lib,"opengl32.lib")
- #pragma comment (lib,"glu32.lib")
- // НОХЯЮМХЕ НАПЮАНРВХЙЮ
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- // global variables
- #define PI 3.14159265358979323846
- HWND hWnd;
- HDC hDC;
- HGLRC hRC;
- int index = 0;
- float mouse_x, mouse_y;
- int winWidth = 800, winHeight = 500; // ДКХМЮ, БШЯНРЮ
- void InitPixel(HDC hDC)
- {
- int PixelFormat;
- PIXELFORMATDESCRIPTOR pfd;
- memset(&pfd,0,sizeof(PIXELFORMATDESCRIPTOR));
- pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
- PixelFormat = ChoosePixelFormat(hDC, &pfd);
- SetPixelFormat(hDC, PixelFormat, &pfd);
- }
- int random(int min, int max) // [min, max]
- {
- //srand((unsigned) time(NULL));
- return rand() % (max - min + 1) + min;
- }
- void DRAW_sin()
- {
- int p = 4;
- float h = 0.01;
- int k = p * 2 * PI / h;
- glPointSize(2);
- glColor3f(0.5, 0.5, 0.5);
- glBegin(GL_POINTS);
- for (int i = 0; i < k; i++) {
- float x = i * h / p / PI - 1;
- float y = sin(i * h) * 0.5;
- glVertex2f(x, y);
- }
- glEnd();
- }
- void DRAW_tringle()
- {
- glBegin(GL_TRIANGLE_STRIP);
- glVertex2f(0, 0);
- for (int i = 0; i < 19; i++)
- {
- float x = (float) rand() / (RAND_MAX + 1) * (winWidth - 0) + 0 + 0.5;
- float y = (float) rand() / (RAND_MAX + 1) * (winHeight - 0) + 0 + 0.5;
- x = (x - ((float) winWidth / 2)) / ((float) winWidth / 2);
- y = (((float) winHeight / 2) - y) / ((float) winHeight / 2);
- glColor3f((float) rand() / RAND_MAX, (float) rand() / RAND_MAX, (float) rand() / RAND_MAX);
- glVertex2f(x, y);
- }
- glEnd();
- }
- void DRAW_fire()
- {
- glEnable(GL_LINE_STIPPLE);
- int k = random(20, 200);
- for (int i = 0; i < k; i++)
- {
- glLineWidth(random(1, 5));
- glLineStipple(random(1, 4), random(0x0000, 0xFFFF));
- glBegin(GL_LINES);
- float x = (mouse_x - ((float) winWidth / 2)) / ((float) winWidth / 2);
- float y = (((float) winHeight / 2) - mouse_y) / ((float) winHeight / 2);
- float x1 = x, y1 = y;
- glColor3f((float) rand() / RAND_MAX, (float) rand() / RAND_MAX, (float) rand() / RAND_MAX);
- glVertex2f(x, y); // mouse pos.
- //x = (float) rand() / (RAND_MAX + 1) * (winWidth - 0) + 0 + 0.5;
- //y = (float) rand() / (RAND_MAX + 1) * (winHeight - 0) + 0 + 0.5;
- x = random(0, winWidth);
- y = random(0, winHeight);
- x = (x - ((float) winWidth / 2)) / ((float) winWidth / 2);
- y = (((float) winHeight / 2) - y) / ((float) winHeight / 2);
- x = x1 + 0.5 * (x * sin(random(0, 360)));
- y = y1 + 0.8 * (y * cos(random(0, 360)));
- glColor3f((float) rand() / RAND_MAX, (float) rand() / RAND_MAX, (float) rand() / RAND_MAX);
- glVertex2f(x, y);
- glEnd();
- }
- glDisable(GL_LINE_STIPPLE);
- }
- void DRAW()
- {
- glClear(GL_COLOR_BUFFER_BIT);
- glClear(GL_DEPTH_BUFFER_BIT);
- if (index == 0)
- DRAW_sin();
- else if (index == 1)
- DRAW_tringle();
- else if (index == 2)
- DRAW_fire();
- SwapBuffers(hDC);
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- // хМХЖХЮКХГЮЖХЪ НЙМЮ
- WNDCLASSEX win;
- win.cbSize = sizeof(WNDCLASSEX);
- win.style = CS_HREDRAW | CS_VREDRAW;
- win.lpfnWndProc = WndProc;
- win.cbClsExtra = 0;
- win.cbWndExtra = 0;
- win.hInstance = hInstance;
- win.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
- win.hCursor = LoadCursor(NULL, IDC_ARROW);
- win.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
- win.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
- win.lpszClassName = "MyClassName";
- win.hIconSm = LoadIcon(win.hInstance, MAKEINTRESOURCE(IDI_APPLICATION));
- // пЕЦХЯРПЮЖХЪ НЙМЮ
- if (!RegisterClassEx(&win))
- {
- MessageBox(NULL, "нЬХАЙЮ ПЕЦХЯРПЮЖХХ!", "нЬХАЙЮ", NULL);
- return 1;
- }
- // яНГДЮМХЕ НЙМЮ
- hWnd = CreateWindow(
- "MyClassName",
- "MyTitle",
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, // ОНГХЖХЪ НЙМЮ: x, y
- winWidth, winHeight, // ПЮГЛЕПШ НЙМЮ: ЬХПХМЮ, БШЯНРЮ
- NULL,
- NULL,
- hInstance,
- NULL
- );
- if (!hWnd)
- {
- MessageBox(NULL, "нЬХАЙЮ ОПХ ЯНГДЮМХХ НЙМЮ!", "нЬХАЙЮ", NULL);
- return 1;
- }
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
- MSG msg;
- while (GetMessage(&msg, NULL, 0, 0))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- return 0;
- }
- // НАПЮАНРВХЙ
- LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch (message)
- {
- case WM_CREATE:
- hDC = GetDC(hWnd);
- hRC = wglCreateContext(hDC);
- InitPixel(hDC);
- hRC = wglCreateContext(hDC);
- wglMakeCurrent(hDC,hRC);
- glClearColor(0.1, 0.1, 0.1, 1.0);
- break;
- //case WM_PAINT:
- // glViewport(0, 0, winWidth, winHeight);
- // glClear(GL_COLOR_BUFFER_BIT);
- // glClear(GL_DEPTH_BUFFER_BIT);
- // DRAW();
- // SwapBuffers(hDC);
- // break;
- case WM_KEYDOWN:
- if (wParam == VK_ESCAPE)
- DestroyWindow(hWnd);
- break;
- case WM_MOUSEMOVE:
- DRAW();
- mouse_x = LOWORD(lParam);
- mouse_y = HIWORD(lParam);
- break;
- case WM_COMMAND:
- switch (LOWORD(wParam))
- {
- case ID_SIN:
- index = 0;
- DRAW();
- break;
- case ID_TRINGLE:
- index = 1;
- DRAW();
- break;
- case ID_FIRE:
- index = 2;
- DRAW();
- break;
- }
- break;
- case WM_SIZE:
- winWidth = LOWORD(lParam);
- winHeight = HIWORD(lParam);
- glViewport(0, 0, winWidth, winHeight);
- DRAW();
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- wglMakeCurrent(0, 0);
- wglDeleteContext(hRC);
- ReleaseDC(hWnd, hDC);
- DeleteDC(hDC);
- break;
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement