Hva jeg er støt på et problem... er ikke kommet ret langt med tutorialen....
Den har ville compile fint... indtil jeg kom til
SwapBuffers(Context.DeviceContext);
kommando'eN!
Fejl:
[Error] Unit1.pas(79): Object or class type required
kode:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OpenGL;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
TContext = record
RenderContext, DeviceContext : THandle;
end;
function SetupContext(Sender : TObject) : TContext;
var
PFD : PixelFormatDescriptor;
I : Integer;
begin
with TWinControl(Sender) do
Result.DeviceContext := GetDC(Handle);
ZeroMemory(@PFD,SizeOf(PFD));
with PFD do
begin
nSize := SizeOf(PixelFormatDescriptor);
nVersion := 1;
dwFlags := pfd_Support_OpenGL or pfd_Draw_to_Window or pfd_DoubleBuffer;
iPixelType := pfd_Type_RGBA;
cColorBits := 24;
cDepthBits := 32;
iLayerType := pfd_Main_Plane
end;
I := ChoosePixelFormat(Result.DeviceContext,@PFD);
if I = 0 then
Exit;
if not SetPixelFormat(Result.DeviceContext, I, @PFD) then
Exit;
Result.RenderContext := wglCreateContext(Result.DeviceContext);
if Result.RenderContext = 0 then
Exit;
if not wglMakeCurrent(Result.DeviceContext, Result.RenderContext) then
Exit;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
Context : TContext;
begin
//Referer til vores Funktion, der vil returnere en context til vores form
Context := SetupContext(Form1);
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
// Definere farven der skal overskrive Color bufferen
glClearColor(0,0,0,0);
// Overskriver Color Bufferen
glClear(gl_Color_Buffer_Bit);
// Benytter OpenGL's Color buffer med Windows (GDI'en)
SwapBuffers(Context.DeviceContext);
end;
end.
(Bruger Delphi 7 ved ikke hvorfor en version OpenGL)