9478bef48d71d856bf79b273b3cf66ba36540000
[rocksndiamonds.git] / src / game_sp / DirectXGlobals.c
1 // ----------------------------------------------------------------------------
2 // DirectXGlobals.c
3 // ----------------------------------------------------------------------------
4
5 #include "DirectXGlobals.h"
6
7 // static char *VB_Name = "DirectXGlobals";
8
9 // --- Option Explicit
10
11 DirectX7 DirectX;
12 DirectX7 DirectXS;
13 DirectDraw7 DDraw;
14 DirectSound DSound;
15
16 // Public DInput As DirectInput
17 // Public DKeyboard As DirectInputDevice
18 DirectDrawSurface7 PrimarySurface;
19
20 void InitDirectX(long hWndForm, long hWndClip)
21 {
22   // DirectX = New DirectX7; // (handle this later, if needed)
23   // DirectXS = New DirectX7; // (handle this later, if needed)
24
25   // DirectSound:
26
27   // --- On Error Resume Next
28   DSound = DirectXS.DirectSoundCreate("");
29   if (Err.Number != 0)
30   {
31     ReportError("InitDirectX()", "Unable to start DirectSound.");
32   }
33   else
34   {
35     DSound.SetCooperativeLevel(hWndForm, DSSCL_PRIORITY);
36     LoadSoundFX();
37   }
38
39   // DirectDraw:
40   DDraw = DirectX.DirectDrawCreate("");
41   DDraw.SetCooperativeLevel(0, DDSCL_NORMAL);
42   RestorePrimarySurface();
43   if (hWndClip != 0)
44     ClipToWindow(hWndClip);
45
46   // 'DirectInput:
47   //  Set DInput = DirectX.DirectInputCreate()
48   //  Set DKeyboard = DInput.CreateDevice("GUID_SysKeyboard")
49   //  Call DKeyboard.SetCommonDataFormat(DIFORMAT_KEYBOARD)
50   //  Call DKeyboard.SetCooperativeLevel(hWndForm, DISCL_NONEXCLUSIVE Or DISCL_BACKGROUND)
51   //  Call DKeyboard.Acquire
52 }
53
54 void RestorePrimarySurface()
55 {
56   DDSURFACEDESC2 SD;
57
58   // Create PrimarySurface:
59   {
60     SD.lFlags = DDSD_CAPS;
61     SD.ddsCaps.lCaps = DDSCAPS_PRIMARYSURFACE;
62   }
63
64   // --- On Error Resume Next
65   SET_TO_NOTHING(&PrimarySurface, sizeof(PrimarySurface));
66   PrimarySurface = DDraw.CreateSurface(SD);
67 }
68
69 void ReleaseDirectDraw()
70 {
71   SET_TO_NOTHING(&PrimarySurface, sizeof(PrimarySurface));
72   SET_TO_NOTHING(&DDraw, sizeof(DDraw));
73   SET_TO_NOTHING(&DirectX, sizeof(DirectX));
74 }
75
76 void ClipToWindow(long hWnd)
77 {
78   DirectDrawClipper Clipper;
79   long shWnd;
80
81   if (hWnd != 0)
82     shWnd = hWnd;
83
84   // create clipper
85   Clipper = DDraw.CreateClipper(0);
86   Clipper.SetHWnd(shWnd);
87   PrimarySurface.SetClipper(Clipper);
88   SET_TO_NOTHING(&Clipper, sizeof(Clipper));
89 }
90
91 // Public Sub DimPrimary(Brightness&)
92 // Dim Pal As DirectDrawPalette
93 //  Set Pal = PrimarySurface.GetPalette()
94 // End Sub
95