- unit UTut4;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,OpenGL,
- ExtCtrls, StdCtrls;
- type
- TForm1 = class(TForm)
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure FormPaint(Sender: TObject);
- private
- { Private-Deklarationen }
- hrc : HGLRC;
- DC : HDC;
- procedure SetDCPixelFormat(Handle : HDC);
- procedure Render;
- public
- { Public-Deklarationen }
- end;
- var
- Form1: TForm1;
- obj : GLUQuadricOBJ;
- implementation
- {$R *.DFM}
- procedure TForm1.SetDCPixelFormat(Handle : HDC);
- var pfd : TPixelFormatDescriptor;
- nPixelFormat : Integer;
- begin
- {Feld wird mit 0en gefuellt}
- FillChar(pfd,SizeOf(pfd),0);
- with pfd do
- begin
- nSize := SizeOf(pfd);
- nVersion := 1;
- dwFlags := PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL;
- iPixelType := PFD_TYPE_RGBA;
- cColorBits := 24;
- cDepthBits := 32;
- iLayerType := PFD_MAIN_PLANE;
- end;
- nPixelFormat := ChoosePixelFormat(Handle, @pfd);
- SetPixelFormat(Handle, nPixelFormat, @pfd);
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- DC := GetDC(Form1.Handle);
- SetDCPixelFormat(DC);
- hrc:=wglCreateContext(DC);
- Obj:=gluNewQuadric;
- gluQuadricDrawStyle(Obj, GL_Fill);
- end;
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- wglDeleteContext(hrc);
- gluDeleteQuadric(Obj);
- end;
- procedure TForm1.Render;
- begin
- glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
- glTranslatef(0,0,-50);
- glColor3f(1.0,0,0);
- gluSphere(Obj, 0.2, 16, 16);
- SwapBuffers(DC);
- end;
- procedure TForm1.FormPaint(Sender: TObject);
- begin
- wglMakeCurrent(DC, hrc);
- render;
- wglMakeCurrent(0, 0);
- end;
- end.