openGL 3D編程方面C語言的較多,delphi openGL網上資料比較少。
看到warrially兄弟研究的很虎,很喜歡Delphi 游戲編程,也學學.
網上最原始的就是老外的一篇《Delphi下的OpenGL開發入門》被翻譯過來:
html">http://www.BkJia.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;
//=============借用這個最實用的最基礎的代碼
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 =
(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