Wie bekomme ich eine OpenGL Objekt in einen Delphi Frame (Delphi 5) ?
Announcement
Collapse
No announcement yet.
OpenGL in Delphi Form
Collapse
X
-
So gehts:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
OpenGL12, AppEvnts;
type
TForm1 = class(TForm)
ApplicationEvents1: TApplicationEvents;
procedure FormCreate(Sender: TObject);
procedure ApplicationEvents1Idle(Sender: TObject; var Done: Boolean);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
DC : HDC;
RC : HGLRC;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
var
DummyPal : HPalette;
begin
DC := GetDC(Handle);
RC := CreateRenderingContext(DC, [opDoubleBuffered], 32, 24, 0, 0, 0, 0, DummyPal);
ActivateRenderingContext(DC, RC);
end;
procedure TForm1.ApplicationEvents1Idle(Sender: TObject;
var Done: Boolean);
begin
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glClearColor(0,0,0,0);
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);
glOrtho(-2.0, 2.0, -2.0, 2.0, -2.0, 2.0);
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glFlush();
SwapBuffers(DC);
end;
end.
Um den Code zu compilieren benötigt Ihr nur noch OpenGL12. Das gibt es in vielen Tutorials zu OpenGL als Download
Comment
Comment