rendered paste body/************************** * Includes * **************************/#include <windows.h> #include <math.h> #include <stdio.h> #include <stdarg.h> #include <gl\gl.h> #include <gl\glu.h> #include <gl\glaux.h> /************************** * Function Declarations * **************************/HDC hDC=NULL; // Private GDI Device ContextHGLRC hRC=NULL; // Permanent Rendering ContextHWND hWnd=NULL; // Holds Our Window HandleHINSTANCE hInstance; // Holds The Instance Of The ApplicationGLuint base; // Base Display List For The Font SetGLfloat cnt1; // 1st Counter Used To Move Text & For ColoringGLfloat cnt2; // 2nd Counter Used To Move Text & For ColoringLRESULT 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);void koch(float x1, float y1, float x2, float y2, int k);bool keys[256]; /************************** * WinMain * **************************/GLvoid BuildFont(GLvoid) // Build Our Bitmap Font{ HFONT font; // Windows Font ID HFONT oldfont; // Used For Good House Keeping base = glGenLists(96); // Storage For 96 Characters font = CreateFont( -24, // Height Of Font 0, // Width Of Font 0, // Angle Of Escapement 0, // Orientation Angle FW_BOLD, // Font Weight FALSE, // Italic FALSE, // Underline FALSE, // Strikeout ANSI_CHARSET, // Character Set Identifier OUT_TT_PRECIS, // Output Precision CLIP_DEFAULT_PRECIS, // Clipping Precision ANTIALIASED_QUALITY, // Output Quality FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch "Courier New"); // Font Name oldfont = (HFONT)SelectObject(hDC, font); // Selects The Font We Want wglUseFontBitmaps(hDC, 32, 96, base); // Builds 96 Characters Starting At Character 32 SelectObject(hDC, oldfont); // Selects The Font We Want DeleteObject(font); // Delete The Font}GLvoid KillFont(GLvoid) // Delete The Font List{ glDeleteLists(base, 96); // Delete All 96 Characters}GLvoid glPrint(const char *fmt, ...) // Custom GL "Print" Routine{ char text[256]; // Holds Our String va_list ap; // Pointer To List Of Arguments if (fmt == NULL) // If There's No Text return; // Do Nothing va_start(ap, fmt); // Parses The String For Variables vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers va_end(ap); // Results Are Stored In Text glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits glListBase(base - 32); // Sets The Base Character to 32 glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text glPopAttrib(); // Pops The Display List Bits}int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow){ WNDCLASS wc; HWND hWnd; HDC hDC; HGLRC hRC; MSG msg; BOOL bQuit = FALSE; float theta = 0.0f; /* register window class */ 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); /* create main window */ hWnd = CreateWindow ( "GLSample", "OpenGL Sample", WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE, 0, 0, 750, 750, NULL, NULL, hInstance, NULL); /* enable OpenGL for the window */ EnableOpenGL (hWnd, &hDC, &hRC); /* program main loop */ glEnable(GL_DEPTH_TEST); // Enables Depth Testing // 1 2 3 4 5 6 7 8float x[9]={0 , -0.6, 0.6, 0.0, 0.0, 0.0, 0.3, 0.3, 0.0};float y[9]={0 , -0.6, -0.6, 0.45, 0.0, 0.3, 0.3, 0.0, 0.0}; float z[9]={0 , 0.0, 0.0, 0.0, 0.0, 0.3, 0.3, 0.3, 0.3};int k=4;//*********************************************/////petla/////******************************* //*********************************************/////glowna////******************************* while (!bQuit) { /* check for messages */ if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) { /* handle or dispatch messages */ if (msg.message == WM_QUIT) { bQuit = TRUE; } else { TranslateMessage (&msg); DispatchMessage (&msg); } } else { if(keys[VK_DOWN]) { for (int i = 1; i < 9; i++) y[i] +=0.02f; } else if(keys[VK_UP]) { for (int i = 1; i < 9; i++) y[i] -=0.02f; } if(keys[VK_LEFT]) { for (int i = 1; i < 9; i++) x[i] +=0.02f; } else if(keys[VK_RIGHT]) { for (int i = 1; i < 9; i++) x[i] -=0.02f; } if(keys['S']) { for (int i = 1; i < 4;i++) { x[i] = x[i]*1.3f; y[i] = y[i]*1.3f; } Sleep(200); } if(keys['X']) { for (int i = 1; i < 4;i++) { x[i] = x[i] / 1.3f; y[i] = y[i] / 1.3f; } Sleep(200); } if(keys['A']) { k++; Sleep(200); } else if(keys['Z']) { if (k) k--; Sleep(200); } glClearColor (0.0f, 0.0f, 0.0f, 0.0f); glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); koch(x[1],y[1],x[2],y[2],k); koch(x[3],y[3],x[1],y[1],k); koch(x[2],y[2],x[3],y[3],k); SwapBuffers (hDC); } }//************************************************************************************* //************************************************************************************* //************************************************************************************* /* shutdown OpenGL */ DisableOpenGL (hWnd, hDC, hRC); /* destroy the window explicitly */ DestroyWindow (hWnd); return msg.wParam;}/******************** Standardowe proceduty windowsa ********************/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; case WM_KEYDOWN: switch (wParam) { case VK_ESCAPE: PostQuitMessage(0); return 0; default: keys[wParam]=true; // Odpowiednie pole zostaje ustawione return 0; // skocz dalej } case WM_KEYUP: // Czy klawisz zosta wcini�y { keys[wParam]=false; // Odpowiednie pole zostaje ustawione na false return 0; // skocz dalej } return 0; default: return DefWindowProc (hWnd, message, wParam, lParam); }}/******************* * Enable OpenGL * *******************/void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC){ PIXELFORMATDESCRIPTOR pfd; int iFormat; /* get the device context (DC) */ *hDC = GetDC (hWnd); /* set the pixel format for the DC */ 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); /* create and enable the render context (RC) */ *hRC = wglCreateContext( *hDC ); wglMakeCurrent( *hDC, *hRC ); glClearDepth(1.0f); // ustawienie bufora gebi glEnable(GL_DEPTH_TEST); // wczenie testowania g�i glDepthFunc(GL_LEQUAL); // ustawienie typu testowania glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); BuildFont(); // Build The Font }/****************** * Disable OpenGL * ******************/void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC){ wglMakeCurrent (NULL, NULL); wglDeleteContext (hRC); ReleaseDC (hWnd, hDC); KillFont();}// funkcje obliczeniowe//********************************//********************************void koch(float x1, float y1, float x2, float y2, int k){float dlx = (x2-x1) , dly = (y2-y1); if (!k ) { if (!( (x1 > 1.2) || (x1 < -1.2) || (y1 > 1.2) || (y1 < -1.2) )) { glBegin(GL_LINES); glColor3f( fabs(sin((x1+x2)/2+ 0.5f)) , fabs(sin((y1+y2)/2 + 0.5f)) , fabs((cos(y1+y2+x1)))); glVertex2f(x1,y1); glVertex2f(x2,y2); glEnd(); } } else { koch(x1,y1, x1 + dlx/3, y1+dly/3, k-1); koch(x1 + dlx*2/3, y1+dly*2/3, x2 , y2 , k-1); koch(x1+dlx/3, y1+dly/3, (x1+x2)/2+sqrt(3)/6*dly, (y1+y2)/2-sqrt(3)/6*dlx,k-1); koch((x1+x2)/2+sqrt(3)/6*dly, (y1+y2)/2-sqrt(3)/6*dlx,x1 + dlx*2/3, y1+dly*2/3,k-1); } }