Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Snejinka;
- uses
- Messages,
- Windows,
- OpenGL,
- DGLUT;
- const
- AppName = 'Snejinka';
- var
- Message : Msg;
- Window : HWnd;
- oX, oY : Array [0..69] of GLfloat;
- ps : PaintStruct;
- Angle: GLfloat;
- WindowClass : WndClass;
- glnWidth, glnHeight : GLsizei;
- dc : HDC;
- AppActive : bool;
- hrc : HGLRC;
- procedure Scena;
- var
- i : 0..69;
- begin
- glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
- glPushMatrix;
- glRotatef(45,1.0,1.0, 0.0);
- glRotatef(Angle, 1.0, 1.0, 0.0);
- For i := 0 to 69 do begin
- glPushMatrix;
- glColor3f(1.0, 0.0, 1.4);
- glTranslatef(oX [i], oY [i], 0.0);
- glRotatef(80.0 * i, 1.0, 1.0, 1.0);
- glScalef (1.0, 7.0, 1.0);
- glutSolidCube (0.1);
- glPopMatrix;
- end;
- glPopMatrix;
- SwapBuffers(DC);
- end;
- procedure Skorost;
- begin
- Angle := Angle + 0.4;
- If Angle >= 360.0 then Angle := 0.0;
- InvalidateRect(Window, nil, False);
- end;
- procedure PixelF (hdc : HDC);
- var
- pfd : Pixelformatdescriptor;
- PFormat : Integer;
- Begin
- pfd.dwFlags := PFD_SUPPORT_OPENGL or PFD_DRAW_TO_WINDOW or PFD_DOUBLEBUFFER;
- PFormat := ChoosePixelFormat(DC, @pfd);
- SetPixelFormat(DC, PFormat, @pfd);
- end;
- function Prozorec (Window : HWnd; Message, WParam : Word;
- LParam : LongInt) : LongInt; export; stdcall;
- var
- i : 0..69;
- Begin
- case Message of
- wm_Create:
- begin
- dc := GetDC (Window);
- PixelF (dc);
- hrc := wglCreateContext (dc); //контекст
- wglMakeCurrent (dc, hrc);
- For i := 0 to 69 do begin
- oX [i] := cos (Pi / 25 * i);
- oY [i] := sin (Pi / 25 * i);
- end;
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glEnable (GL_COLOR_MATERIAL);
- glClearColor (1.0, 1.0, 1.0, 1.0);
- end;
- wm_Size:
- begin
- glnWidth := LoWord (lParam);
- glnHeight := HiWord (lParam);
- glViewport(0, 0, glnWidth, glnHeight);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity;
- gluPerspective(20.0, glnWidth / glnHeight, 7.0, 20.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity;
- glTranslatef(0.0, 0.0, -10.0);
- glRotatef(60.0, 1.0, 0.0, 1.0);
- InvalidateRect(Window, nil, False);
- end;
- WM_ACTIVATEAPP:
- If (wParam=WA_ACTIVE)
- then AppActive := True
- else AppActive := False;
- wm_Paint:
- begin
- dc := BeginPaint (Window, ps);
- Scena;
- EndPaint (Window, ps);
- end;
- wm_Destroy:
- begin
- wglMakeCurrent(0, 0);
- ReleaseDC (Window, dc);
- DeleteDC (dc);
- PostQuitMessage (0);
- Exit;
- end;
- end;
- Prozorec := DefWindowProc (Window, Message, WParam, LParam);
- End;
- Begin
- With WindowClass do begin
- lpfnWndProc := @Prozorec;
- lpszClassName := AppName;
- end;
- RegisterClass (WindowClass);
- Window := CreateWindow
- (AppName, AppName, ws_OverLappedWindow, cw_UseDefault, cw_UseDefault, cw_UseDefault,
- cw_UseDefault, HWND_DESKTOP, 0, HInstance, nil);
- ShowWindow (Window, CmdShow);
- While True do begin
- If PeekMessage(Message,0, 0, 0, pm_NoRemove) then begin
- If not GetMessage(Message, 0, 0, 0 )
- then Break
- else begin
- TranslateMessage(Message);
- DispatchMessage(Message);
- end;
- end
- else
- If AppActive
- then Skorost
- else WaitMessage;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement