* Ifdef in some VideoUpdate methods (mostly empty implementations).
[matthijs/ABM2.git] / ABM2 / Engine / VideoUpdate.cpp
1 // VideoUpdate.cpp: implementation of the CVideoUpdate class.\r
2 //\r
3 //////////////////////////////////////////////////////////////////////\r
4 \r
5 #include "engine.h"\r
6 #include "../main.h"\r
7 #include "VideoUpdate.h"\r
8 \r
9 // include the Direct3D Library file\r
10 #ifdef WIN32\r
11 #pragma comment (lib, "d3d9.lib")\r
12 #pragma comment (lib, "d3dx9.lib")\r
13 \r
14 //////////////////////////////////////////////////////////////////////\r
15 // Construction/Destruction\r
16 //////////////////////////////////////////////////////////////////////\r
17 LPDIRECT3DDEVICE9 d3ddev;    // the pointer to the device class\r
18 #endif //WIN32\r
19 CMMPointer<Dator<int> > CVideoUpdate::screenWidth=0;\r
20 CMMPointer<Dator<int> > CVideoUpdate::screenHeight=0;\r
21 CMMPointer<Dator<int> > CVideoUpdate::screenBPP=0;\r
22 int CVideoUpdate::scrWidth=640;\r
23 int CVideoUpdate::scrHeight=480;\r
24 int CVideoUpdate::scrBPP=16;\r
25 \r
26 CVideoUpdate::CVideoUpdate()\r
27 {\r
28 #ifdef WIN32\r
29         d3d = Direct3DCreate9(D3D_SDK_VERSION);\r
30 \r
31         D3DPRESENT_PARAMETERS d3dpp;\r
32         D3DDISPLAYMODE d3ddm;\r
33         d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm);\r
34 \r
35         ZeroMemory(&d3dpp, sizeof(d3dpp));\r
36         d3dpp.Windowed = true;\r
37         d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;\r
38         d3dpp.hDeviceWindow = hWnd;\r
39         //d3dpp.BackBufferFormat = d3ddm.Format;\r
40         d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;\r
41         d3dpp.BackBufferWidth = scrWidth;\r
42         d3dpp.BackBufferHeight = scrHeight;\r
43 \r
44 \r
45         // create a device class using this information and the info from the d3dpp stuct\r
46         d3d->CreateDevice(D3DADAPTER_DEFAULT,\r
47                                                                                 D3DDEVTYPE_HAL,\r
48                                                                                 hWnd,\r
49                                                                                 D3DCREATE_SOFTWARE_VERTEXPROCESSING,\r
50                                                                                 &d3dpp,\r
51                                                                                 &d3ddev);\r
52 \r
53             // Turn on alpha-blending\r
54     d3ddev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);\r
55     // Set the render state up for source alpha blending.\r
56     d3ddev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);\r
57     d3ddev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);\r
58     // Get the alpha information solely from the texture.\r
59     d3ddev->SetTextureStageState(0, D3DTSS_ALPHAOP,   D3DTOP_SELECTARG1);\r
60     d3ddev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);\r
61 #endif // WIN32\r
62 }\r
63 \r
64 CVideoUpdate::~CVideoUpdate()\r
65 {\r
66 #ifdef WIN32\r
67     if (d3ddev != NULL) d3ddev->Release();\r
68     if (d3d != NULL) d3d->Release();\r
69 #endif // WIN32\r
70 }\r
71 \r
72 bool CVideoUpdate::Start()\r
73 {\r
74         assert(screenWidth && screenHeight && screenBPP);\r
75 /*\r
76         if(-1==SDL_InitSubSystem(SDL_INIT_VIDEO))\r
77         {\r
78                 CLog::Get().Write(LOG_CLIENT,IDS_GENERIC_SUB_INIT_FAIL,"Video",SDL_GetError());\r
79                 return false;\r
80         }\r
81         SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 8 );\r
82         SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );\r
83         SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );\r
84         SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );\r
85         SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );\r
86         SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );\r
87 \r
88         int flags = SDL_OPENGL | SDL_ANYFORMAT | SDL_FULLSCREEN;\r
89 \r
90         if(!SDL_SetVideoMode(scrWidth, scrHeight, scrBPP, flags))\r
91         {\r
92                 CLog::Get().Write(LOG_CLIENT, IDS_BAD_DISPLAYMODE, scrWidth, scrHeight, scrBPP, SDL_GetError());\r
93                 return false;\r
94         }\r
95 \r
96         //hide the mouse cursor\r
97         SDL_ShowCursor(SDL_DISABLE);\r
98 */\r
99 #ifdef WIN32\r
100     d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_COLORVALUE(0.0f, 0.4f, 1.0f, 1.0f), 1.0f, 0);\r
101 \r
102     d3ddev->BeginScene();    // begins the 3D scene\r
103 #endif // WIN32\r
104 \r
105                 return true;\r
106 }\r
107 \r
108 void CVideoUpdate::Update()\r
109 {\r
110 #ifdef WIN32\r
111         // end frame\r
112         d3ddev->EndScene();\r
113         d3ddev->Present(NULL, NULL, NULL, NULL);\r
114 \r
115         // start new frame\r
116         d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_COLORVALUE(0.0f, 0.4f, 1.0f, 1.0f), 1.0f, 0);\r
117         d3ddev->BeginScene();\r
118 #endif // WIN32\r
119 }\r
120 \r
121 void CVideoUpdate::Stop()\r
122 {\r
123 //      SDL_QuitSubSystem(SDL_INIT_VIDEO);\r
124 }\r