Develop DirectX games with Delphi

xiaoxiao2021-03-05  26

Blog http://blog.9cbs.net/pankun/ of the sword god

This is not a dream about DirectX, but explains how to develop DirectX games with Delphi. Because it is online or bookstore, the book about DirectX is basically described with C or VC. The data develops the game with Delphi is Less and less, this article is to let readers learn how to develop games using existing information to learn. This article is to understand DirectX, but do not know how to develop DirectX games in Delphi. .

Recommended Reference: << Game Programming Guide >>, << DirectX Chinese Review >>

Can Delphi can develop games? Answer is of course, there are many people on the Internet to think that development games can only use c or vc. Delphi is only suitable for desktop applications, and persuade these views to see Delphi. And the code elected by VC, or look at the "Miracle Age" game, "Miracle Age" is developed by Delphi, speed and picture is better than the Empire era. Delphi is fully objective, and can embed assembly, support MMX is today (Delphi MMX register is MM0-MM7). It is completely suitable for game development. In fact, regardless of VC, Delphi is just a tool, as long as the internal work can make a good program or a game.

Preparation: There are two options for developing DirectX games with Delphi. First, use JEDI's DirectX declaration (http://www.delphi-jedi.org). The other is to use Delphix controls. Here we are ready to use JEDI DirectX declares to develop DirectX games, the reason for the DirectX declaration package is because this is to develop games in SDK mode. If you need to go to another language, you don't have to re-learn DirectX. As for the Delphix control, I have never used, no say, no say, no say, However, even if you don't have to use the Japanese goods ;-) First go to the following address to download DirectX's declaration package (http://kuga.51.net/download/files/directx7.rar), and unzip it into your own directory. Select Tools-> Environment Options in Delphi, select the library tab in the open window, click the button behind the library path. You will pop up a Directories window, click the button on the right side of Greyed Items Denote Invalid Path. Select DirectX declaration to decompress Directory. Click the Add button, which adds the directory where the DirectX declaration is added to the Delphi's library path. You can reference the unit in the DirectX declaration directly in the USES. This declaration package comes with several examples, you can As a reference.

Debugging experience: It is best to make the screen resolution when designing the screen is the same resolution as the game, so as not to transfer the resolution of the resolution when debugging. Develop full screen games is best in Win2000 / XP, otherwise 98 When the game will enter the dead cycle or create an exception. Machine will be easier. When the full screen game enters the dead cycle in 2000 / XP, you can switch to Delphi in Delphi (but this time because the DirectX game is full screen Excise a screen, there will be no changes on the screen, so take more time to try it. If it is an abnormal, switch to Delphi, press Enter to press CTRL F2. End debug game.

Note: If you use Delphi7, please change the 145 line {$ IFDEF VER140} in DirectDraw.PAS to {$ IFDEF VER150}. It is best to use the API way to create the game main window instead of using VCL. TFORM class.

Let us look in C and DirectDraw DELPHI initialization code segment .c version of the image: BOOL InitDDraw () {LPDIRECTDRAW7 lpDD; // DirectDraw object pointer if (DirectDrawCreateEx (NULL, (void **) & lpDD, IID_IDirectDraw7, NULL)! = DD_OK) RETURN FALSE; {Create DirectDRAW Object} {Method for Error detection in DirectDRAW object} {, this is the most common method} if (LPDD-> setcooperativeelevel (HWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN) )! = Dd_ok) Return false; {Set DirectDraw control level} if (LPDD-> setDisplaymode (640, 480, 32, 0, ddsdm_standardvgamode)! = DD_OK) Return False; {Array display mode}} Delphi version: function TFORM1. InitDirectDraw: Boolean; var lpDD: IDirectDraw7; begin Result: = False; {} {assume initialization failure to establish DirectDraw objects} if DirectDrawCreateEx (nil, lpDD, IID_IDIRECTDRAW7, nil) <> DD_OK then exit; {set DirectDraw control stage The first parameter is the handle of the DirectDraw window, where the full-screen plus exclusive pattern set here} if lpdd.setcooPERATIVELEVEL (HWND, DDSCL_EXCLUSIVE OR DDSCL_FULLSCREEN) <> DD_OK THEN EXIT; {Set display mode, first, The two parameters are the size of the resize, the third parameter is used to set the color bits of the display mode, the refresh rate of the fourth parameter setting screen, 0 is the default value, the unique valid value of the fourth parameter is only DDSDM_Standardvgamode} IF LPDD.SETDISPLAYMODE (640, 480, 32, 0, DDSD M_Standardvgamode) <> dd_ok kiln ration; result: = true;

It can be seen that this two-segment code is exactly the same as the syntax and the object name, as long as you understand this, we can fully refer to VC or C information, then use Delphi to make your own game. DirectX declaration in Delphi. name, structure name and VC is not the same, general correspondence relationship is as follows: DELPHI VCDirectDraw objects IDirectDraw7 LPDIRECTDRAW7 page object IDirectDrawSurface7 LPDIRECTDRAWSURFACE7DirectDraw page description TDDSurfaceDesc2 DDSURFACEDESC2 basically just not the same prefix, for lack of space, here is not to list all of the image and structure .

转载请注明原文地址:https://www.9cbs.com/read-34845.html

New Post(0)