mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-05-01 22:03:42 +02:00
148 lines
5.3 KiB
ObjectPascal
148 lines
5.3 KiB
ObjectPascal
{
|
|
*****************************************************************************
|
|
* *
|
|
* See the file COPYING.modifiedLGPL, included in this distribution, *
|
|
* for details about the copyright. *
|
|
* *
|
|
* This program is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
* *
|
|
*****************************************************************************
|
|
|
|
Author: Mattias Gaertner
|
|
|
|
}
|
|
unit MainUnit;
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
interface
|
|
|
|
uses
|
|
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs,
|
|
OpenGLContext, GL, GLU;
|
|
|
|
type
|
|
|
|
{ TForm1 }
|
|
|
|
TForm1 = class(TForm)
|
|
procedure FormCreate(Sender: TObject);
|
|
procedure OpenGLControl1Paint(Sender: TObject);
|
|
procedure OpenGLControl1Resize(Sender: TObject);
|
|
private
|
|
public
|
|
cube_rotationx: GLFloat;
|
|
cube_rotationy: GLFloat;
|
|
cube_rotationz: GLFloat;
|
|
OpenGLControl1: TOpenGLControl;
|
|
end;
|
|
|
|
var
|
|
Form1: TForm1;
|
|
|
|
implementation
|
|
|
|
{ TForm1 }
|
|
|
|
procedure TForm1.FormCreate(Sender: TObject);
|
|
begin
|
|
if Sender=nil then ;
|
|
|
|
OpenGLControl1:=TOpenGLControl.Create(Self);
|
|
with OpenGLControl1 do begin
|
|
Name:='OpenGLControl1';
|
|
Align:=alClient;
|
|
Parent:=Self;
|
|
OnPaint:=@OpenGLControl1Paint;
|
|
OnResize:=@OpenGLControl1Resize;
|
|
AutoResizeViewport:=true;
|
|
end;
|
|
end;
|
|
|
|
procedure TForm1.OpenGLControl1Paint(Sender: TObject);
|
|
var
|
|
Speed: Double;
|
|
begin
|
|
if Sender=nil then ;
|
|
|
|
glClearColor(1.0, 1.0, 1.0, 1.0);
|
|
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
glViewport(0,0, width, height);
|
|
glMatrixMode(GL_PROJECTION);
|
|
glLoadIdentity();
|
|
gluPerspective(45.0, double(width) / height, 0.1, 100.0);
|
|
glMatrixMode(GL_MODELVIEW);
|
|
glLoadIdentity();
|
|
|
|
glTranslatef(0.0, 0.0,-6.0);
|
|
glRotatef(cube_rotationx, cube_rotationy, cube_rotationz, 0.0);
|
|
|
|
glBegin(GL_QUADS);
|
|
glColor3f(0.0,1.0,0.0); // Set The Color To Green
|
|
glVertex3f( 1.0, 1.0,-1.0); // Top Right Of The Quad (Top)
|
|
glVertex3f(-1.0, 1.0,-1.0); // Top Left Of The Quad (Top)
|
|
glVertex3f(-1.0, 1.0, 1.0); // Bottom Left Of The Quad (Top)
|
|
glVertex3f( 1.0, 1.0, 1.0); // Bottom Right Of The Quad (Top)
|
|
glEnd();
|
|
glBegin(GL_QUADS);
|
|
glColor3f(1.0,0.5,0.0); // Set The Color To Orange
|
|
glVertex3f( 1.0,-1.0, 1.0); // Top Right Of The Quad (Bottom)
|
|
glVertex3f(-1.0,-1.0, 1.0); // Top Left Of The Quad (Bottom)
|
|
glVertex3f(-1.0,-1.0,-1.0); // Bottom Left Of The Quad (Bottom)
|
|
glVertex3f( 1.0,-1.0,-1.0); // Bottom Right Of The Quad (Bottom)
|
|
glEnd();
|
|
glBegin(GL_QUADS);
|
|
glColor3f(1.0,0.0,0.0); // Set The Color To Red
|
|
glVertex3f( 1.0, 1.0, 1.0); // Top Right Of The Quad (Front)
|
|
glVertex3f(-1.0, 1.0, 1.0); // Top Left Of The Quad (Front)
|
|
glVertex3f(-1.0,-1.0, 1.0); // Bottom Left Of The Quad (Front)
|
|
glVertex3f( 1.0,-1.0, 1.0); // Bottom Right Of The Quad (Front)
|
|
glEnd();
|
|
glBegin(GL_QUADS);
|
|
glColor3f(1.0,1.0,0.0); // Set The Color To Yellow
|
|
glVertex3f( 1.0,-1.0,-1.0); // Bottom Left Of The Quad (Back)
|
|
glVertex3f(-1.0,-1.0,-1.0); // Bottom Right Of The Quad (Back)
|
|
glVertex3f(-1.0, 1.0,-1.0); // Top Right Of The Quad (Back)
|
|
glVertex3f( 1.0, 1.0,-1.0); // Top Left Of The Quad (Back)
|
|
glEnd();
|
|
glBegin(GL_QUADS);
|
|
glColor3f(0.0,0.0,1.0); // Set The Color To Blue
|
|
glVertex3f(-1.0, 1.0, 1.0); // Top Right Of The Quad (Left)
|
|
glVertex3f(-1.0, 1.0,-1.0); // Top Left Of The Quad (Left)
|
|
glVertex3f(-1.0,-1.0,-1.0); // Bottom Left Of The Quad (Left)
|
|
glVertex3f(-1.0,-1.0, 1.0); // Bottom Right Of The Quad (Left)
|
|
glEnd();
|
|
glBegin(GL_QUADS);
|
|
glColor3f(1.0,0.0,1.0); // Set The Color To Violet
|
|
glVertex3f( 1.0, 1.0,-1.0); // Top Right Of The Quad (Right)
|
|
glVertex3f( 1.0, 1.0, 1.0); // Top Left Of The Quad (Right)
|
|
glVertex3f( 1.0,-1.0, 1.0); // Bottom Left Of The Quad (Right)
|
|
glVertex3f( 1.0,-1.0,-1.0); // Bottom Right Of The Quad (Right)
|
|
glEnd();
|
|
|
|
Speed := double(OpenGLControl1.FrameDiffTimeInMSecs)/10;
|
|
|
|
cube_rotationx += 5.15 * Speed;
|
|
cube_rotationy += 5.15 * Speed;
|
|
cube_rotationz += 20.0 * Speed;
|
|
|
|
OpenGLControl1.SwapBuffers;
|
|
end;
|
|
|
|
procedure TForm1.OpenGLControl1Resize(Sender: TObject);
|
|
begin
|
|
if Sender=nil then ;
|
|
if OpenGLControl1.Height <= 0 then exit;
|
|
|
|
end;
|
|
|
|
initialization
|
|
{$I mainunit.lrs}
|
|
|
|
end.
|
|
|