Archived

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

bobbias

API's, DirectX, OpenGL? What's It All Mean?

Recommended Posts

Please Help Me, (Okay So I Sound Desperate... I Am!) I have some Questions I''d like answered, if you could. #1 What the heck is an API? #2 Can they be used in Delphi/Pascal? #3 If so, how do you use them? #4 Can I use DirectX in Delphi/Pascal? #5 If so, how do you use it? #6 What is OpenGL? #7 Can I use it in Delphi/Pascal? #8 If so, how do you use it? Oh, and if you can tell me how to use graphics and music in Delphi/Pascal, Please tell me! Thanks in advance.

Share this post


Link to post
Share on other sites
I try to answer as much questions as possible.

Q1. What the heck is an API?
A1. Application Programming Interface. It''s a set of functions used to wrote programs. It''s like a library.

Q2. Can they be used in Delphi/Pascal?
A2. If the API''s have SDK''s/libs for Delphi/Pascal, yes. Otherwise I don''t think so

Q3. If so, how do you use them?
A3. Download the SDK/programming libs, read the manual and your ready to go

Q4. Can I use DirectX in Delphi/Pascal?
A4. No idea. Anyone else?

Q5. If so, how do you use it?
A5. You should download a SDK for Delphi/Pascal. However, DirectX can only be used in Win32 or Win32 console apps.

Q6. What is OpenGL?
A6. OpenGL is a Graphics API avaliable for different platforms and completely open-source. Looks alot like DirectX but is more 3D oriented.

Q7. Can I use it in Delphi/Pascal?
A7. No idea, ask www.google.nl

Q8. If so, how do you use it?
A8. Download the SDK, read some tutorials and your done.

Sand Hawk


----------------
-Earth is 98% full. Please delete anybody you can.


My Site

Share this post


Link to post
Share on other sites
quote:
Original post by bobbias
Please Help Me, (Okay So I Sound Desperate... I Am!)
I have some Questions I''d like answered, if you could.

#1 What the heck is an API?

Foldoc definition
In short, it''s a set of functions and/or classes that you use to get things done. An example is Win32, which is the underlying API for Windows. They provide a layer of abstraction over something (such as 3D hardware).

quote:
#2 Can they be used in Delphi/Pascal?

Yep

quote:
#3 If so, how do you use them?

In the case of Delphi, you simply get an appropriate .PAS file (for example, from the big list over at Delphi-JEDI). You may sometimes require to distribute a DLL too, but that''ll be mentioned in the docs. Note that in other languages you have to download *massive* SDKS (e.g. the DirectX one, >140Mbytes IIRC). You don''t need that for Delphi.

quote:
#4 Can I use DirectX in Delphi/Pascal?

Yep. Find the converted units over at here.

quote:
#5 If so, how do you use it?

You define interfaces (which provide functions for you to call) for the appropriate thing - e.g. IDirectDraw7. You''ll have to look out for tutorials though, because it''s not a "try things and see what happens".

quote:
#6 What is OpenGL?

Open Graphics Library. You can use it to access the 3D hardware and draw things to the screen using hardware acceleration. See also NeHe (includes Delphi source).

quote:
#7 Can I use it in Delphi/Pascal?

Yep. See NeHe, Sulaco, Delphi3D, DelphiGL, GLScene (you''ll have to google that one).

quote:
#8 If so, how do you use it?

There should be an OpenGL.pas file with Delphi. You might want to get a better one (search for Mike Lischke''s OpenGL12.pas, if I got the name and author right). Whatever, you add "opengl" to your uses clause, call the appropriate functions, and party on.

quote:
Oh, and if you can tell me how to use graphics and music in Delphi/Pascal, Please tell me!

Thanks in advance.

You might want to have a look at DelphiX, which is a component set allowing you to use DirectX features easily. You can also get other libraries (GLScene), using Graphics libraries, get FMod, BASS or DirectSound for your sound, SDL (cross platform)...

There are dozens of options. That''s part of the battle; try various things to see if you find any you like.

Share this post


Link to post
Share on other sites
quote:
Original post by Sand_Hawk
A6. OpenGL is a Graphics API avaliable for different platforms and completely open-source. Looks alot like DirectX but is more 3D oriented.



OpenGL is a standard. The "Open" means an open standard, not open source. Thats like saying "C++ is open source!".

Share this post


Link to post
Share on other sites
Doh! That was a slightly poor choice of words. I meant "declare" rather than "define". Here's an example:

  unit DXScreen;

interface

uses
DirectDraw; <-- lets us use the DirectDraw interfaces/functions

type
TDXScreen = class
private
FDD7: IDirectDraw7; <-- an DDraw7 interface object
FClipper: IDirectDrawClipper; <-- clip objects to the screen
FPrimary: IDirectDrawSurface7; <-- main screen display
FBack: IDirectDrawSurface7; <-- draw onto this
protected
public
// todo -- lots of functions here

end;

The idea is that each of those interfaces contain functions that you can use. The IDirectDraw7 interface provides you with a way to create surfaces, onto which you draw things. The IDirectDrawSurface7 interface lets you draw bitmaps and change pixels (it's the main drawing thing). You'd load bitmaps onto a separate surface (you can have many surfaces) then "blit" that surface onto your back buffer surface.

You are meant to do all of your work onto the back buffer then, once a frame, call flip() to exchange the surfaces and display what you've drawn. This is very quick, but remember to *always* draw onto the back buffer, not the front one (unless you want nasty flickering, etc.).

Here's a little snippet of how you'd draw onto the back buffer:

  procedure TDXScreen.Draw(const Dest, Source: PRect; const Image: TDXImage);
begin
FBack.Blt(Dest, Image.Surface, Source, DDBLT_WAIT, nil);
end;

That code makes the assumption that you'll wrap up surfaces into another class (which is usually a good idea). The TDXImage class would contain things to let you load bitmaps, check the size, etc.

Flipping the screen:

  procedure TDXScreen.Flip;
begin
FPrimary.Flip(nil, DDFLIP_WAIT);
end;

Code for filling a rectangle with a colour might look like this:
  procedure TDXScreen.FillRect(const FillArea: PRect; const Colour: PIXEL_TYPE);
var
fx: TDDBLTFX;
begin
FillChar(fx, SizeOf(fx), 0);
fx.dwSize := SizeOf(fx);
fx.dwFillColor := Colour;

FBack.Blt(FillArea, nil, nil, DDBLT_WAIT or DDBLT_COLORFILL, @fx);
end;

The Blt function in IDirectSurface7 can either copy from a surface or it can fill with a colour (with the specified colour supplied in a TDDBLTFX structure.

Initialising DDraw is quite an involved process, but once you've done it it is simply a copy-and-paste job for the next project. You'll want to wrap up this crap into a set of classes unless you're quite masochistic (I was, I guess; I did two projects before I did this!).

I've only gone into the briefest of details; there are quite a lot of commands you've got to do in a specified order.

I'd not recommend you do this the hard way until you've tried the easy way (using one of the component sets that exist, for example). If you must then you'll want to know about creating non-VCL programs. This is a strange and frightening world. Check out this part of my GDI tutorial, which talks about the process a bit.

[edited by - Alimonster on August 15, 2002 4:18:33 PM]

Share this post


Link to post
Share on other sites
thanks... but could you, by any chance, have a link to t tutorial that explains what each part of what you just said in deapth???????

Share this post


Link to post
Share on other sites
Funny you should ask...
I''ve not read it but I remember bumping into it a while ago. It may or may not use DelphiX, I can''t remember. (That site''s filled to the brim with useful articles btw).

I''m going to write a tutorial sometime in the distant future on DDraw, but that won''t happen any time soon. You might want to have a look at MSDN. It has tutorials in C++ and VB (no Delphi though), but more importantly it *explains core concepts*. It lists the functions you need to call and the interfaces to which they belong. Even if you don''t get the syntax, at least it''ll be a start.

Share this post


Link to post
Share on other sites