急求旋转立方体程序  哪位若有的话,请发邮件到[email protected]
多谢了

解决方案 »

  1.   

    opengl到有个例子,不过不是立方体的,要吗?
      

  2.   

    unit uPrincipal;interfaceuses
        Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
        OpenGL, ExtCtrls;type
      TPrincipal = class(TForm)
        procedure FormCreate(Sender: TObject);
        procedure FormResize(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      Protected { Protected declarations }
        Procedure WMPaint (Var Msg : TWMPaint); Message WM_PAINT;  private { Private declarations }
        DC : HDC;
        HRC : HGLRC;
        Procedure SetDCPixelFormat;  public { Public declarations }  end;var
      Principal: TPrincipal;
      FPS, Angle : GLFloat;
      NewCount, LastCount, FrameCount : Integer;implementation{$R *.dfm}Procedure TPrincipal.WMPaint (Var Msg : TWMPaint);
    Var
      Ps : TPaintStruct;
    Begin
      BeginPaint (Handle, Ps);
      NewCount := GetTickCount;
      Inc (FrameCount);
      If (NewCount - LastCount) > 1000 Then
      Begin
         Caption := Format ('MAD GLcube - %f fps', [FrameCount * 1000 / (NewCount - LastCount)]);
         LastCount := NewCount;
         FrameCount := 0;
      End;
      glClear (GL_COLOR_BUFFER_BIT Or GL_DEPTH_BUFFER_BIT);                   // Clear color & depth buffers
      glLoadIdentity;
      glTranslatef (0.0, 0.0, -8.0);                                          // Polygon depth
      glRotatef (30.0, 1.0, 0.0, 0.0);
      glRotatef (Angle, 0.0, 1.0, 0.0);
      glBegin (GL_POLYGON);
             glNormal3f (0.0, 0.0, 1.0);
             glVertex3f (1.0, 1.0, 1.0);
             glVertex3f (-1.0, 1.0, 1.0);
             glVertex3f (-1.0, -1.0, 1.0);
             glVertex3f (1.0, -1.0, 1.0);
      glEnd;
      glBegin (GL_POLYGON);
             glNormal3f (0.0, 0.0, -1.0);
             glVertex3f (1.0, 1.0, -1.0);
             glVertex3f (1.0, -1.0, -1.0);
             glVertex3f (-1.0, -1.0, -1.0);
             glVertex3f (-1.0, 1.0, -1.0);
      glEnd;
      glBegin (GL_POLYGON);
             glNormal3f (-1.0, 0.0, 0.0);
             glVertex3f (-1.0, 1.0, 1.0);
             glVertex3f (-1.0, 1.0, -1.0);
             glVertex3f (-1.0, -1.0, -1.0);
             glVertex3f (-1.0, -1.0, 1.0);
      glEnd;
      glBegin (GL_POLYGON);
             glNormal3f (1.0, 0.0, 0.0);
             glVertex3f (1.0, 1.0, 1.0);
             glVertex3f (1.0, -1.0, 1.0);
             glVertex3f (1.0, -1.0, -1.0);
             glVertex3f (1.0, 1.0, -1.0);
      glEnd;
      glBegin (GL_POLYGON);
             glNormal3f (0.0, 1.0, 0.0);
             glVertex3f (-1.0, 1.0, -1.0);
             glVertex3f (-1.0, 1.0, 1.0);
             glVertex3f (1.0, 1.0, 1.0);
             glVertex3f (1.0, 1.0, -1.0);
      glEnd;
      glBegin (GL_POLYGON);
             glNormal3f (0.0, -1.0, 0.0);
             glVertex3f (-1.0, -1.0, -1.0);
             glVertex3f (1.0, -1.0, -1.0);
             glVertex3f (1.0, -1.0, 1.0);
             glVertex3f (-1.0, -1.0, 1.0);
      glEnd;
      SwapBuffers (DC);
      If Angle = 360.0 Then Angle := 0.0;
      Angle := Angle + 1.0;
      EndPaint (Handle, Ps);
      InvalidateRect (Handle, Nil, False);  // Force window repaint
    End;Procedure TPrincipal.SetDCPixelFormat;
    Const
      Pfd: PIXELFORMATDESCRIPTOR = (
           nSize : SizeOf (PIXELFORMATDESCRIPTOR);
           nVersion : 1;
           dwFlags : PFD_DRAW_TO_WINDOW Or PFD_SUPPORT_OPENGL Or PFD_DOUBLEBUFFER;
           iPixelType : PFD_TYPE_RGBA;
           cColorBits : 32;
           cRedBits : 0;
           cRedShift : 0;
           cGreenBits : 0;
           cBlueBits : 0;
           cBlueShift : 0;
           cAlphaBits : 0;
           cAlphaShift : 0;
           cAccumBits : 0;
           cAccumRedBits : 0;
           cAccumGreenBits : 0;
           cAccumBlueBits : 0;
           cAccumAlphaBits : 0;
           cDepthBits : 32;
           cStencilBits : 0;
           cAuxBuffers : 0;
           iLayerType : PFD_MAIN_PLANE;
           bReserved : 0;
           dwLayerMask : 0;
           dwVisibleMask : 0;
           dwDamageMask : 0);
    Var
      PixelFormat : Integer;
    Begin
      PixelFormat := ChoosePixelFormat (DC, @Pfd);
      SetPixelFormat (DC, PixelFormat, @Pfd);
    End;procedure TPrincipal.FormCreate(Sender: TObject);
    Const
      LightAmbient : Array [0..3] Of GLfloat = (0.1, 0.1, 0.1, 1.0);
      LightDiffuse : Array [0..3] Of GLfloat = (0.7, 0.7, 0.7, 1.0);
      LightSpecular : Array [0..3] Of GLfloat = (0.0, 0.0, 0.0, 1.0);
      LightPosition: Array [0..3] Of GLfloat = (0.0, 0.0, 2.0, 1.0);
      MaterialColor : Array [0..3] Of GLfloat = (0.0, 0.0, 1.0, 0.0);
    Begin
      DC := GetDC (Handle);                                   // Initialize the rendering context
      SetDCPixelFormat;
      HRC := wglCreateContext (DC);                           // Make a GL Context
      wglMakeCurrent (DC, HRC);
      glClearColor(0.0, 0.0, 0.0, 0.0);                     // Clear background color to black
      glClearDepth(1.0);                         // Clear the depth buffer
      glDepthFunc(GL_LESS);                     // Type of depth test
      glShadeModel (GL_SMOOTH);                     // Smooth color shading
      glEnable (GL_DEPTH_TEST);                     // Depth test
      glMatrixMode (GL_PROJECTION);
      glLoadIdentity;                         // Reset projection matrix
      gluPerspective (45.0, Width / Height, 0.1, 100.0);      // Aspect ratio of the viewport
      glMatrixMode (GL_MODELVIEW);
      glLightfv (GL_LIGHT0, GL_AMBIENT, @LightAmbient);       // Create light
      glLightfv (GL_LIGHT0, GL_DIFFUSE, @LightDiffuse);
      glLightfv (GL_LIGHT0, GL_SPECULAR, @LightSpecular);
      glLightfv (GL_LIGHT0, GL_POSITION, @LightPosition);     // Light position
      glEnable (GL_LIGHTING);
      glEnable (GL_LIGHT0);
      glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, @MaterialColor);  // Reflective properties
      Angle := 0;
    End;procedure TPrincipal.FormResize(Sender: TObject);
    Begin
      glViewport (0, 0, Width, Height);       // Reset The Current Viewport And Perspective Transformation
      glMatrixMode (GL_PROJECTION);
      glLoadIdentity;
      gluPerspective (30.0, Width / Height, 0.1, 100.0);
      glMatrixMode(GL_MODELVIEW);
      InvalidateRect (Handle, Nil, False);  // Force window repaint
    End;procedure TPrincipal.FormDestroy(Sender: TObject);
    begin
      wglMakeCurrent (0, 0);
      wglDeleteContext (HRC);
      ReleaseDC (Handle, DC);
    end;end.
      

  3.   

    http://www.csdn.net/Develop/read_article.asp?id=20109