unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls,
OpenGLContext, Math, glcanvas;
type
{ TForm1 }
TForm1 = class(TForm)
OpenGLControl1: TOpenGLControl;
Panel1: TPanel;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure OpenGLControl1Paint(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
num, rot: Single;
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Timer1Timer(Sender: TObject);
begin
OpenGLControl1.Invalidate;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
glInit(OpenGLControl1);
if not OpenGLControl1.MakeCurrent then raise Exception.Create('OpenGL context makeCurrent Error');
num := 0;
rot := 0;
end;
procedure TForm1.OpenGLControl1Paint(Sender: TObject);
var
i, q: Integer;
a, d: Single;
cx, cy: Integer;
rayX, rayY: Single;
begin
if not OpenGLControl1.MakeCurrent then Exit;
glFillScreen(OpenGLControl1, 0.0, 0.0, 0.0, 1.0);
cx := OpenGLControl1.Width div 2;
cy := OpenGLControl1.Height div 2;
glSaveMatrix; // sun
glTranslateMatrix(cx, cy, 0);
for i := -180 to 179 do
if i mod 12 = 0 then
begin
rayX := sin(DegToRad(i)) * 15;
rayY := cos(DegToRad(i)) * 15;
glSaveMatrix;
glTranslateMatrix(rayX, rayY, 0);
glRotateMatrix(-i + rot, 0, 0, 1); // Z rotation
for q := 0 to 195 do
if q mod 5 = 0 then
begin
d := 40 - (q / 200) * 40;
a := sin(DegToRad(-i + q + num)) * 2;
glEllipse(a, q * 1.7, d, d, 20, 1.0, 0.6, 0.0, 0.1, true);
end;
glRestoreMatrix; // rays
end;
glRestoreMatrix; // sun
glSaveMatrix;
glFilled3DCube(OpenGLControl1, -80, 0, 0, 50, 1.0, 1.0, 1.0, 1.0, rot, -rot, rot, 0.0, 0.0, 1.0);
glWired3DCube(OpenGLControl1, -80, 0, 0, 50, 1.0,0.0,0.0, 1.0, rot, -rot, rot, 4.0);
glRestoreMatrix;
glFilled3DCube(OpenGLControl1, 80, 0, 0, 50, 0.0,0.5,1.0, 1.0, rot, rot, rot, 1.0, 0.0, 0.0);
glWired3DCube(OpenGLControl1, 80, 0, 0, 50, 0.5,0.5,0.5, 1.0, rot, rot, rot, 4.0);
num += 11.5; // deg
rot += 1.15; // deg
OpenGLControl1.SwapBuffers;
end;
end.