


What really happens in the background is that DirectDraw changes the pointer of backbuffer with the pointer of frontbuffer, so that next time the video card send the video data to the monitor it uses the backbuffered content and not the old frontbuffer. This process is called page flipping and is very similar to the process of creating cartoons (where we use lots of paper sheets to animated a drawing). When we finish it, we move all the information contained in the backbuffer to the frontbuffer. To solve this we draw everything we need to show to the user in the next frame in the backbuffer. the user can see the UFO move first and them the ship, but they need to move both at the same time). If we draw this to the front buffer directly we can have some kind of synchronization problems (ie. Since the objects are moving, we need to move our UFO to the position (12,10) and our ship to position (102, 10). Lets say that the user is currently seeing an UFO on the screen at position (10,10) and the user's ship is at position (100,100). This surface stores the information of what will be showed to the user in the next frame of our application. Attached to this FrontBuffer surface, we have another surface called the BackBuffer. In fact, for DirectDraw applications, the area that displays what we are seeing on the screen is considered a surface too, and it's called the FrontBuffer. For this you'll probably need a graphic buffer that will hold the space ships, the UFOs, the shots.Īll this graphics will be stored in memory in this structures that we'll call surfaces. Let's assume that we are creating a space invaders game ( like the one I wrote). Everything we need to drawn on the screen needs to be created on a surface first. Surfaces are memory regions that contains graphics that can be used in your application. All the drawing created by DirectDraw are based on structures called surfaces. Before your start to modify the code, I need to present you some concepts (surfaces and page flipping).

Now we are going to work on the initialization of the DirectDraw in our application. If you compile and run the application you will see an entirely black window that covers all your desktop.
USE PHOTOSHOP WINDOWS
Ok, our basic windows application is set. To create this global variables, simply declare them above the winmain definition, like this: We will need another global variable to hold the handle of our main window (that we are about to create). This variable will have global scope, and will hold the instance handle of our application. Notice that in many places I use the variables g_hInst. All this parameters are contained in WNDCLASS structure. In the window class we need to pass some information about the window to the RegisterClass function. The first thing that this function does is register a window class in windows environment (this is needed for the window creation process). Wc.hbrBackground = (HBRUSH )GetStockObject(BLACK_BRUSH) Wc.hCursor = LoadCursor(NULL, IDC_ARROW) Wc.hIcon = LoadIcon(g_hInst, IDI_APPLICATION)
USE PHOTOSHOP CODE
The code generated by the wizard will look like this: At the first screen we will select the option "Simple Win32 Application" to allow Visual C++ to create a WinMain function for us. We will start our basic DirectDraw program by selecting the "Windows Application" option in the Visual C++ interface. Not that the use of MFC in a DirectX application is prohibited, but MFC has a lot of code aimed to desktop apps and not graphic intensive ones, so its better to stick on plain Windows API and STL. Since we are working with a DirectX application, there is no need to use the MFC library in our program.

WinMain and Message Loop - The Starting point For all those that asked me the introductory article, here it is. Lots of people asked me to write an introductory article about DirectDraw programming and Spriting so that people can understand the basic concepts and start discovering the other things about DirectX from samples (MSDN and others available here).
