unit skybox1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,dglOpenGL, AppEvnts, GLBmp, StdCtrls, ExtCtrls,gl3ds;
type
TForm1 =
class(TForm)
ApplicationEvents1: TApplicationEvents;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure ApplicationEvents1Idle(Sender: TObject;
var Done: Boolean);
procedure FormResize(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormDestroy(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private-Deklarationen }
public
FDC : HDC;
FRC : HGLRC;
List : Cardinal;
yrot ,xrot : TGLFloat;
x,y:real;
OMpos : TPoint;
mesh: TAll3dsMesh;
procedure GLInit;
procedure LoadSkyBox;
procedure GenerateSkyBox(pWidth, pHeight, pLength : TGLFloat);
procedure DrawScene;
end;
var
Form1: TForm1;
SkyBoxTexture :
Array[0..5]
of TGLBmp;
timefactor : double = 1;
fps : integer = 20;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
Dummy : HPalette;
begin
InitOpenGL;
// Get a handle from our Window
FDC := GetDC(
Handle);
// Generate our rendering context with a color depth of 32Bpp
FRC := CreateRenderingContext(FDC, [opDoubleBuffered], 32, 24, 0, 0, 0, 0);
// Save our old mouse position
OMPos := Mouse.CursorPos;
ActivateRenderingContext(FDC, FRC);
GLInit;
LoadSkyBox;
mesh:= TAll3dsMesh.Create(
nil);
//erstellen
mesh.LoadFromFile('
cube.3ds');
// objekt laden
Cursor := crCross;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
DeActivateRenderingContext;
wglDeleteContext(FRC);
ReleaseDC(
Handle, FDC);
Mesh.free;
//freigabe
end;
procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
//courser berchnen und und undd....
end;
procedure TForm1.FormResize(Sender: TObject);
begin
if HandleAllocated
then
begin
glViewport(0, 0, ClientWidth, ClientHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
gluPerspective(45, ClientWidth/ClientHeight, 0.1, 1000);
end;
end;
procedure TForm1.GLInit;
begin
// Enable texture mapping
glEnable(GL_TEXTURE_2D);
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if fps=0
then
begin
fps := 1;
end;
timefactor := 20/fps;
fps := 0;
end;
procedure TForm1.LoadSkyBox;
//bilder für skybox laden
end;
procedure TForm1.GenerateSkyBox(pWidth, pHeight, pLength : TGLFloat);
///erstellt eine Skybox
end;
procedure TForm1.ApplicationEvents1Idle(Sender: TObject;
var Done: Boolean);
begin
DrawScene;
SetCursorPos(Width
div 2 + left, height
div 2 + top);
fps := fps+1;
end;
procedure TForm1.DrawScene;
begin
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;
// As the Skybox will fill the entire screen, we will only have to clear
// the depth buffer and not the color buffer
glClear(GL_DEPTH_BUFFER_BIT);
//glRotatef(xrot, 1, 0, 0);
//glRotatef(yrot, 0, 1, 0);
glTranslated(0,0,-xrot);
mesh.Render;
// rendern
// Call the Displaylist of our Skybox
glCallList(List);
SwapBuffers(FDC);
end;
end.