Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Darhazer

GLUT in Delphi

This topic is 5759 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have the GLUT library, downloaded from www.opengl.org but I have no C++ compiler... and I prefer to write games in Delphi Is there any way to use GLUT whitin Delphi? I''ve heard that there is a converter for .h files into Delphi libraries... I was searching the .net for Delphi version of GLUT library but found no one Can anyone tell help?

Share this post


Link to post
Share on other sites
Advertisement
i know that this isnt the answer your looking for but anyway : GLUTs main function is to create a window and handle input functions like keyboard and joystick, and for timing, and all this in a OS independent way.

Delphi creates the window for you (with kylix in an dual os way) helps you with input (keyboard, i dont know about joystick) and timing, all in the kylix dual OS way.. and on other systems (not linux or windows) you cant compile delphi-code anyway.. so why use GLUT in delphi?

Share this post


Link to post
Share on other sites
Did you ever used OpenGL in Delphi?
I need GLUT for two reasons. First of all, you can render OpenGL direct to the form... I''ve tried some days to render OpenGL scene, but all I have find was some examples on rendering via GLScene. But I don''t want to use GLScene. I;ve tried many ways - Paint Event, working in Canavs... Read a lot of OpenGL but nothing helps. Then, due to another OpenGL forum, I found dosens of examples And in no one the Form, generated by Delphi was used. There all used function WinMain() (which handles the Windows messages) and create own windows. But unlike C++ in Paskal this isn''t standart task, this isn''t so easy and... It is unnatural
One of the reason is to create window. Another to use rendering function like glutWireSpehre.

And, if you are interested, I will paste the code for WinMain()
But if I use that code, I won''t be able to compile the game under Linux with Kylix

function WinMain(hInstance: HINST; hPrevInstance: HINST; lpCmdLine: PChar; nCmdShow: integer): integer; stdcall;
var
msg: TMsg;
wc: TWndClass;
h_Wnd: HWND;
dmScreenSettings: TDEVMODE;

begin
ZeroMemory( @wc, sizeof( wc ) );

wc.style := CS_HREDRAW or CS_VREDRAW or CS_OWNDC;
wc.lpfnWndProc := @WndProc;
wc.hInstance := hInstance;
wc.hCursor := LoadCursor(0, IDC_ARROW);
wc.lpszClassName := ''OpenGL WinClass'';

if(RegisterClass(wc)=0) then
begin
MessageBox(0,''Failed To Register The Window Class.'',''Error'',MB_OK or MB_ICONERROR);
Result := 0;
exit;
end;

h_Wnd := CreateWindow(
''OpenGL WinClass'',
''AlexeyGL'',
WS_POPUP or
WS_CLIPCHILDREN or
WS_CLIPSIBLINGS,
0, 0,
640, 480,
0,
0,
hInstance,
nil);

if (h_Wnd = 0) then
begin
MessageBox(0,''Window Creation Error.'',''Error'',MB_OK or MB_ICONERROR);
Result := 0;
exit;
end;

ZeroMemory( @dmScreenSettings, sizeof( TDEVMODE ) );
dmScreenSettings.dmSize := sizeof( TDEVMODE );
dmScreenSettings.dmPelsWidth := 640;
dmScreenSettings.dmPelsHeight := 480;
dmScreenSettings.dmFields := DM_PELSWIDTH or DM_PELSHEIGHT;
ChangeDisplaySettings(dmScreenSettings, CDS_FULLSCREEN);

ShowWindow(h_Wnd, SW_SHOW);
UpdateWindow(h_Wnd);
SetFocus(h_Wnd);

while ( true ) do
begin
while (PeekMessage(msg, 0, 0, 0, PM_NOREMOVE)) do
begin
if (GetMessage(msg, 0, 0, 0)) then
begin
TranslateMessage(msg);
DispatchMessage(msg);
end
else
begin
Result := 1;
exit;
end;
end;

DrawGLScene();
SwapBuffers(h_DC);

if (keys[VK_ESCAPE]) then SendMessage(h_Wnd,WM_CLOSE,0,0);
end;
end;

"What do you think you were created for..."
To be Game Maker

Share this post


Link to post
Share on other sites
Hi

You are not alone!

The first thing you should do is get yourself registered at DGDev. You''ll be surprised how many game developers use Delphi

You can use OpenGL quite easily with Delphi forms. I usually use a TPanel as this lets you control where you draw the OpenGL stuff.

The best OpenGL headers I''ve found for Delphi are here.

Alternatively if you want to make it platform independent you could try JEDI-SDL which is a Delphi version of SDL.

Anyway, back to using OpenGL with forms:

Here''s a procedure for setting the PixelFormat

Procedure TForm1.SetDCPixelFormat;
Const
Pfd : PIXELFORMATDESCRIPTOR = (
nSize : SizeOf (PIXELFORMATDESCRIPTOR);
nVersion : 1;
dwFlags : PFD_DRAW_TO_bitmap{ Or PFD_SUPPORT_OPENGL }Or PFD_DOUBLEBUFFER;
iPixelType : PFD_TYPE_RGBA;
cColorBits : 16;
cRedBits : 0;
cRedShift : 0;
cGreenBits : 0;
cBlueBits : 0;
cBlueShift : 0;
cAlphaBits : 0;
cAlphaShift : 0;
cAccumBits : 0;
cAccumRedBits : 0;
cAccumGreenBits : 0;
cAccumBlueBits : 0;
cAccumAlphaBits : 0;
cDepthBits : 32;
cStencilBits : 0;
cAuxBuffers : 0;
iLayerType : PFD_MAIN_PLANE;
bReserved : 0;
dwLayerMask : 0;
dwVisibleMask : 0;
dwDamageMask : 0);
Var
PixelFormat : Integer;
Begin
PixelFormat := ChoosePixelFormat (DC, @Pfd);
SetPixelFormat (DC, PixelFormat, @Pfd);
End;


And you use it like this

InitOpenGL; //This is from the OpenGL header file
DC := GetDC (panel1.Handle);
SetDCPixelFormat;
HRC := wglCreateContext (DC);
wglMakeCurrent (DC, HRC);


Now you have a rendering context you can do all your OpenGL stuff abd then call

SwapBuffers(dc);

to show it on the screen.

You''ll need to work out how to put this into your own code of course but it''s not that difficult.

If you need any more help, just ask, either here or at DGDev!



______________________________

DGDev - The Delphi Games Development Community

Share this post


Link to post
Share on other sites
Darhazer, im using delphi all the time and drawing inside a normal form is my main use. i made a own little simple component that works like a panel, but dont listens to the WM_erasebkgnd so it removes the possible flicker caused by a redraw. (http://mazy.annat.nu/files/Delphi/Components)

so the first reason is pretty much covered.
and for glutWiredSphere and such.. well soon you will se that those are just a less flexible version of the gluQuadric and nearly all those functions is still only for testin purposes. When you want to draw something funnier you create polygons by code, or load models from standard 3d package.

Om not forcing you to do it the ''delphi'' way, but i just thought it was easier

Share this post


Link to post
Share on other sites
Thank to all of us
You really help me
If there any GLScene tutorials on the web? I have only the official reference, which is not too usefull for learning?

"What do you think you were created for..."
To be Game Maker

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!