1

DelphiでOpenGlを学習しようとしています..しかし、古いコードと言われたものを使用したこの小さなプログラムがあります。実行するとフォームが緑色に変わる単純なプログラムです。しかし、glFinish の代わりに wglSwapBuffers を使用したいのですが、glFinish を wglSwapBuffers に置き換えて PFD_DOUBLEBUFFER を PFD のフラグに追加すると、認識されません。私は用途に何か欠けていますか?

次に、自分の OpenGL コンテキストがかなり古くなっていることを知っています。wglCreateContextAttribsARB を使用してこれを修正するにはどうすればよいですか?

    unit First1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs,OpenGL,Menus;

type
  TForm2 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormPaint(Sender: TObject);
  private
    { Private declarations }
    GLContext   :   HGLRC;
    errorCode : GLenum;
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}


procedure TForm2.FormCreate(Sender: TObject);
var
  pfd: TPixelformatDescriptor;
  FormatIndex: integer;
begin
  fillchar(pfd,SizeOf(pfd),0);
  with pfd do
  begin
    nSize       := SizeOf(pfd);
    nVersion    := 1; {The current version of descriptor is 1};
    dwFlags     := PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER;
    iPixelType  := PFD_TYPE_RGBA;
    cColorBits  := 24;  {Support 24bit Color}
    cDepthBits  := 32;  {Depth of z-buffer}
    iLayerType  := PFD_MAIN_PLANE;
  end; {width}
  FormatIndex  := ChoosePixelFormat(Canvas.Handle,@pfd);
  SetPixelformat(Canvas.Handle,formatIndex,@pfd);
  GLContext := wglCreateContext(Canvas.Handle);
  wglMakeCurrent(Canvas.Handle,GLContext);
end; {FormCreate}

procedure TForm2.FormDestroy(Sender: TObject);
begin
  wglMakeCurrent(Canvas.Handle,0);
  wglDeleteContext(GLContext);
end;

procedure TForm2.FormPaint(Sender: TObject);
begin
 {background}
  glClearColor(0.0,0.4,0.0,0.0);
  glClear(GL_COLOR_BUFFER_BIT);
  wglSwapBuffers;


 {error checking}
  errorCode := glGetError;
  if errorCode<>GL_NO_ERROR  then
    raise Exception.Create('Error in Paint'#13+gluErrorString(errorCode));
end;

end.
4

0 に答える 0