Advertisement
Guest User

Untitled

a guest
Mar 17th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 9.85 KB | None | 0 0
  1. #include <windows.h>
  2. #include <gl/gl.h>
  3. #include <gl/glu.h>
  4. #include <gl/glaux.h>
  5.  
  6. #include "us_types.h"
  7.  
  8. LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
  9. WPARAM wParam, LPARAM lParam);
  10. void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC);
  11. void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC);
  12.  
  13. HWND hWnd;
  14.  
  15. int i2 = 0;
  16. GLuint texture[2];
  17. 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};
  18. float color_red = 0,color_green = 0,color_blue = 0;
  19. struct {
  20.     int x;
  21.     int y;
  22. } cursor_koor;
  23. float cursor_x;
  24. struct {
  25.     int left;
  26.     int top;
  27.     int right;
  28.     int bottom;
  29. } window_koor;
  30. 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,
  31. 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,
  32. 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,
  33. 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,
  34. 0x0,0xff,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x4c,0xb1,0x22,0x4c,0xb1,0x22,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0x0,0xff,0x0,0xff,0x0,0xff,
  35. 0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0x0,0x0,0xff,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0xff,0x0,
  36. 0xff,0x0,0x0,0xff,0x0,0xc8,0x7f,0x7f,0x0,0xff,0x0,0x85,0xe9,0x5f,0xb1,0xe7,0x61,0xb1,0xe7,0x61,0x85,0xe9,0x5f,0x0,0xff,0x0,0xc8,0x7f,0x7f,0x0,0xff,0x0,0x0,0xff,0x0,
  37. 0x0,0xff,0xff,0x0,0xff,0x0,0x0,0xff,0x0,0xff,0x0,0x0,0x0,0x0,0xff,0xff,0x0,0x0,0xff,0x0,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,
  38. 0x0,0xff,0x0,0xff,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0x4c,0xb1,0x22,0x4c,0xb1,0x22,0x0,0xff,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,
  39. 0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0xff,0xff,0xff,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,
  40. 0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0xff,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x85,0xe9,0x5f,0xb1,0xe7,0x61,0xb1,0xe7,0x61,0x85,0xe9,0x5f,0x0,0xff,0x0,
  41. 0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0xff,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0xff,0xff,0x0,0xff,0x0,0x0,0xff,0x0,0x0,
  42. 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,0x4c,0xb1,0x22,0x4c,0xb1,0x22,0x0,0xff,
  43. 0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0x0,
  44. 0xff,0x0,0x0,0x0,0x0,0xff,0xff,0x0,0x0,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0xff,0x0,0xff,0x0,0x0,0xff,0x0,0xc8,0x7f,0x7f,0x0,0xff,0x0,0x85,0xe9,0x5f,0xb1,0xe7,0x61,0xb1,
  45. 0xe7,0x61,0x85,0xe9,0x5f,0x0,0xff,0x0,0xc8,0x7f,0x7f,0x0,0xff,0x0,0x0,0xff,0x0,0x0,0xff,0xff,0x0,0xff,0x0,0x0,0xff,0x0,0xff,0x0,0x0,0x0,0x0,0xff,0xff,0x0,0x0,0xff,0x0,
  46. 0x0,0x0,0xff,0x0,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0xff,0x0,0xff,0x0,0xff,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,0xff,0x0,
  47. 0x4c,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,
  48. 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,
  49. 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,
  50. 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,
  51. 0x0,0xff,0x0,0x0,0xff,0x0,0xff,0x0,0xff,0x4c,0xb1,0x22,};
  52.  
  53.  
  54.  
  55. void risovat() {
  56.     glClear (GL_COLOR_BUFFER_BIT);
  57.    
  58.     float blockx = 0;
  59.     float blocky = 0;
  60.    
  61.     u8 i1 = 0;
  62.    
  63.     glBegin(GL_QUADS);
  64.     while (i1 < 50) {
  65.         switch (i1/10) {
  66.             case 0: {
  67.                 color_red = 0.51f;
  68.                 color_green = 0.42f;
  69.                 color_blue = 0.627f;
  70.                 break;
  71.             }
  72.             case 1: {
  73.                 color_red = 0.345f;
  74.                 color_green = 0.659f;
  75.                 color_blue = 0.706f;
  76.                 break;
  77.             }
  78.             case 2: {
  79.                 color_red = 1.0f;
  80.                 color_green = 0.71f;
  81.                 color_blue = 0.102f;
  82.                 break;
  83.             }
  84.             case 3: {
  85.                 color_red = 0.102f;
  86.                 color_green = 1.0f;
  87.                 color_blue = 0.482f;
  88.                 break;
  89.             }
  90.             case 4: {
  91.                 color_red = 1.0f;
  92.                 color_green = 0;
  93.                 color_blue = 0;
  94.                 break;
  95.             }
  96.         }      
  97.         if (blockb[i1]) {
  98.             glColor3f(color_red,color_green,color_blue);
  99.             if (i1 == 18) {
  100.                 color_red = 1.0f; color_green = 0; color_blue = 0;
  101.             }
  102.             if (i1 == 21) {
  103.                 color_red = 1.0f; color_green = 1.0f; color_blue = 0;
  104.             }
  105.             if (i1 == 45) {
  106.                 color_red = 0.5f; color_green = 0; color_blue = 0.2f;
  107.             }
  108.             glVertex2f(blockx,blocky);
  109.            
  110.             glColor3f(color_red,color_green,color_blue);
  111.             if (i1 == 18) {
  112.                 color_red = 1.0f; color_green = 1.0f; color_blue = 1.0f;
  113.             }
  114.             if (i1 == 21) {
  115.                 color_red = 1.0f; color_green = 1.0f; color_blue = 0.8f;
  116.             }
  117.             if (i1 == 45) {
  118.                 color_red = 0.2f; color_green = 0.3; color_blue = 0.5;
  119.             }
  120.             glVertex2f(blockx + 0.2f,blocky);
  121.            
  122.             glColor3f(color_red,color_green,color_blue);
  123.             if (i1 == 18) {
  124.                 color_red = 1.0f; color_green = 0; color_blue = 1.0;
  125.             }
  126.             if (i1 == 21) {
  127.                 color_red = 1.0f; color_green = 0; color_blue = 0.5f;
  128.             }
  129.             if (i1 == 45) {
  130.                 color_red = 0.8f; color_green = 1.0f; color_blue = 0;
  131.             }
  132.             glVertex2f(blockx + 0.2f,blocky - 0.05f);
  133.            
  134.             glColor3f(color_red,color_green,color_blue);
  135.             if (i1 == 18) {
  136.                 color_red = 0.0f; color_green = 1.0f; color_blue = 0;
  137.             }
  138.             if (i1 == 21) {
  139.                 color_red = 0; color_green = 0; color_blue = 1.0f;
  140.             }
  141.             if (i1 == 45) {
  142.                 color_red = 0; color_green = 1.0f; color_blue = 1.0f;
  143.             }
  144.             glVertex2f(blockx,blocky - 0.05f);
  145.         }
  146.         blockx += 0.2f;
  147.         i1++;
  148.         if (i1%10 == 0) {
  149.             blockx = 0;
  150.             blocky -= 0.05f;
  151.         }
  152.        
  153.     }
  154.     glEnd();
  155.    
  156.     glBindTexture(GL_TEXTURE_2D,texture[0]);
  157.     glBegin(GL_QUADS);
  158.     GetCursorPos(&cursor_koor);
  159.     GetWindowRect(hWnd,&window_koor);
  160.     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) {
  161.         cursor_x = (cursor_koor.x - window_koor.left)/250.0;
  162.     }
  163.    
  164.     glColor3f(1,1,1);
  165.     glTexCoord2f(1,0);
  166.     glVertex2f(cursor_x - 0.2f,-1.875);
  167.     glTexCoord2f(1,1);
  168.     glVertex2f(cursor_x + 0.2f,-1.875);
  169.     glTexCoord2f(0,1);
  170.     glVertex2f(cursor_x + 0.2f,-1.9f);
  171.     glTexCoord2f(0,0);
  172.     glVertex2f(cursor_x - 0.2f,-1.9f);
  173.     glEnd();
  174. }
  175.  
  176. GLvoid load_texture() {
  177.     glGenTextures(1,&texture[0]);
  178.     glBindTexture(GL_TEXTURE_2D,texture[0]);
  179.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
  180.     glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
  181.     glTexImage2D(GL_TEXTURE_2D,0,3,50,5,0,GL_RGB,GL_UNSIGNED_BYTE,&texture1);
  182. }
  183.  
  184. int WINAPI WinMain (HINSTANCE hInstance,
  185.                     HINSTANCE hPrevInstance,
  186.                     LPSTR lpCmdLine,
  187.                     int iCmdShow)
  188. {
  189.     WNDCLASS wc;
  190.     HDC hDC;
  191.     HGLRC hRC;        
  192.     MSG msg;
  193.     BOOL bQuit = FALSE;
  194.  
  195.     wc.style = CS_OWNDC;
  196.     wc.lpfnWndProc = WndProc;
  197.     wc.cbClsExtra = 0;
  198.     wc.cbWndExtra = 0;
  199.     wc.hInstance = hInstance;
  200.     wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
  201.     wc.hCursor = LoadCursor (NULL, IDC_ARROW);
  202.     wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
  203.     wc.lpszMenuName = NULL;
  204.     wc.lpszClassName = "GLSample";
  205.     RegisterClass (&wc);
  206.  
  207.     hWnd = CreateWindow (
  208.       "GLSample", "Breakout",
  209.       WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
  210.       550, 100, 500, 800,
  211.       NULL, NULL, hInstance, NULL);
  212.  
  213.     EnableOpenGL (hWnd, &hDC, &hRC);
  214.     glTranslatef(-1.0f,1.0f,0.0f);
  215.  
  216.     while (!bQuit)
  217.     {
  218.         if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
  219.         {
  220.             if (msg.message == WM_QUIT)
  221.             {
  222.                 bQuit = TRUE;
  223.             }
  224.             else
  225.             {
  226.                 TranslateMessage (&msg);
  227.                 DispatchMessage (&msg);
  228.             }
  229.         }
  230.         else
  231.         {
  232.             risovat();
  233.             SwapBuffers (hDC);
  234.         }
  235.     }
  236.  
  237.     DisableOpenGL (hWnd, hDC, hRC);
  238.  
  239.     DestroyWindow (hWnd);
  240.  
  241.     return msg.wParam;
  242. }
  243.  
  244. LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
  245.                           WPARAM wParam, LPARAM lParam)
  246. {
  247.  
  248.     switch (message)
  249.     {
  250.     case WM_CREATE:
  251.         return 0;
  252.     case WM_CLOSE:
  253.         PostQuitMessage (0);
  254.         return 0;
  255.  
  256.     case WM_DESTROY:
  257.         return 0;
  258.        
  259.  
  260.     default:
  261.         return DefWindowProc (hWnd, message, wParam, lParam);
  262.     }
  263. }
  264.  
  265.  
  266.  
  267. void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC)
  268. {
  269.     PIXELFORMATDESCRIPTOR pfd;
  270.     int iFormat;
  271.     *hDC = GetDC (hWnd);
  272.     ZeroMemory (&pfd, sizeof (pfd));
  273.     pfd.nSize = sizeof (pfd);
  274.     pfd.nVersion = 1;
  275.     pfd.dwFlags = PFD_DRAW_TO_WINDOW |
  276.       PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  277.     pfd.iPixelType = PFD_TYPE_RGBA;
  278.     pfd.cColorBits = 24;
  279.     pfd.cDepthBits = 16;
  280.     pfd.iLayerType = PFD_MAIN_PLANE;
  281.     iFormat = ChoosePixelFormat (*hDC, &pfd);
  282.     SetPixelFormat (*hDC, iFormat, &pfd);
  283.     *hRC = wglCreateContext( *hDC );
  284.     wglMakeCurrent( *hDC, *hRC );
  285.    
  286.     glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
  287.     load_texture();
  288.     glEnable(GL_TEXTURE_2D);
  289. }
  290.  
  291.  
  292.  
  293. void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
  294. {
  295.     wglMakeCurrent (NULL, NULL);
  296.     wglDeleteContext (hRC);
  297.     ReleaseDC (hWnd, hDC);
  298. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement