|
X??????????? [em3]
??????????????Delphi??OpenGL??
???????Delphi????OpenGL???????OpenGL????????????Delphi?????????Delphi????????????????Delphi??OpenGL????????
??????????????????????????????????Delphi??OpenGL???????????Delphi??????OpenGL????????? DOT????? delphi3d.net?????????????????????????????Accumulations buffers?????????????
????????????????????????????????????? D:\DOT??????Delphi???Tools????Options??Options???Library?????Library path??? ... ???????????? ... ?????????????D:\DOT??????????Add??????????????????????????Browsing path?????????????Library path??????????
??????????????????OpenGL?????
?????????????????????????????????Object Inspector??????BorderIcons????????biSystemMenu???????False????BorderStyle?????bsSingle???Height??480?Width??640????????????????????
?????????????????????????????????
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
end.
uses???DotWindow, GL, GLu, GLext???
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DotWindow, GL, GLu, GLext;
????????????????????????????
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DotWindow, GL, GLu, GLext;
type
TForm1 = class(TDotForm) //??????????TForm?????TDotForm
procedure FormPaint(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
bFullScreen : Bool; //?????????
rX, rY : GLuint; //????
procedure DrawScene;
procedure LoadExtensions;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
???????????OnCreate???????FormCreate?????????????OpenGL?????
procedure TForm1.FormCreate(Sender: TObject);
begin
bFullScreen := False;
rX := 360;
rY := 360;
if bFullScreen then
begin
dotSetDisplayMode(800, 600, 32, 60);
Self.BorderStyle := bsNone;
Self.Height := 600;
Self.Width := 800;
Self.WindowState := wsMaximized;
Self.Context.DC := GetDC(Self.Handle);
ShowCursor(False);
end;
Self.Context.QuickPF(32, 0, 24, 0, 0);
Self.Context.InitGL;
LoadExtensions;
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glClearColor(0, 0, 0, 0);
glMatrixMode(GL_PROJECTION);
gluPerspective(60.0, Self.ClientWidth / Self.ClientHeight, 1.0, 100.0);
glMatrixMode(GL_MODELVIEW);
end;
?????????????????DOT?????
dotSetDisplayMode
??????????????????????640?480?1024?768????????????8?16?32 ????32????????????????????60????
Self.Context.QuickPF
??????????????????????????????????????? ????????????????????????????? ???????
Self.Context.InitGL
??????????????OpenGL?Context?????????? [em10]??
???Self. ??????????????????
LoadExtensions
????OpenGL????????????
procedure TForm1.LoadExtensions;
procedure Load(const ext: String);
begin
if not glext_LoadExtension(ext) then
raise Exception.Create('This demo requires ' + ext + '!');
end;
begin
{*****************************************************************************
?????OpenGL????????????ICD????????
?????????
???????????D2006?????????????
?????ShowMessage
****************************************************************************}
Load('GL_ARB_multitexture');
Load('GL_EXT_texture_filter_anisotropic');
end;
OpenGL????????
?????????????OnPaint??????FormPaint?????OpenGL?????
procedure TForm1.FormPaint(Sender: TObject);
begin
DrawScene;
end;
DrawScene ??????
procedure TForm1.DrawScene;
begin
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
glLoadIdentity;
glTranslatef(0, 0, -3);
glRotatef(rX, 1, 0, 0);
glRotatef(rY, 0, 1, 0);
glBegin(GL_QUADS);
glColor3f(1, 0, 0);
glVertex3f(-0.5,-0.5, 0.5);
glVertex3f(0.5,-0.5, 0.5);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(-0.5, 0.5, 0.5);
///////////////////////////////////////
glColor3f(0, 1, 0);
glVertex3f(-0.5,-0.5,-0.5);
glVertex3f(-0.5, 0.5,-0.5);
glVertex3f(0.5, 0.5,-0.5);
glVertex3f(0.5,-0.5,-0.5);
//////////////////////////////////////
glColor3f(0, 0, 1);
glVertex3f(-0.5,-0.5,-0.5);
glVertex3f(-0.5,-0.5, 0.5);
glVertex3f(-0.5, 0.5, 0.5);
glVertex3f(-0.5, 0.5,-0.5);
//////////////////////////////////////
glColor3f(1, 1, 0);
glVertex3f(0.5,-0.5,-0.5);
glVertex3f(0.5, 0.5,-0.5);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(0.5,-0.5, 0.5);
/////////////////////////////////////
glColor3f(1, 0, 1);
glVertex3f(-0.5, 0.5,-0.5);
glVertex3f(-0.5, 0.5, 0.5);
glVertex3f(0.5, 0.5, 0.5);
glVertex3f(0.5, 0.5,-0.5);
////////////////////////////////////
glColor3f(1, 1, 1);
glVertex3f(-0.5,-0.5,-0.5);
glVertex3f(0.5,-0.5,-0.5);
glVertex3f(0.5,-0.5, 0.5);
glVertex3f(-0.5,-0.5, 0.5);
glEnd;
Self.Context.PageFlip;
end;
????????????????OnClose???????FormClose??????????
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
dotSetDisplayMode(0, 0, 0, 0);
end;
????????????dotSetDisplayMode(0, 0, 0, 0)??????????????????????????????
???????????????????????????????FormKeyDown????
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
case Key of
VK_UP:
begin
if rX = 0 then
rX := 360;
Dec(rX);
DrawScene;
end;
VK_DOWN:
begin
if rX = 720 then
rX := 360;
Inc(rX);
DrawScene;
end;
VK_LEFT:
begin
if rY = 0 then
rY := 360;
Dec(rY);
DrawScene;
end;
VK_RIGHT:
begin
if rY = 720 then
rY := 360;
Inc(rY);
DrawScene;
end;
VK_ESCAPE:
Close;
end;
end;
???????????????????????????????????Esc?????????
????????
???????????OpenGL??????????C/C++????????????????
DOT?????????OpenGL?????????????DOT???????????????OpenGL???????
Delphi????????????????????????Windows??????
??????????????OpenGL????
???????????????????????????
????? [em1]
QQ?245343050
|
|