Platform SDK: DirectX |
This section pertains only to application development in Visual Basic. See DirectDraw C/C++ Tutorials.
The first procedure called from the Form_Load event is the init procedure. This procedure creates the DirectDraw object. This is accomplished by invoking the DirectX7.DirectDrawCreate method of the DirectX7 object and setting the returned object to DirectDraw which we declared as an object variable of class DirectDraw7. In the Tutorial 1 blitting sample, this is done with the statement:
Set objDD = objDX.DirectDrawCreate("")
This method takes only one string argument and passing an empty string specifies the active display driver.
Next you must specify the behavior of the application by calling the DirectDraw7.SetCooperativeLevel method of the DirectDraw object. The Tutorial 1 blitting sample is run as a regular windowed application and this is done with the statement:
Call objDD.SetCooperativeLevel (Me.hwnd, DDSCL_NORMAL)
You are now ready to start creating surfaces. Before you actually create the surface object, you need to create a surface description by setting the members of the DDSURFACEDESC2 type. One of the members of this type is ddscaps, a nested type, and by setting the lFlags member of the DDSURFACEDESC2 to DDSD_CAPS, you are stating that the ddscaps member is valid in this type. This is done with the statement:
ddsd1.lFlags = DDSD_CAPS
Next you need to specify that this type description is for a primary surface, which is done with the statement:
ddsd1.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE
After creating the surface description, you actually create the surface object by invoking the CreateSurface method from the DirectDraw object with the set surface description as an argument. This is done in the Tutorial 1 blitting sample with the statement:
Set objDDPrimSurf = objDD.CreateSurface(ddsd1)
The surface object creation steps are repeated for a second surface which has the DDSCAPS_OFFSCREENPLAIN flag set to specify that this surface is any off-screen surface that is not an overlay, texture, z-buffer, front-buffer, back-buffer, or alpha surface. It is used to identify plain surfaces. Then the CreateSurfaceFromFile method is invoked from the DirectDraw object. This method creates the surface object and loads a bitmap onto the surface. The location of the bitmap is specified through the FindMediaDir procedure. These steps are shown with the statements:
FindMediaDir "lake.bmp" ddsd2.lFlags = DDSD_CAPS ddsd2.ddsCaps.lCaps = DDSCAPS_OFFSCREENPLAIN Set objDDSurf = objDD.CreateSurfaceFromFile("lake.bmp", ddsd2)
A DirectDrawClipper object is then created by calling the DirectDraw7.CreateClipper method. Clippers, or DirectDrawClipper objects, allow you to blit to selected parts of a surface represented by a bounding rectangle. In Tutorial 1, we want to contain the blit to the Picture1 picture box control. This is done with the following statements:
Set ddClipper = objDD.CreateClipper(0) ddClipper.SetHWnd Picture1.hWnd objDDPrimSurf.SetClipper ddClipper
After initializing all the variables and objects we set the bInit variable to True and call the blt subroutine.
Next: Step 4: Blit the Surface