Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <gl/gl.h>
- #include <gl/glu.h>
- #include <gl/glaux.h>
- #include "us_types.h"
- LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
- WPARAM wParam, LPARAM lParam);
- void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC);
- void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC);
- HWND hWnd;
- int i2 = 0;
- GLuint texture[2];
- u8 blockb[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
- float color_red = 0,color_green = 0,color_blue = 0;
- struct {
- int x;
- int y;
- } cursor_koor;
- float cursor_x;
- struct {
- int left;
- int top;
- int right;
- int bottom;
- } window_koor;
- texture1[] = {0x4c,0xb1,0x22,0xff,0x0,0xff,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,
- 0xff,0x0,0x0,0xff,0x0,0xff,0x0,0x0,0x0,0x0,0xff,0x0,0x0,0xff,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0xff,0xff,0x0,0xff,0x0,0x0,0xff,0x0,0xc8,0x7f,0x7f,0xc8,0x7f,0x7f,0x0,0xff,
- 0x0,0xea,0xd9,0x99,0xea,0xd9,0x99,0xea,0xd9,0x99,0xea,0xd9,0x99,0x0,0xff,0x0,0xc8,0x7f,0x7f,0xc8,0x7f,0x7f,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0xff,0x0,0xff,0x0,0xff,
- 0x0,0x0,0x0,0x0,0xff,0x0,0x0,0xff,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,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4c,0xb1,0x22,0x4c,0xb1,0x22,0xff,0x0,0xff,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,
- 0xff,0x0,0x0,0xff,0x0,0xff,0x0,0x0,0x0,0x0,0xff,0x0,0x0,0xff,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0xff,0xff,0x0,0xff,0x0,0x0,0xff,0x0,0xc8,0x7f,0x7f,0xc8,0x7f,0x7f,0x0,0xff,
- 0x0,0xea,0xd9,0x99,0xea,0xd9,0x99,0xea,0xd9,0x99,0xea,0xd9,0x99,0x0,0xff,0x0,0xc8,0x7f,0x7f,0xc8,0x7f,0x7f,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0xff,0x0,0xff,0x0,0xff,
- 0x0,0x0,0x0,0x0,0xff,0x0,0x0,0xff,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,
- 0x0,0xff,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x4c,0xb1,0x22,};
- void risovat() {
- glClear (GL_COLOR_BUFFER_BIT);
- float blockx = 0;
- float blocky = 0;
- u8 i1 = 0;
- glBegin(GL_QUADS);
- while (i1 < 50) {
- switch (i1/10) {
- case 0: {
- color_red = 0.51f;
- color_green = 0.42f;
- color_blue = 0.627f;
- break;
- }
- case 1: {
- color_red = 0.345f;
- color_green = 0.659f;
- color_blue = 0.706f;
- break;
- }
- case 2: {
- color_red = 1.0f;
- color_green = 0.71f;
- color_blue = 0.102f;
- break;
- }
- case 3: {
- color_red = 0.102f;
- color_green = 1.0f;
- color_blue = 0.482f;
- break;
- }
- case 4: {
- color_red = 1.0f;
- color_green = 0;
- color_blue = 0;
- break;
- }
- }
- if (blockb[i1]) {
- glColor3f(color_red,color_green,color_blue);
- if (i1 == 18) {
- color_red = 1.0f; color_green = 0; color_blue = 0;
- }
- if (i1 == 21) {
- color_red = 1.0f; color_green = 1.0f; color_blue = 0;
- }
- if (i1 == 45) {
- color_red = 0.5f; color_green = 0; color_blue = 0.2f;
- }
- glVertex2f(blockx,blocky);
- glColor3f(color_red,color_green,color_blue);
- if (i1 == 18) {
- color_red = 1.0f; color_green = 1.0f; color_blue = 1.0f;
- }
- if (i1 == 21) {
- color_red = 1.0f; color_green = 1.0f; color_blue = 0.8f;
- }
- if (i1 == 45) {
- color_red = 0.2f; color_green = 0.3; color_blue = 0.5;
- }
- glVertex2f(blockx + 0.2f,blocky);
- glColor3f(color_red,color_green,color_blue);
- if (i1 == 18) {
- color_red = 1.0f; color_green = 0; color_blue = 1.0;
- }
- if (i1 == 21) {
- color_red = 1.0f; color_green = 0; color_blue = 0.5f;
- }
- if (i1 == 45) {
- color_red = 0.8f; color_green = 1.0f; color_blue = 0;
- }
- glVertex2f(blockx + 0.2f,blocky - 0.05f);
- glColor3f(color_red,color_green,color_blue);
- if (i1 == 18) {
- color_red = 0.0f; color_green = 1.0f; color_blue = 0;
- }
- if (i1 == 21) {
- color_red = 0; color_green = 0; color_blue = 1.0f;
- }
- if (i1 == 45) {
- color_red = 0; color_green = 1.0f; color_blue = 1.0f;
- }
- glVertex2f(blockx,blocky - 0.05f);
- }
- blockx += 0.2f;
- i1++;
- if (i1%10 == 0) {
- blockx = 0;
- blocky -= 0.05f;
- }
- }
- glEnd();
- glBindTexture(GL_TEXTURE_2D,texture[0]);
- glBegin(GL_QUADS);
- GetCursorPos(&cursor_koor);
- GetWindowRect(hWnd,&window_koor);
- if (cursor_koor.x > window_koor.left && cursor_koor.x < window_koor.right && cursor_koor.y > window_koor.top && cursor_koor.y < window_koor.bottom) {
- cursor_x = (cursor_koor.x - window_koor.left)/250.0;
- }
- glColor3f(1,1,1);
- glTexCoord2f(1,0);
- glVertex2f(cursor_x - 0.2f,-1.875);
- glTexCoord2f(1,1);
- glVertex2f(cursor_x + 0.2f,-1.875);
- glTexCoord2f(0,1);
- glVertex2f(cursor_x + 0.2f,-1.9f);
- glTexCoord2f(0,0);
- glVertex2f(cursor_x - 0.2f,-1.9f);
- glEnd();
- }
- GLvoid load_texture() {
- glGenTextures(1,&texture[0]);
- glBindTexture(GL_TEXTURE_2D,texture[0]);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D,0,3,50,5,0,GL_RGB,GL_UNSIGNED_BYTE,&texture1);
- }
- int WINAPI WinMain (HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int iCmdShow)
- {
- WNDCLASS wc;
- HDC hDC;
- HGLRC hRC;
- MSG msg;
- BOOL bQuit = FALSE;
- wc.style = CS_OWNDC;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor (NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = "GLSample";
- RegisterClass (&wc);
- hWnd = CreateWindow (
- "GLSample", "Breakout",
- WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
- 550, 100, 500, 800,
- NULL, NULL, hInstance, NULL);
- EnableOpenGL (hWnd, &hDC, &hRC);
- glTranslatef(-1.0f,1.0f,0.0f);
- while (!bQuit)
- {
- if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
- {
- if (msg.message == WM_QUIT)
- {
- bQuit = TRUE;
- }
- else
- {
- TranslateMessage (&msg);
- DispatchMessage (&msg);
- }
- }
- else
- {
- risovat();
- SwapBuffers (hDC);
- }
- }
- DisableOpenGL (hWnd, hDC, hRC);
- DestroyWindow (hWnd);
- return msg.wParam;
- }
- LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
- WPARAM wParam, LPARAM lParam)
- {
- switch (message)
- {
- case WM_CREATE:
- return 0;
- case WM_CLOSE:
- PostQuitMessage (0);
- return 0;
- case WM_DESTROY:
- return 0;
- default:
- return DefWindowProc (hWnd, message, wParam, lParam);
- }
- }
- void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC)
- {
- PIXELFORMATDESCRIPTOR pfd;
- int iFormat;
- *hDC = GetDC (hWnd);
- ZeroMemory (&pfd, sizeof (pfd));
- pfd.nSize = sizeof (pfd);
- pfd.nVersion = 1;
- pfd.dwFlags = PFD_DRAW_TO_WINDOW |
- PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
- pfd.iPixelType = PFD_TYPE_RGBA;
- pfd.cColorBits = 24;
- pfd.cDepthBits = 16;
- pfd.iLayerType = PFD_MAIN_PLANE;
- iFormat = ChoosePixelFormat (*hDC, &pfd);
- SetPixelFormat (*hDC, iFormat, &pfd);
- *hRC = wglCreateContext( *hDC );
- wglMakeCurrent( *hDC, *hRC );
- glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
- load_texture();
- glEnable(GL_TEXTURE_2D);
- }
- void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
- {
- wglMakeCurrent (NULL, NULL);
- wglDeleteContext (hRC);
- ReleaseDC (hWnd, hDC);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement