unit W1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Transfrm, cOpenGL,OpenGL, Material, light;

type
  TForm1 = class(TForm)
    OpenGL1: TOpenGL;
    Transform1: TTransform;
    Transform2: TTransform;
    Light1: TLight;
    Material1: TMaterial;
    procedure FormCreate(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure Transform1Paint(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure Transform2Paint(Sender: TObject);
  private
    hom: GLfloat;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
  hom := 1.0; 
  glFrontFace(GL_CW);
end;

procedure TForm1.FormResize(Sender: TObject);
begin
  if OpenGL1.Smaller then
    FormPaint(Sender);
end;

procedure TForm1.FormPaint(Sender: TObject);
begin
  glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  Transform1.Apply;
  Transform2.Apply;
  glFlush;
  OpenGL1.ErrorCheck('FormPaint');
end;

procedure TForm1.Transform1Paint(Sender: TObject);
begin
  Light1.Apply;
end;


procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  case Key of
    'a': hom := 0.1;
    'b': hom := 0.2;
    'c': hom := 0.3;
    'd': hom := 0.4;
    'e': hom := 0.5;
    'f': hom := 0.6;
    'g': hom := 0.7;
    'h': hom := 0.8;
    'i': hom := 0.9;
    'j': hom := 1.0;
    'k': hom := 1.1;
    'l': hom := 1.2;
    'm': hom := 1.3;
    'n': hom := 1.4;
    else Key := #0;
  end; {case}
  if Key<>#0 then
    Invalidate;

  case Key of
    'a': hom := 0.1;
    'b': hom := 0.2;
    'c': hom := 0.3;
    'd': hom := 0.4;
    'e': hom := 0.5;
    'f': hom := 0.6;
    'g': hom := 0.7;
    'h': hom := 0.8;
    'i': hom := 0.9;
    'j': hom := 1.0;
    'k': hom := 1.1;
    'l': hom := 1.2;
    'm': hom := 1.3;
    'n': hom := 1.4;
    else Key := #0;
  end; {case}
  if Key<>#0 then
    Invalidate;
end;

procedure TForm1.Transform2Paint(Sender: TObject);
begin
  Material1.Apply;
  glBegin(GL_TRIANGLE_FAN);
    glVertex4f(+0.0,+0.0,+0.0,hom);
    glVertex4f(-0.3,+0.3,-0.4,hom);
    glVertex4f(+0.3,+0.3,-0.4,hom);
    glVertex4f(+0.0,-0.3,-0.4,hom);
    glVertex4f(-0.3,+0.3,-0.4,hom);
  glEnd;
end;

end.
