SwapBuffer我用了,窗体的DoubleBuffer属性我也设置了。还是不行。
解决方案 »
- 用APRO怎样得到modem接通信息
- game 版怎么那么冷?散分
- 类的创建
- Parent和Owner的关系(注意不是VCL概念).
- 请教有关报表打印的问题
- 急需TIF解决方案(解决一定给高分)
- 一个数据库错误的问题。
- 请问如何响应动态建立的菜单项事件?
- 如何用sql 語句將某個字段值設為null
- 使用WebBrowser控件时,如何使弹出新的Pop窗体使用自己定制的Webbrowser窗体?
- 我准备使用IC卡进行程序控制,不过我是第一次接触.想请教几个问题.
- 菜鸟求救:Delphi第三方控件到底如何安装?为什么我以选择COMPILER按钮就说有Internel Error:URW3XXX什么的错误?是不是因为是D版的缘故
因为后者会重画整个画布,而前者只重画矩形区域,节省了时间,减少闪烁。
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;