SwapBuffer我用了,窗体的DoubleBuffer属性我也设置了。还是不行。

解决方案 »

  1.   

    你应该在窗体的OnPaint事件里重画物体和背景,或者响应WM_PAINT消息。也就是说你应该在OnPaint里写OnTimer里几乎同样的代码,只不过不进行旋转参数递增。
      

  2.   

    使用InvalidateRect(),而不是Invalidate()
    因为后者会重画整个画布,而前者只重画矩形区域,节省了时间,减少闪烁。
      

  3.   

    孤海闲鸥,请问你一个问题,在DELPHI中的FORM里面,如何调用OPENGL画图啊,要不要进行初始化,在DELPHI中,OPENGL的实用库和辅助库都用不了,应该怎么做呢?请你帮帮我,不胜感激!并有厚礼送上!多谢!
      

  4.   

    给你一OPENGL的初试化方法!unit MainOpenGL;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      OpenGL, StdCtrls, ExtCtrls;type
      TMainForm = class(TForm)
        procedure PreparePixelFormat(var Devc:HDC);
        procedure InitDC;
        procedure InitGL;
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
        procedure FormResize(Sender: TObject);
      private
        { Private declarations }
        DC:HDC;
        RC:HGLRC;
        procedure RenderScene;
        Protected
      public
        { Public declarations }
      end;var
      MainForm: TMainForm;         _no_mat: array[0..3] of GLfloat=(0.0,0.0,0.0,1.0);
            _ambient: array[0..3] of GLfloat=(0.7,0.7,0.7,1.0);
      _ambient_color: array[0..3] of GLfloat=(0.8,0.8,0.2,1.0);
            _diffuse: array[0..3] of GLfloat=(0.1,0.5,0.8,1.0);
           _specular: array[0..3] of GLfloat=(1.0,1.0,1.0,1.0);
           _emission: array[0..3] of GLfloat=(0.3,0.2,0.2,0.0);
       _no_shininess: array[0..0] of GLfloat=(0.0);
      _low_shininess: array[0..0] of GLfloat=(5.0);
     _high_shininess: array[0..0] of GLfloat=(100.0);
    implementation{$R *.DFM}// 画图部分
    procedure TMainForm.RenderScene;
    var
                Obj:GLUquadricObj;         no_mat:PGLfloat;
            ambient:PGLfloat;
      ambient_color:PGLfloat;
            diffuse:PGLfloat;
           specular:PGLfloat;
           emission:PGLfloat;
       no_shininess:PGLfloat;
      low_shininess:PGLfloat;
     high_shininess:PGLfloat;begin
             no_mat:=@_no_mat[0];
            ambient:=@_ambient[0];
      ambient_color:=@_ambient_color[0];
            diffuse:=@_diffuse[0];
           specular:=@_specular[0];
           emission:=@_emission[0];
       no_shininess:=@_no_shininess;
      low_shininess:=@_low_shininess;
     high_shininess:=@_high_shininess;   glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
      //1,   obj:=gluNewQuadric;
       glPushMatrix;
          glTranslatef(-0.75,0.75,0.0);
          glMaterialfv(GL_FRONT,GL_AMBIENT,no_mat);
          glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);
          glMaterialfv(GL_FRONT,GL_SPECULAR,no_mat);
          glMaterialfv(GL_FRONT,GL_SHININESS,no_shininess);
          glMaterialfv(GL_FRONT,GL_EMISSION,no_mat);
       gluSphere(Obj,0.1,10,10);
       glpopMatrix;
       gluDeleteQuadric(Obj);   SwapBuffers(DC);
    end;
    procedure TMainForm.PreparePixelFormat(var Devc:HDC);
    var
       hHeap:THandle;
       nColors,i:Integer;
       PFD:TPixelFormatDescriptor;
       ChosenPixelFormat:Integer;
    begin
       FillChar(PFD,SizeOf(TPixelFormatDescriptor),0);
       PFD.nSize:=SizeOf(TPixelFormatDescriptor);
       PFD.nVersion:=1;
       PFD.dwFlags:=PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL
                    or PFD_DOUBLEBUFFER;
       PFD.iPixelType:=PFD_TYPE_RGBA;
       PFD.cColorBits:=16;
       PFD.cDepthBits:=32;
       PFD.iLayerType:=PFD_MAIN_PLANE;
       ChosenPixelFormat:=ChoosePixelFormat(DevC,@PFD);
       if ChosenPixelFormat=0 then
          Raise ExcePtion.Create(' No failed!');
       SetPixelFormat(DevC,ChosenPixelFormat,@PFD);   end;procedure TMainForm.InitDC;
    begin
        DC:=GetDC(Handle);
        PreparePixelFormat(DC);
    end;procedure TMainForm.InitGL;
    begin
        glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity;
        glEnable(GL_LIGHTING);
        glEnable(GL_LIGHT0);
        glOrtho(-1,1,-1,1,-1,50);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity;
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_COLOR_MATERIAL);
        glShadeModel(GL_SMOOTH);
        gluLookAt(2,4,6,0,0,0,0,1,0);
        SwapBuffers(DC);
    end;procedure TMainForm.FormCreate(Sender: TObject);
    begin
        inherited;
        left:=0;
        top:=0;
        width:=Screen.Width;
        height:=Screen.Height;
        initDC;
        RC:=wglCreateContext(DC);
        wglMakeCurrent(DC,RC);
        initGL;
    end;procedure TMainForm.FormDestroy(Sender: TObject);
    begin
        wglMakeCurrent(0,0);
        wglDeleteContext(RC);
        ReleaseDC(Handle,DC);
    end;procedure TMainForm.FormResize(Sender: TObject);
    begin
        inherited;
        glViewPort(1,1,ClientWidth,ClientHeight);
         RenderScene;
    end;