DirectX Programming in CB (1)

Source: Internet
Author: User
Tags object model

C + + Builder is a Visual C + + programming environment, which provides programmers with a convenient and efficient, simple development tool for C + + language, so it has been favored by the majority of C + + programmers, the DirectX Development Toolkit is a set of Microsoft Windows9x to develop High-performance graphics, The interface between sound, input and output and network games, its efficient direct hardware access, and the relative independence of programs and hardware devices make DirectX the only basic tool software that can develop game programs under Windows operating systems.

Although C + + Builder directly contains a set of DirectX3 development packages, some routines are provided, but these routines are not systematically described and are not suitable for the development of programs above DirectX5. On the other hand, almost all the books and literature on DirectX development are described in Visual C + + language, so the authors introduce some of their development experience in C + + Builder to the reader.

This article is suitable for readers with C + + Builder object-oriented programming experience, and the instance development environment is a development toolkit for Chinese Windows98, C + + Builder4, DirectX6 or above.

I. DirectX INTRODUCTION

Characteristics of 1_1.directx

1_2.directx is a standard high-performance gaming, Multimedia development Toolkit in Windows, and programs developed using DirectX can work with the operating system to become "real" desktop applications, with the driver interface provided by the hardware vendor, with the best possible device performance Through direct underlying hardware operation, realize the fastest, short delay, device-independent of the underlying interface.

1_3.directx uses the Component Object Model (COM) standard, so there can be different interfaces for versions of different objects, which makes the programs developed with DirectX A guarantee of full compatibility and support in the future.

The structure of the 1_4.DIRECTX

DirectX requires device-independent capabilities to provide device-related performance, so the structure of DirectX consists of two drivers: the hardware abstraction layer (HAL) and the Hardware impersonation layer (HEL), which creates a "compatible table" at the same time when the direct object is created. It records the features supported by the current hardware system, when DirectX needs to implement a function, query the table, get the hardware support information, if the function can get hardware support, then send to the HAL to get the support of the hardware, or to the Hel to send a request to the simulation mode to achieve functionality.

The main components of 1_5.DIRECTX

(1) DirectDraw: Direct access to graphics hardware, management of memory for display (display memory and system memory), provide high-speed graphics and page switching animation;

(2) Direct3D: Provide 3D hardware interface;

(3) DirectInput: The main support input services, while supporting the output equipment;

(4) DirectSound: Provide 3D sound effect, manage sound card memory;

(5) DirectPlay: Provides the communication and organization function of the network multiplayer game;

(6) DirectSetup: Automatically install the DirectX driver.

In this paper, according to the above composition of DirectX, the implementation method of C + + Builder is introduced by an example respectively.

Two. DirectDraw Program design

2.1 DirectDraw implementation of the foundation-display mode settings

The first problem with designing a graphics program is to set the screen to an appropriate graphical display, and then draw the graphic to the screen. If you are developing graphics applications under DOS, this will be a simple thing to do, as long as you call a DOS Interrupt service program, but using DirectDraw is more complicated. Because DirectDraw's design goal is to provide device-independent programming interfaces and efficient, versatile hardware access support, DirectDraw needs to consider more issues.

DirectDraw supports two graphical ways in a Windows environment: Full screen Exclusive and window mode. Here I first in full screen exclusive, Introduction DirectDraw set screen display way steps, function specific use format and programming method will be introduced in 2.2:

2.1.1 Select Hardware Device

The computer system does not necessarily have only one DirectDraw hardware abstraction device, for example, a computer may have two or more monitors, so which HAL does the DirectDraw object correspond to? We can use the Directdrawenumerate function to enumerate all installed devices of the system for selection and return the unique identification GUID for the device. DirectDraw the GUID of the default primary display device is null;

2.1.2 Create DirectDraw Object

Because DirectX is a technology that uses object-oriented programming, the first thing you can do with DirectDraw is to create a DirectDraw object. You can create a DirectDraw object based on the selected device using the Directdrawcreate function and the device GUID you obtained in the first step as a parameter;

2.1.3 Get DirectDraw later version of COM interface

If you do not intend to use the features provided by DirectX5 above, you can skip this step, or you must use the Queryintrface method of the newly created DirectDraw object to obtain a IDIRECTDRAW2 or higher COM interface. In 2.2 cases, we will introduce how to obtain the IDIRECTDRAW2 interface provided by DirectX5 above version.

2.1.4 Setting the collaboration level

A collaborative approach can control the interaction between the program and other applications in the system, typically by setting it to full screen exclusive or window-Normal mode. Setting the collaboration level can use the SetCooperativeLevel method of the DirectDraw object;

2.1.5 enumerates the various display modes supported by the device, selecting and setting the appropriate display resolution, color depth and refresh rate.

Using the DirectDraw Enumdisplaymodes method, you can enumerate all the graphics supported by the device for the user to choose from, and this enumeration feature can be used in some applications that have determined graphics display to check whether the system device supports the specified graphics display.

Use the DirectDraw Setdisplaymode method to set the desired graphical display.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.