Delphi openGL 编程入门<一>
openGL 3D编程方面C语言的较多,delphi openGL网上资料比较少。
看到warrially兄弟研究的很虎,很喜欢Delphi 游戏编程,也学学.
网上最原始的就是老外的一篇《Delphi下的OpenGL开发入门》被翻译过来:
html">http://www.zzzyk.com/kf/201012/79716.html
一般都在Draw里面,也可以其他单元独立出来。
procedure TForm1.Draw;
begin
//==============================================================================
// GL画图开头
//==============================================================================
glBegin( GL_POINTS);
glEnd();
//------------------------------------------------------------------------------
// GL画图结尾
//------------------------------------------------------------------------------
SwapBuffers(wglGetCurrentDC);
end;
基本的图形无非 点线多边形球曲面。glBegin()命令常用枚举常量
函数为:
procedure glBegin(mode: GLenum);stdcall;
procedure glEnd;stdcall;
枚举常量 | 意义 | 值 |
GL_POINTS | 绘制点 | $0000 |
GL_LINES | 绘制线段 | $0001 |
GL_LINE_STRIP | 绘制折线 | $0002 |
GL_LINE_LOOP | 绘制闭合折线 | $0003 |
GL_TRIANGLES | 绘制三角形 | $0004 |
GL_TRIANGLE_STRIP | 绘制连续三角形 | $0005 |
GL_TRAINGLE_FAN | 绘制三角扇形 | $0006 |
GL_QUADS | 绘制四边形 | $0007 |
GL_QUAD_STRIP | 绘制连续四边形 | $0008 |
GL_POLYGON | 绘制多边形 | $0009 |
//=============借用这个最实用的最基础的代码
unit openGLdemo;
inte易做图ce
uses
OpenGL, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, ComCtrls;
type
TForm1 = class(TForm)
pnl1: TPanel;
tmr1: TTimer;
procedure FormCreate(Sender: TObject);
procedure tmr1Timer(Sender: TObject);
private
procedure Draw; //Draws an OpenGL scene on request
public
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure setupPixelFormat(DC:HDC);
const
pfd:TPIXELFORMATDESCRIPTOR =
(nSize:sizeof(TPIXELFORMATDESCRIPTOR); // size
nVersion:1; // version
dwFlags:PFD_SUPPORT_OPENGL or PFD_DRAW_TO_WINDOW or PFD_DOUBLEBUFFER; // support double-buffering
iPixelType:PFD_TYPE_RGBA; // color type
cColorBits:24; // preferred color depth
cRedBits:0; cRedShift:0; // color bits (ignored)
cGreenBits:0; cGreenShift:0;
cBlueBits:0; cBlueShift:0;
cAlphaBits:0; cAlphaShift:0; // no alpha buffer
cAccumBits: 0;
cAccumRedBits: 0; // no accumulation buffer,
cAccumGreenBits: 0
补充:软件开发 , Delphi ,