1

试图用delphi来精简OpenGl ..但我有这个小程序使用我被告知过时的代码。它只是一个简单的程序,运行时将表单变为绿色。但是我想使用 wglSwapBuffers 而不是 glFinish,但是当我用 wglSwapBuffers 替换 glFinish 并将 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