Sets up our Direct3D rendering context Returns 1 if ok, 0 if something bad
| 1329 | // Sets up our Direct3D rendering context |
| 1330 | // Returns 1 if ok, 0 if something bad |
| 1331 | int d3d_Init(oeApplication *app, renderer_preferred_state *pref_state) { |
| 1332 | HRESULT ddrval; |
| 1333 | HWND hwnd; |
| 1334 | d3d_device *dd; |
| 1335 | DDSURFACEDESC2 ddsd2; |
| 1336 | DDSCAPS2 ddscaps; |
| 1337 | int retval = 1; |
| 1338 | bool retried = false; |
| 1339 | int found_format = -1, i; |
| 1340 | |
| 1341 | if (!d3d_UsingDX6()) { |
| 1342 | rend_SetErrorMessage("DirectX 6 is not properly installed."); |
| 1343 | return 0; |
| 1344 | } |
| 1345 | |
| 1346 | ParentApplication = app; |
| 1347 | |
| 1348 | if (pref_state != &D3D_preferred_state) |
| 1349 | D3D_preferred_state = *pref_state; |
| 1350 | |
| 1351 | TryAgain: |
| 1352 | |
| 1353 | // Poll for valid 3d devices |
| 1354 | dd = d3d_PollDevices(); |
| 1355 | |
| 1356 | if (!dd) { |
| 1357 | mprintf(1, "ERROR: No Direct3D devices found!!!"); |
| 1358 | rend_SetErrorMessage("No Direct3D devices found!!!"); |
| 1359 | return 0; |
| 1360 | } |
| 1361 | |
| 1362 | hwnd = (HWND)((oeWin32Application *)app)->m_hWnd; |
| 1363 | |
| 1364 | // Create our direct draw stuff |
| 1365 | ddrval = DirectDrawCreate(dd->pguid_2d, &lpDD1, NULL); |
| 1366 | |
| 1367 | if (ddrval != DD_OK) { |
| 1368 | mprintf(0, "D3D_INIT: DirectDrawCreate failed.\n"); |
| 1369 | rend_SetErrorMessage("DirectDrawCreate failed."); |
| 1370 | |
| 1371 | goto D3DError; |
| 1372 | } |
| 1373 | |
| 1374 | ddrval = lpDD1->QueryInterface(IID_IDirectDraw4, (LPVOID *)&lpDD); |
| 1375 | if (ddrval != DD_OK) { |
| 1376 | lpDD = NULL; |
| 1377 | rend_SetErrorMessage("DirectDrawCreate2 failed."); |
| 1378 | mprintf(0, "D3D_INIT: DirectDrawCreate2 failed.\n"); |
| 1379 | goto D3DError; |
| 1380 | } |
| 1381 | |
| 1382 | ddrval = lpDD->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT); |
| 1383 | |
| 1384 | if (ddrval != DD_OK) { |
| 1385 | mprintf(0, "D3D_INIT: SetCooperativeLevel EXCLUSIVE failed.\n D3D_Error=%s\n", d3d_ErrorString(ddrval)); |
| 1386 | rend_SetErrorMessage("SetCoopLevel EXCULUSIVE failed."); |
| 1387 | goto D3DError; |
| 1388 | } |
no test coverage detected