- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, OpenGl, StdCtrls, ExtCtrls;
- type
- TForm1 = class(TForm)
- Button1: TButton;
- Timer1: TTimer;
- procedure Button1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure Timer1Timer(Sender: TObject);
- procedure FormPaint(Sender: TObject);
- private
- { Private declarations }
- handleGL:HWND;
- dc : HDC;
- hrc: HGLRC;
- ps : TPaintStruct;
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- procedure SetDCPixelFormat (hdc : HDC);
- var
- pfd : TPixelFormatDescriptor;
- nPixelFormat : Integer;
- begin
- FillChar (pfd, SizeOf (pfd), 0);
- pfd.dwFlags :=PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER;
- nPixelFormat :=ChoosePixelFormat (hdc, @pfd);
- SetPixelFormat(hdc, nPixelFormat, @pfd);
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- DC := GetDC (Handle);
- SetDCPixelFormat(DC);
- hrc := wglCreateContext(DC);
- wglMakeCurrent(DC, hrc);
- glClearColor (0.0, 0.0, 0.75, 1.0);
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity;
- glFrustum (-1, 1, -1, 1, 2, 20);
- glMatrixMode (GL_MODELVIEW);
- glLoadIdentity;
- glTranslatef(0.0, 0.0, -6.0);
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- glEnable (GL_LIGHTING);
- glEnable (GL_LIGHT0);
- glEnable (GL_DEPTH_TEST);
- timer1.enabled:=true;
- end;
- procedure TForm1.Timer1Timer(Sender: TObject);
- begin
- glRotatef(1.0, 1.0, 1.0, 1.0);
- glRotatef(1.0, 1.0, 1.0, 0.0);
- glRotatef(1.0, 1.0, 1.0, 1.0);
- SwapBuffers(DC);
- InvalidateRect(Handle, nil, False);
- end;
- procedure TForm1.FormPaint(Sender: TObject);
- var
- i,k:integer;
- begin
- glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
- glBegin(GL_QUADS);
- glNormal3f(0.0, 0.0, 1.0);
- glVertex3f(1.0, 1.0, 1.0);
- glVertex3f(-1.0, 1.0, 1.0);
- glVertex3f(-1.0, -1.0, 1.0);
- glVertex3f(1.0, -1.0, 1.0);
- glEnd;
- glBegin(GL_QUADS);
- glNormal3f(-1.0, 0.0, 0.0);
- glVertex3f(-1.0, 1.0, 1.0);
- glVertex3f(-1.0, 1.0, -1.0);
- glVertex3f(-1.0, -1.0, -1.0);
- glVertex3f(-1.0, -1.0, 1.0);
- glEnd;
- glBegin(GL_QUADS);
- glNormal3f(0.0, 1.0, 0.0);
- glVertex3f(-1.0, 1.0, -1.0);
- glVertex3f(-1.0, 1.0, 1.0);
- glVertex3f(1.0, 1.0, 1.0);
- glVertex3f(1.0, 1.0, -1.0);
- glEnd;
- glBegin(GL_QUADS);
- glNormal3f(1.0, 0.0, -1.0);
- glVertex3f(1.0, -1.0, -1.0);
- glVertex3f(1.0, -1.0, 1.0);
- glVertex3f(1.0, 1.0, 1.0);
- glVertex3f(1.0, 1.0, -1.0);
- glEnd;
- glBegin(GL_QUADS);
- glNormal3f(0.0, 0.0, -1.0);
- glVertex3f(1.0, -1.0, 1.0);
- glVertex3f(1.0, -1.0, -1.0);
- glVertex3f(-1.0, -1.0, -1.0);
- glVertex3f(-1.0, -1.0, 1.0);
- glEnd;
- end;
- end.