帮忙看看这段代码为什么没有显示出所要的东西呢?(OpenGL画线)(50分)

  • 主题发起人 主题发起人 陈晨
  • 开始时间 开始时间

陈晨

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,opengl;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormShow(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
DC:HDC;
RC:HGLRC;
implementation

{$R *.dfm}
function SetupPixelFormat(var dc:HDC):Boolean;
var
ppfd:PPIXELFORMATDESCRIPTOR;
npixelformat:Integer;
begin
New(ppfd);
ppfd^.nSize:=sizeof(PIXELFORMATDESCRIPTOR);
ppfd^.nVersion:=1;
ppfd^.dwFlags:=PFD_DRAW_TO_WINDOW
or PFD_SUPPORT_OPENGL or
PFD_DOUBLEBUFFER;
ppfd^.dwLayerMask:=PFD_MAIN_PLANE;
ppfd^.iPixelType:=PFD_TYPE_COLORINDEX;
ppfd^.cColorBits:=8;
ppfd^.cDepthBits:=16;
ppfd^.cAccumBits:=0;
ppfd^.cStencilBits:=0;
npixelformat:=ChoosePixelFormat(dc, ppfd);
if (nPixelformat=0) then
begin
MessageBox(NULL, 'choosePixelFormat failed',
'Error', MB_OK);
Result:=False;
Exit;
end;
if (SetPixelFormat(dc, npixelformat, ppfd)= FALSE) then
begin
MessageBox(NULL, 'SetPixelFormat failed',
'Error', MB_OK);
Result:=False;
Exit;
end;
Result:=True;
Dispose(ppfd);
end;

procedure TForm1.FormShow(Sender: TObject);

begin
DC:=Canvas.Handle;
SetupPixelFormat(dc);
RC:=wglCreateContext(DC);
wglMakeCurrent(DC,RC);
glclearcolor(0.5,0.7,0.9,1.0);
glclear(GL_COLOR_BUFFER_BIT);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
wglMakeCurrent(0,0);
if RC<>null then
wglDeleteContext(RC);
if DC<>null then
ReleaseDC(Handle,DC);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
glbegin(GL_LINES);

glcolor3i(0,255,0);
glVertex2i(50,50);

glcolor3i(255,0,0);
glVertex2i(300,300);

glend();
//swapbuffers(dc);
gluLookAt(2, 4, 6, 0, 0, 0, 0, 1, 0);
SwapBuffers(DC);
end;

end.
 
是不是用gl绘图的大富翁们都破产了?
 
你应该定义一个光源,不然都是一片黑
 
我真的是一点也不会,好容易着了一本BCB的书就那么几页累死我了
 
有一本清化出的《面向对象OpenGl程序设计》里面讲的很详细,是为delphi5写的,你可以
看看。
 
我给写例子你,要不要?
 
to:yangxiao_jiang
我以前也在书店看到的,当时没有涉及图形编程所以没有买,现在找不到了。
to:cdyxl
当然要了,最好是入门级别的,加说明,谢谢。
不然,现在只要能实现简单的直线,圆环的绘制就可以了。
 
建议你去斑竹的主页看看
品雪其寒
http://www.jsinfo.net/nsfz/personal/pinxue/index.html
 
to:stlont
http://www.jsinfo.net/nsfz/personal/pinxue/index.html
不能登陆
 
你把gluLookAt(2, 4, 6, 0, 0, 0, 0, 1, 0);这句去了试试
 
给你一个简单的例子自己看看吧
画出一个红色方块。
用的aux库,自己搜索下。
我找到的一个叫GLAUXIMP.Dll,一个叫GLAUX.dll,都是1M多。
两个里面的函数有点不同。
unit ljqgl1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, opengl;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
[red]uses glaux;[/red] //注意!
{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
auxInitDisplayMode(AUX_SINGLE or AUX_RGBA);
auxInitPosition(0,0,500,500);
auxInitWindowW('simple');
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glRectf(-0.5,-0.5,0.5,0.5);
glFlush();
end;

end.


函数说明: (By LJQ 后的4个是我加入的)
unit Glaux;

interface

uses Windows,Opengl;

type
TAUX_RGBImageRec= record
sizeX, sizeY: GLint;
data: pointer;
end;
PTAUX_RGBImageRec= ^TAUX_RGBImageRec;

function auxDIBImageLoadA(const dibfile: PChar): PTAUX_RGBImageRec; stdcall;
procedure auxWireSphere(value: GLdouble);stdcall;
procedure auxSolidSphere(value: GLdouble);stdcall;
procedure auxWireCube(value: GLdouble);stdcall;
procedure auxSolidCube(value: GLdouble);stdcall;
procedure auxWireBox(value,value1,value2: GLdouble);stdcall;
procedure auxSolidBox(value,value1,value2: GLdouble);stdcall;
procedure auxWireTorus(value,value1: GLdouble);stdcall;
procedure auxSolidTorus(value,value1: GLdouble);stdcall;
procedure auxWireCylinder(value,value1: GLdouble);stdcall;
procedure auxSolidCylinder(value,value1: GLdouble);stdcall;
procedure auxWireIcosahedron(value: GLdouble);stdcall;
procedure auxSolidIcosahedron(value: GLdouble);stdcall;
procedure auxWireOctahedron(value: GLdouble);stdcall;
procedure auxSolidOctahedron(value: GLdouble);stdcall;
procedure auxWireTetrahedron(value: GLdouble);stdcall;
procedure auxSolidTetrahedron(value: GLdouble);stdcall;
procedure auxWireDodecahedron(value: GLdouble);stdcall;
procedure auxSolidDodecahedron(value: GLdouble);stdcall;
procedure auxWireCone(value,value1: GLdouble);stdcall;
procedure auxSolidCone(value,value1: GLdouble);stdcall;
procedure auxWireTeapot(value: GLdouble);stdcall;
procedure auxSolidTeapot(value: GLdouble);stdcall;

[blue]//BY LJQ
procedure auxInitDisplayMode(value: GLdouble);stdcall;
procedure auxInitPosition(x1,y1,x2,y2: GLdouble);stdcall;
procedure auxInitWindowA(title:LPCSTR);stdcall;
procedure auxInitWindowW(title:LPCSTR);stdcall;[/blue]


const
glaux1 = 'glaux.dll';
glaux2 = 'glauximp.dll';
AUX_RGB = 0;
AUX_RGBA = AUX_RGB;
AUX_INDEX = 1;
AUX_SINGLE = 0;
AUX_DOUBLE = 2;
AUX_DIRECT = 0;
AUX_INDIRECT = 4;


implementation

function auxDIBImageLoadA; external glaux1;
procedure auxWireSphere;external glaux1;
procedure auxSolidSphere;external glaux1;
procedure auxWireCube;external glaux1;
procedure auxSolidCube;external glaux1;
procedure auxWireBox;external glaux1;
procedure auxSolidBox;external glaux1;
procedure auxWireTorus;external glaux1;
procedure auxSolidTorus;external glaux1;
procedure auxWireCylinder;external glaux1;
procedure auxSolidCylinder;external glaux1;
procedure auxWireIcosahedron;external glaux1;
procedure auxSolidIcosahedron;external glaux1;
procedure auxWireOctahedron;external glaux1;
procedure auxSolidOctahedron;external glaux1;
procedure auxWireTetrahedron;external glaux1;
procedure auxSolidTetrahedron;external glaux1;
procedure auxWireDodecahedron;external glaux1;
procedure auxSolidDodecahedron;external glaux1;
procedure auxWireCone;external glaux1;
procedure auxSolidCone;external glaux1;
procedure auxWireTeapot;external glaux1;
procedure auxSolidTeapot;external glaux1;

[blue][red]//BY LJQ
procedure auxInitDisplayMode;external glaux1;
procedure auxInitPosition;external glaux1;
procedure auxInitWindowA;external glaux2;
procedure auxInitWindowW;external glaux2;[/red][/blue]



end.

 
后退
顶部