How to : Using directdraw with delphi

preview_player
Показать описание
Using directdraw with delphi

This shows how to start using the DirectX library in Delphi programs and then demonstrates a simple application using the freeware library DelphiX.

If you have ever tried doing fast screen output under Windows, you'll know it's no easy task. With all the tricks possible it still falls lamentably far short of commercial game speeds. But I'll show you how to use DirectX in your apps to do smooth fast output that can be timed in microseconds not minutes!

A few years ago, Microsoft's developers realised that Windows was not a games platform and they vowed to change this. In 1995 the short lived WinG appeared. This allowed fast output in 256 color modes on Win 3.1 and Win 95. It was fast, but limited and soon replaced by DirectX. This is a family of APIs for fast output and input. Your apps can use video cards, sound cards and even force-feedback joysticks through DirectX. I'll look at DirectDraw the visual API and come back to the others in future. Other DirectX APIs include DirectSound for soundcards, DirectInput for joysticks etc, Direct3d for 3d graphics and DirectPlay for multi-player. Although DirectX is now at version 6.1, DirectDraw has been virtually unchanged since version 3. Version 3 BTW is the one built into Win NT 4.0.

Windows's strength is that it works with many different monitors, video cards and in multiple resolutions and colour depths. This requires a lot of code between your App and the video card hardware and this 'Thick Api' is why Windows output routines are slow. This was also true with Dos when it first appeared, and games developers went straight to the metal instead of using the BIOS or DOS API routines. Until two years ago, most games were still written for Dos, even those running under Windows 95. Now, probably 99% use DirectX and soon it seems Windows CE micros will be driving commercial arcade machines using DirectX.

DirectX/DirectDraw supports a thin API approach with few layers between the hardware and your App. DirectX is built on COM, the Component Object Model so that new versions can be released without breaking your existing code. If your App works with DirectX version 5, it is guaranteed to work with DirectX 6, 7 ...308!

DirectDraw provides information to your App about what hardware features the video or sound card has, and what is emulated in software. This DirectX approach guarantees that your software will run on cards not yet designed and will be able to use their advanced features. On the downside it means that you have to write two or three different ways of doing things and choose the best (= fastest) method at runtime.

DirectX and Delphi


I'll now show you the essentials of DirectDraw programming and how to get the best out of the DelphiX components with an example App. If you use DelphiX, you'll find that Mr. Hori's help files are perhaps not crystal clear but you get complete source code and a number of good sample programs to overcome this. DelphiX is a superb piece of software and you could write near arcade quality games in Delphi using it.



Even if you are not into games programming, the extra speed that DirectDraw offers lets you create applications with flicker free high speed output like radar displays, oscilloscopes, scrolling maps etc. I've used it for a scrolling map and it draws a screen full of 256 colour hexagons at 1024 x 768 resolution (each hex fits in a rectangle 32 pixels wide by 34 deep) in 26 ms on a P2 300 equipped with an AGP Matrox Millenium card. That's almost 40 frames per second, not at all bad for Delphi..

In DirectDraw, Microsoft haven't chucked out the GDI either. One of the big pains of Dos game development was outputting text, particularly having to create your own fonts or message bitmaps. Thankfully, the GDI works with DirectDraw so that Truetype fonts can be used. In fact most of the GDI works, so long as a bit of care is taken. Of course GDI output is not very fast, so you should really only use it for creating text, menus etc.

Getting Started

Рекомендации по теме
visit shbcf.ru