DirectX SDK |
This section pertains only to application development in Visual Basic. See Direct3D Immediate Mode C/C++ Tutorials.
After creating the application window, the first object that you will create is the DirectDraw object, which is required to set your application's cooperative level. The same DirectDraw object will be used to create both the surface for displaying your scene and the render target for your application's rendering device.
The Triangle tutorial application begins initialization by creating a DirectDraw object, as shown in the following code:
Private Sub InitDDraw() ' Create the DirectDraw object and set the application ' cooperative level. Set g_dd = g_dx.DirectDrawCreate("")
The preceding code creates a DirectDraw object by calling the DirectDrawCreate global function. It passes an empty string to request that the function create a DirectDraw object for the active display driver. For hardware that doesn't support GDI, such as 3-D only hardware, you should explicitly specify the globally unique identifier (GUID) of the desired driver.
The Triangle tutorial application sets the cooperative level by calling the DirectDraw7.SetCooperativeLevel method. Setting the cooperative level tells the system whether or not the application will render in full-screen mode or in a normal window. (Note that some hardware cannot render into a window. You can detect such hardware by checking for the absence of the DDCAP2_CANRENDERWINDOWED capability flag when you call DirectDraw7.GetCaps.) The preceding code requests windowed cooperative level, also called the "normal" cooperative level, by including the DDSCL_NORMAL flag in the second parameter passed to SetCooperativeLevel. The SetCooperativeLevel method can fail if another application already owns full-screen, exclusive mode.
The following code shows how to set the application's cooperative level:
g_dd.SetCooperativeLevel Me.hWnd, DDSCL_NORMAL
Once you create the DirectDraw object and set the cooperative level, you are ready to prepare the surfaces that will be used to contain and display a rendered scene. The Triangle tutorial does this in Step 2.2: Set Up DirectDraw Surfaces.