解决方案 »
- dxDBGrid中的列如何与从数据库中查出的数据的列一一对应上?
- 我想在访问d盘的时候有个密码验证,就是要输入密码才能访问,请问怎么办?我说的是在操作系统里,不是程序中。
- 有哪位知道学习做Delphi游戏方面入门的书?
- FastReport复合报表问题
- 怎么遍历树或者遍历树的某个子节点啊
- 报表问题
- 如果取xml的某个节点啊,高手救我啊
- ADO问题——:”初始化提供者时发生错误,测试连接失败。无法启动应用程序。工作组信息文件丢失,或是已被其他用户以独占方式打开。”
- 我的代码能在另外一家公司用吗?
- 数据库的备份
- 常見這樣的語句怎么也沒弄明白(if form2.showmodal=mrok then...),幫解釋
- dbgrid里如何计算某个字段的所有值?
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.