type
TForm1 =
class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
myRc,myDc, Box : Cardinal;
Texture : TglBitmap2D;
public
{ Public declarations }
procedure InitGl();
procedure DeInitGl();
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.InitGl();
begin
InitOpenGL();
myDc := GetDC(
Handle);
myRc := CreateRenderingContext(myDc,[opDoubleBuffered],24,16,8,0,0,0);
ActivateRenderingContext(myDc,myRc);
glClearColor(0.3, 0.3, 0.3, 0.0);
// Black Background
glClearDepth(1.5);
// Depth Buffer Setup
glEnable(GL_DEPTH_TEST);
glDepthFunc (GL_LEQUAL);
glEnable(glTEXTURE_2D);
// Enable Texture Mapping
glBitmapSetDefaultFilter(GL_LINEAR,GL_LINEAR);
// aus glBitmap.pas
Texture := TglBitmap2D.Create('
FileName.bmp oder tga oder jpg');
// Texture.AssignFromBitmap(temp);
// Texture.BuildMipMaps := False;
Texture.GenTexture();
end;
procedure TForm1.DeInitGl();
begin
Texture.Free;
DeactivateRenderingContext();
ReleaseDC(
Handle,myDc);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
InitGl();
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
DeInitGl();
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
glClear(GL_COLOR_BUFFER_BIT
or GL_DEPTH_BUFFER_BIT);
// TODO : Draw Hier
//glLoadIdentity();
Texture.Bind();
// bie Bedarf
// End Drawing
SwapBuffers(myDc);
end;
procedure TForm1.FormResize(Sender: TObject);
begin//
if (Height=0)
then Height := 1 ;
glViewport(0, 0, Width, Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, Width / Height, 1.0, 1000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
FormPaint(Self);
end;
procedure TForm1.FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
if Key=27
then Close();
end;
end.