- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- opengl, ExtCtrls;
- type
- TForm1 = class(TForm)
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure FormPaint(Sender: TObject);
- private
- FRC:HGLRC;
- FDC:HDC;
- procedure SetupPixelFormat(DC:HDC);
- { Private-Deklarationen }
- public
- { Public-Deklarationen }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.DFM}
- procedure TForm1.SetupPixelFormat(DC:HDC);
- var
- PFD: TPixelFormatDescriptor;
- nPixelFormat: Integer;
- begin
- FillChar(PFD, SizeOf(PFD), 0);
- with PFD do
- begin
- nSize := sizeof(pfd); // Länge der pfd-Struktur
- nVersion := 1; // Version
- iLayerType:= PFD_MAIN_PLANE; // Layer Type
- dwFlags := PFD_DRAW_TO_WINDOW // Buffer erlaubt zeichenen auf Fenster
- or PFD_SUPPORT_OPENGL; // Buffer unterstützt OpenGL drawing
- iPixelType := PFD_TYPE_RGBA; // RGBA Farbformat
- cColorBits := 32; // OpenGL Farbtiefe
- cDepthBits := 24; // OpenGL Farbtiefe
- end;
- nPixelFormat:= ChoosePixelFormat(DC, @PFD);
- SetPixelFormat(DC, nPixelFormat, @PFD);
- DescribePixelFormat(DC, nPixelFormat,sizeof(TPixelFormatDescriptor),pfd);
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- FDC := canvas.handle ;
- SetupPixelFormat(FDC);
- FRC:= wglCreateContext(FDC);
- wglMakeCurrent(FDC, FRC);
- end;
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- wglMakeCurrent(0, 0);
- wgldeletecontext(FDC);
- end;
- procedure TForm1.FormPaint(Sender: TObject);
- begin
- glclearcolor(0,0,0.5,0);
- glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
- glbegin(GL_TRIANGLES);
- glvertex3f(0,0,0);
- glvertex3f(0,1,0);
- glvertex3f(1,0,0);
- glend;
- glflush;
- end;
- end.