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