Delphi openGL 编程入门
4081 点击·0 回帖
![]() | ![]() | |
![]() | openGL 3D编程方面C语言的较多,delphi openGL网上资料比较少。 看到warrially兄弟研究的很虎,很喜欢delphi 游戏编程,也学学. 网上最原始的就是老外的一篇《delphi下的OpenGL开发入门》被翻译过来: http://www.atcpu.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; interface 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 = (nSizeizeof(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 | |
![]() | ![]() |