11. maj 2002 - 17:30Der er
30 kommentarer og 1 løsning
www.opengl-delphi.dk
Hej
Jeg er igang med at læse tutorialsne om opengl inde på www.opengl-delphi.dk men da jeg satte "TNewContext = record" sagde den "Expected ':' but '=' found." hvad har jeg gjort galt.
TNewContext = record dc: hdc; rc: hglrc; end; TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormPaint(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1; NC : TNewContext;
implementation
{$R *.dfm}
function SetupOpenGL(dc : hdc; rc : hglrc; form : Tform; zNear, zFar : single) : TNewContext; var pfd: TPixelFormatDescriptor; i : integer; begin fillchar(pfd,SizeOf(pfd),0); with pfd do begin nsize := sizeof(pfd); nversion := 1; dwflags := pfd_support_opengl or pfd_draw_to_window or pfd_doublebuffer; ipixeltype := pfd_type_rgba; ccolorbits := 24; cdepthbits := 32; cstencilbits := 0; ilayertype := pfd_main_plane; end; dc := getdc(form.handle); i := choosepixelformat(dc,@pfd); if i = 0 then exit; if not setpixelformat(dc,i,@pfd) then exit; rc := wglcreatecontext(dc); if rc = 0 then exit; if not wglmakecurrent(dc,rc) then exit; glmatrixmode(gl_projection); with form do glfrustum(-1.0, +1.0, -(clientheight/clientwidth), clientheight/clientwidth, zNear, zFar); result.dc := dc; result.rc := rc; end;
procedure ReleaseOpenGL(MyContext : TNewContext; MyForm : TForm); begin with MyContext do begin wglmakecurrent(dc,0); wgldeletecontext(rc); releasedc(MyForm.handle,dc); end; end;
procedure TForm1.FormCreate(Sender: TObject); begin with NC do NC := SetupOpenGL(dc,rc,form1,2,30); end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin ReleaseOpenGL(NC,form1);
end;
procedure TForm1.FormPaint(Sender: TObject); begin SwapBuffers(NC.dc); end;
type TNewContext = record dc: hdc; rc: hglrc; end; TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure FormPaint(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1; NC : TNewContext;
implementation
{$R *.DFM}
function SetupOpenGL(dc: hdc; rc: hglrc; Form: Tform; zNear, zFar: Single): TNewContext; var pfd: TPixelFormatDescriptor; I : integer; begin FillChar(pfd, SizeOf(pfd), 0); with pfd do begin nSize := sizeof(pfd); nVersion := 1; dwFlags := PFD_SUPPORT_OPENGL or PFD_DRAW_TO_WINDOW or PFD_DOUBLEBUFFER; iPixelType := PFD_TYPE_RGBA; cColorBits := 24; cDepthBits := 32; cStencilBits := 0; iLayerType := PFD_MAIN_PLANE; end; dc := GetDC(Form.Handle); I := ChoosePixelFormat(dc, @pfd); if I = 0 then Exit; if not SetPixelFormat(dc, I, @pfd) then Exit; rc := wglCreateContext(dc); if rc = 0 then Exit; if not wglMakeCurrent(dc, rc) then Exit; glMatrixMode(GL_PROJECTION); with Form do glFrustum(-1.0, +1.0, -(ClientHeight/ClientWidth), ClientHeight/ClientWidth, zNear, zFar); Result.dc := dc; Result.rc := rc; end;
procedure ReleaseOpenGL(MyContext: TNewContext; MyForm: TForm); begin with MyContext do begin wglMakeCurrent(dc, 0); wglDeleteContext(rc); ReleaseDC(MyForm.Handle, dc); end; end;
procedure TForm1.FormCreate(Sender: TObject); begin with NC do NC := SetupOpenGL(dc, rc, Form1, 2, 30); end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin ReleaseOpenGL(NC, Form1); end;
procedure TForm1.FormPaint(Sender: TObject); begin glClearColor(0.0,0.0,0.0,0.0); glClear(gl_Color_Buffer_Bit);
Du skal huske at læse ALLE tutorials'ene igennem... De er lavet således, at man ikke kan forstå den sidste, hvis man ikke har læst og forstået den første del af den.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.