如何使用wglCreateContextAttribsARB wglSwapBuffers

时间:2013-01-11 05:44:34

标签: delphi opengl delphi-xe2

尝试用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.

0 个答案:

没有答案