Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. program Snejinka;
  2.  
  3. uses
  4. Messages,
  5. Windows,
  6. OpenGL,
  7. DGLUT;
  8.  
  9. const
  10. AppName = 'Snejinka';
  11.  
  12. var
  13. Message : Msg;
  14. Window : HWnd;
  15. oX, oY : Array [0..69] of GLfloat;
  16. ps : PaintStruct;
  17. Angle: GLfloat;
  18. WindowClass : WndClass;
  19. glnWidth, glnHeight : GLsizei;
  20. dc : HDC;
  21. AppActive : bool;
  22. hrc : HGLRC;
  23.  
  24. procedure Scena;
  25. var
  26. i : 0..69;
  27. begin
  28. glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  29.  
  30. glPushMatrix;
  31. glRotatef(45,1.0,1.0, 0.0);
  32. glRotatef(Angle, 1.0, 1.0, 0.0);
  33.  
  34. For i := 0 to 69 do begin
  35. glPushMatrix;
  36. glColor3f(1.0, 0.0, 1.4);
  37. glTranslatef(oX [i], oY [i], 0.0);
  38. glRotatef(80.0 * i, 1.0, 1.0, 1.0);
  39. glScalef (1.0, 7.0, 1.0);
  40. glutSolidCube (0.1);
  41.  
  42.  
  43. glPopMatrix;
  44. end;
  45.  
  46. glPopMatrix;
  47.  
  48. SwapBuffers(DC);
  49. end;
  50.  
  51.  
  52. procedure Skorost;
  53. begin
  54. Angle := Angle + 0.4;
  55. If Angle >= 360.0 then Angle := 0.0;
  56. InvalidateRect(Window, nil, False);
  57. end;
  58.  
  59.  
  60. procedure PixelF (hdc : HDC);
  61. var
  62. pfd : Pixelformatdescriptor;
  63. PFormat : Integer;
  64. Begin
  65.  
  66. pfd.dwFlags := PFD_SUPPORT_OPENGL or PFD_DRAW_TO_WINDOW or PFD_DOUBLEBUFFER;
  67. PFormat := ChoosePixelFormat(DC, @pfd);
  68. SetPixelFormat(DC, PFormat, @pfd);
  69. end;
  70.  
  71.  
  72. function Prozorec (Window : HWnd; Message, WParam : Word;
  73. LParam : LongInt) : LongInt; export; stdcall;
  74. var
  75. i : 0..69;
  76. Begin
  77. case Message of
  78. wm_Create:
  79. begin
  80. dc := GetDC (Window);
  81. PixelF (dc);
  82. hrc := wglCreateContext (dc); //контекст
  83. wglMakeCurrent (dc, hrc);
  84.  
  85. For i := 0 to 69 do begin
  86. oX [i] := cos (Pi / 25 * i);
  87. oY [i] := sin (Pi / 25 * i);
  88. end;
  89.  
  90. glEnable(GL_DEPTH_TEST);
  91.  
  92. glEnable(GL_LIGHTING);
  93. glEnable(GL_LIGHT0);
  94. glEnable (GL_COLOR_MATERIAL);
  95.  
  96. glClearColor (1.0, 1.0, 1.0, 1.0);
  97. end;
  98.  
  99.  
  100. wm_Size:
  101. begin
  102. glnWidth := LoWord (lParam);
  103. glnHeight := HiWord (lParam);
  104. glViewport(0, 0, glnWidth, glnHeight);
  105.  
  106. glMatrixMode(GL_PROJECTION);
  107. glLoadIdentity;
  108.  
  109. gluPerspective(20.0, glnWidth / glnHeight, 7.0, 20.0);
  110. glMatrixMode(GL_MODELVIEW);
  111. glLoadIdentity;
  112.  
  113. glTranslatef(0.0, 0.0, -10.0);
  114. glRotatef(60.0, 1.0, 0.0, 1.0);
  115. InvalidateRect(Window, nil, False);
  116. end;
  117.  
  118. WM_ACTIVATEAPP:
  119. If (wParam=WA_ACTIVE)
  120. then AppActive := True
  121. else AppActive := False;
  122. wm_Paint:
  123. begin
  124. dc := BeginPaint (Window, ps);
  125. Scena;
  126. EndPaint (Window, ps);
  127. end;
  128.  
  129. wm_Destroy:
  130. begin
  131. wglMakeCurrent(0, 0);
  132. ReleaseDC (Window, dc);
  133. DeleteDC (dc);
  134. PostQuitMessage (0);
  135. Exit;
  136. end;
  137.  
  138. end;
  139.  
  140. Prozorec := DefWindowProc (Window, Message, WParam, LParam);
  141. End;
  142.  
  143. Begin
  144. With WindowClass do begin
  145. lpfnWndProc := @Prozorec;
  146. lpszClassName := AppName;
  147. end;
  148.  
  149. RegisterClass (WindowClass);
  150. Window := CreateWindow
  151. (AppName, AppName, ws_OverLappedWindow, cw_UseDefault, cw_UseDefault, cw_UseDefault,
  152. cw_UseDefault, HWND_DESKTOP, 0, HInstance, nil);
  153.  
  154. ShowWindow (Window, CmdShow);
  155. While True do begin
  156. If PeekMessage(Message,0, 0, 0, pm_NoRemove) then begin
  157. If not GetMessage(Message, 0, 0, 0 )
  158. then Break
  159. else begin
  160. TranslateMessage(Message);
  161. DispatchMessage(Message);
  162. end;
  163. end
  164. else
  165. If AppActive
  166. then Skorost
  167. else WaitMessage;
  168. end;
  169. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement