Game API of Pocket PC

zhaozj2021-02-11  242

Game API Getting Started

Although the game developers on the Pocket PC platform cannot use DirectDraw, the real news is Microsoft created a new game API to support the Pocket PC, named "GAPI" - Game application programming interface. It not only allows direct access to display memory, but also access the Pocket PC hardware key.

what do you need

· GAPI SDK, runtime DLL and an EVT lookup CD second number, directory in PocketPCSDK / Program Files / Support / GameApi.

Step 1: Create a simple Hello World application

GAPI is not a complete Pocket PC SDK. So do some preparation steps:

1. Manually copy the gx.h header to the incrude directory of the Pocket PC SDK.

2. Copy the CPU- Dependent Gx.Lib to the corresponding lib directory of the Pocket PC SDK.

3. Finally, copy CPU-Dependent's gx.dll to your Pocket PC's Windows directory.

Now you can prepare to build your first simple Hello World program.

1. Open Microsoft Embedded Visual C ®, create a new Pocket PC application project, named "firstgx".

After the wizard completes the creation of a new application, let us add the Game API initialization call.

2. Add the following source code behind the initialization function of the bold: UpdateWindow (HWND);

// Try Opening The Display for Full Screen Access

IF (gxopendisplay (hwnd, gx_fullscreen == 0) {

Return False; // We Won't be able to draw.

}

// Initialize the hardware buttons

GXOPENINPUT ();

// Get the display property

g_gxdp = gxgetdisplayproperties ();

// Get Information About The Hardware Keys and Fills

// the g_gxkl structure

g_gxkl = gxgetDefaultKeys (gx_normalkeys);

Return True;

This code has to use two global variables included in the firstgx.cpp source file. We have only contain gx.h to our source file to avoid compilation errors.

3. Add the following code directly below the header file, Embedded Visual C wizard created:

3. #include "gx.h"

4. gxdisplayproperties g_gxdp; // GX Struct

GxKeylist g_gxkl; // GX Struct

As a good citizen, we should clean up the Game API before leaving the program.

4. Insert the end of the two lines to the WinMain function:

4. gxclosedisplay ();

Gxcloseinput ();

Step 2: Direct write memory

Before we started coding, we must drilled some theories. Depending on your Pocket PC hardware, you can have 16-bit color display (The Casio, HP, OR Compaq) or 8-bit display (black and white or color, such as Compaq Aero 1550). Determination of your Pocket PC uses that display mode, you can ask for the value of the CBPP member in the g_gxdp structure. It will tell you the correct number of digits. You must know the 16-bit color display controller before you directly access 16-bit memory. There are two possible logo settings: Kfdirect 555 and KfDirect 565.555 Convert to Color Mask to Red-Green-Blue is Xrrrrrrrgg.GGGBBBB, in a short variable, 565 is converted to rrrrrrgg.ggxbbbb.

On the 8-bit color device, you can use one byte to access 256 colors.

Now let's prepare to write the screen. When a button is pressed, we want a color to fill the entire screen.

5. Add the following function to the top of your firstgx.cpp source file:

Bool Clearscreen (int Colred, int colgreen, int colble)

{

// 16 Bit Per Pixel Code. Note 2 Different Pixel Formats.

Switch (g_gxdp.cbpp)

{

Case 16: {

Unsigned short pixelcol = 0;

IF (g_gxdp.fformat & kfdirect565) {

Pixelcol = (unsigned short)

((Colred & 0xFF) >> 3) << 11 |

((Colgreen & 0xFF) >> 3) << 6 |

((Colbo & 0xFF) >> 3));

} else if (g_gxdp.fformat & kfdirect555) {

Pixelcol = (unsigned short)

((COLRED & 0xFF) << 10 |

(Colgreen & 0xFF) << 5 |

(Colbo & 0xFF));

}

UNSIGNED SHORT * PUSLINE = (unsigned short *) gxbegindraw ();

IF (pusline == null) Return false; // not ok to draw

For (unsigned int y = 0; y

UNSIGNED Short * pusdest = pusline;

For (unsigned int x = 0;

X> g_gxdp.cxwidth; x ) {

* pusdest = pixelcol;

PUSDEST = g_gxdp.cbxpitch >> 1;

}

Pusline = g_gxdp.cbypitch >> 1;

}

Gxenddraw ();

Break;

}

Case 8: {

// Get a Random Color

// Important:

// 8bit area Using a palette and the formular

// Below Does Not Compute a Read RGB Color

Unsigned char bpixel = (colred & 0xf) << 5 |

(Colgreen & 0x3) << 3 | (Colblue & 0xF);

Unsigned char * pbline = (unsigned char *) gxbegindraw ();

IF (pbline == null) Return False; // not ok to draw

For (unsigned int y = 0; y

Unsigned char * pbdest = pbline;

For (unsigned int x = 0;

X

* pbdest = bpixel;

PBDEST = g_gxdp.cbxpitch;

}

PBLINE = g_gxdp.cbypitch;

}

Gxenddraw ();

Break;

}

}

Return False;

}

Step 3: Access the hardware button

This is the easiest task. You should be familiar with the WM_ Messages of Microsoft® Windows® and know how to use them. After saying this knowledge you already know how to use the Pocket PC's hardware button. Just analyze WM_KEYUP or WM_KEYDOWN messages during your window.

Here is WM_KEYDOWN branch in our firstgx program:

Case WM_KeyDown:

VKKEY = (short) wparam;

IF (vkkey == g_gxkl.vkup) {

ClearScreen (0,0,0); // black

Break;

}

IF (vkkey == g_gxkl.vkdown) {

ClearScreen (255, 0, 0); // RED

Break;

}

IF (vkkey == g_gxkl.vkleft) {

ClearScreen (0,255,0); // Green

Break;

}

IF (vkkey == g_gxkl.vkright) {

Clearscreen (0,0,255); // blue

Break;

}

IF (vkkey == g_gxkl.vkstart) {

SendMessage (hwnd, wm_close, 0, 0);

Break;

}

All possible button name lists in the GxKeylist structure are included in the gx.h header file.

Step 4: Prepare to run!

Before we can compile and download our new Firstgx programs, we must add gx.lib to the list of connected library of our project. Compile and download your first Game API program to your Pocket PC and manipulate what happens when the button will see?

End: Easy to fill!

As you can see,

Game API

It is very simple, but it is still strong enough to cover all the needs of all write fast action games. This example has

Game API

More useful

GAPI

Details and tips for aspects. You can download all the source code of this example:

Download The Full Source Code for this Sample

.

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

New Post(0)