//----------------------------------------------------------------------------- // Name: BltSplashScreen() // Desc: //----------------------------------------------------------------------------- HRESULT BltSplashScreen( RECT* prc ) { HRESULT hr; HBITMAP hbm; if( ( g_pddsFrontBuffer == NULL ) || ( g_pSplashPalette == NULL ) || ( g_pddsBackBuffer == NULL ) ) return E_FAIL; // Set the palette before loading the splash screen g_pddsFrontBuffer->SetPalette( g_pSplashPalette ); hbm = (HBITMAP)LoadImage( GetModuleHandle( NULL ), TEXT("SPLASH"), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION ); if( NULL == hbm ) return E_FAIL; // If the surface is lost, DDUtil_CopyBitmap will fail and the surface will // be restored below. hr = DDUtil_CopyBitmap( g_pddsBackBuffer, hbm, 0, 0, 0, 0 ); DeleteObject( hbm ); while( 1 ) { hr = g_pddsFrontBuffer->Blt( &g_rcWindow, g_pddsBackBuffer, prc, DDBLT_WAIT, NULL); if( SUCCEEDED(hr) ) return S_OK; if( hr == DDERR_SURFACELOST ) if( FAILED( RestoreSurfaces() ) ) return E_FAIL; if( hr != DDERR_WASSTILLDRAWING ) return E_FAIL; } }
static vmResult win32ddraw_enable(void) { DDSCAPS ddsCaps; DDSURFACEDESC ddsd; int ret; int idx; // log("enable\n"); /* Enable fullscreen mode so we can properly create the surfaces. */ win_SetFullScreenMode(); /* Create primary surface */ memset((void *)&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP; ddsd.dwBackBufferCount = 1; ret = lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL); if (ret != DD_OK) { module_logger(&win32DirectDrawVideo, _L|LOG_ERROR, _("CreateSurface (%d)\n"), ret); DDFAIL(_("CreateSurface (screen)"), ret); } /* Create back buffer, for page flipping */ ddsCaps.dwCaps = DDSCAPS_BACKBUFFER; ret = lpDDSPrimary->GetAttachedSurface(&ddsCaps, &lpDDSBack); if (ret != DD_OK) DDFAIL(_("GetAttachedSurface (screen)"), ret); #if 0 /* Create offscreen surface */ ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth = fsx; ddsd.dwHeight = fsy; ret = lpDD->CreateSurface(&ddsd, &lpDDSBitmap, NULL); if (ret != DD_OK) DDFAIL(_("CreateSurface (offscreen)"), ret); #endif /* Set up the palette. */ for (idx = 0; idx < 256; idx++) { DD_RGBTOPAL(idx, idx == 0 ? 1 : idx == 16 ? 15 : idx > 16 ? 8 : idx); } /* for (idx = DD_PALBASE+17; idx < 246; idx++) { pals[idx].peFlags = PC_NOCOLLAPSE; pals[idx].peRed = pals[idx].peGreen = pals[idx].peBlue = idx; } */ /* for (idx = 0; idx < 256; idx++) { pals[idx].peFlags = PC_NOCOLLAPSE; pals[idx].peRed = pals[idx].peGreen = pals[idx].peBlue = rand(); } */ /* Create the palette */ ret = lpDD->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256, pals, &lpDDPal, (IUnknown FAR *)NULL); if (ret != DD_OK) DDFAIL(_("CreatePalette failed"), ret); /* attach the palette [this may be redundant if we do it twice] */ if (lpDDPal) { ret = lpDDSPrimary->SetPalette(lpDDPal); if (ret != DD_OK) DDFAIL(_("deo failed (%d)\n"), ret); // /* turn it on [it should already be so, but make sure] */ // ret = lpDDPal->SetEntries(0 /*flags */, 0, 256, pals); // if (ret != DD_OK) // DDFAIL(_("SetEntries failed (%d)\n"), ret); } /* Reset screen if we might not be primary */ win_ResetFullScreenMode(); // win_video_event_tag = TM_UniqueTag(); // TM_SetEvent(win_video_event_tag, TM_HZ*100/30, 0, // TM_REPEAT|TM_FUNC, win_video_update); return vmOk; }
//----------------------------------------------------------------------------- // Name: SetGamePalette() // Desc: //----------------------------------------------------------------------------- VOID SetGamePalette() { if( g_pddsFrontBuffer ) g_pddsFrontBuffer->SetPalette( g_pArtPalette ); }
//----------------------------------------------------------------------------- // Name: RestoreSurfaces() // Desc: //----------------------------------------------------------------------------- HRESULT RestoreSurfaces() { HRESULT hr; HBITMAP hbm; if( FAILED( hr = g_pddsFrontBuffer->Restore() ) ) return hr; if( FAILED( hr = g_pddsBackBuffer->Restore() ) ) return hr; for( DWORD i=0; i<4; i++ ) if( FAILED( hr = g_pddsShip[i]->Restore() ) ) return hr; // Create and set the palette for the splash bitmap g_pSplashPalette = DDUtil_LoadPalette( g_pDD, TEXT("SPLASH") ); if( NULL == g_pSplashPalette ) return E_FAIL; // Create and set the palette for the art bitmap g_pArtPalette = DDUtil_LoadPalette( g_pDD, TEXT("Duel8") ); if( NULL == g_pArtPalette ) return E_FAIL; // set the palette before loading the art g_pddsFrontBuffer->SetPalette( g_pArtPalette ); hbm = (HBITMAP)LoadImage( GetModuleHandle(NULL), TEXT("Duel8"), IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION ); if( NULL == hbm ) return E_FAIL; if( FAILED( hr = DDUtil_CopyBitmap( g_pddsShip[0], hbm, 0, 0, 320, 128 ) ) ) { DeleteObject( hbm ); return E_FAIL; } if( FAILED( hr = DDUtil_CopyBitmap( g_pddsShip[1], hbm, 0, 128, 320, 128 ) ) ) { DeleteObject( hbm ); return E_FAIL; } if( FAILED( hr = DDUtil_CopyBitmap( g_pddsShip[2], hbm, 0, 256, 320, 128 ) ) ) { DeleteObject( hbm ); return E_FAIL; } if( FAILED( hr = DDUtil_CopyBitmap( g_pddsShip[3], hbm, 0, 384, 320, 128 ) ) ) { DeleteObject( hbm ); return E_FAIL; } if( FAILED( hr = DDUtil_CopyBitmap( g_pddsNumbers, hbm, 0, 512, 320, 16 ) ) ) { DeleteObject( hbm ); return E_FAIL; } DeleteObject( hbm ); // set colorfill colors and colorkeys according to bitmap contents g_dwFillColor = DDUtil_ColorMatch( g_pddsShip[0], CLR_INVALID ); DDUtil_SetColorKey( g_pddsShip[0], CLR_INVALID ); DDUtil_SetColorKey( g_pddsShip[1], CLR_INVALID ); DDUtil_SetColorKey( g_pddsShip[2], CLR_INVALID ); DDUtil_SetColorKey( g_pddsShip[3], CLR_INVALID ); DDUtil_SetColorKey( g_pddsNumbers, CLR_INVALID ); return S_OK; }
/******************************************************************** * Function : WinMain() * Purpose : Mandatory Windows Init function. ********************************************************************/ int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; HWND hwnd; WNDCLASS wc; static char ClassName[] = "ChromeTestingFacility"; DDSURFACEDESC ddsd; DDSCAPS ddscaps; HRESULT ddreturn; int n; // Set all key booleans to FALSE, assume no key is pressed. bForwardKey = FALSE; bBackKey = FALSE; bLeftKey = FALSE; bRightKey = FALSE; nState = 0; nGauge = 0; lpCmdLine = lpCmdLine; hPrevInstance = hPrevInstance; RealTime = 0; /* Start of using spacebar for frameflipping. */ /* Register and realize our display window */ wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = WindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = NULL; wc.lpszMenuName = ClassName; wc.lpszClassName = ClassName; RegisterClass(&wc); /* Initialize our test world. */ if (!InitWorld(XRES, YRES, Colormap)) { return FALSE; } /* Convert the Chrome colormap to a windows colormap. */ for (n = 0; n < 256; n++) { WinColormap[n].peRed = (unsigned char)((Colormap[n] & 0xFF0000) >> 16); WinColormap[n].peGreen = (unsigned char)((Colormap[n] & 0xFF00) >> 8); WinColormap[n].peBlue = (unsigned char)((Colormap[n] & 0xFF)); WinColormap[n].peFlags = 0; } /* Create a full screen window so that GDI won't ever be * called. */ hwnd = CreateWindowEx(WS_EX_TOPMOST, ClassName, ClassName, WS_POPUP, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hInstance, NULL); if (hwnd == NULL) return FALSE; ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); SetFocus(hwnd); ShowCursor(FALSE); /* Remove cursor to prevent GDI from writing. */ /* Instanciate our DirectDraw object */ ddreturn = DirectDrawCreate(NULL, &lpDirectDrawObject, NULL); if (ddreturn != DD_OK) { DestroyWindow(hwnd); return FALSE; } ddreturn = lpDirectDrawObject->SetCooperativeLevel(hwnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN| DDSCL_ALLOWMODEX); if (ddreturn != DD_OK) { DestroyWindow(hwnd); return FALSE; } /* Create a palette for the surfaces. */ ddreturn = lpDirectDrawObject->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 | DDPCAPS_INITIALIZE, (LPPALETTEENTRY)WinColormap, &lpPalette, NULL); if (ddreturn != DD_OK) { DestroyWindow(hwnd); return FALSE; } /* Set the video mode to XRESxYRESx8. */ ddreturn = lpDirectDrawObject->SetDisplayMode(XRES, YRES, 8); if (ddreturn != DD_OK) { DestroyWindow(hwnd); return FALSE; } /* Create a default font for the application. */ AppFont = CreateFont(11, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, NONANTIALIASED_QUALITY, VARIABLE_PITCH, "Comic Sans MS"); /* Create the primary surface and one back buffer surface */ ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; ddreturn = lpDirectDrawObject->CreateSurface(&ddsd, &lpPrimary, NULL); if (ddreturn != DD_OK) { DestroyWindow(hwnd); return FALSE; } ddreturn = lpPrimary->SetPalette(lpPalette); if (ddreturn != DD_OK) { DestroyWindow(hwnd); return FALSE; } /* Get a surface pointer to our back buffer. */ ddscaps.dwCaps = DDSCAPS_BACKBUFFER; ddreturn = lpPrimary->GetAttachedSurface(&ddscaps, &lpBackbuffer); if (ddreturn != DD_OK) { DestroyWindow(hwnd); return FALSE; } /* ddreturn = lpBackbuffer->SetPalette(lpPalette); if (ddreturn != DD_OK) { DestroyWindow(hwnd); return FALSE; } */ { /* Clear the background once for both buffers so we don't get anoying flicker effect. */ DDBLTFX BltFx; BltFx.dwSize = sizeof(BltFx); BltFx.dwFillColor = 255; ddreturn = lpBackbuffer->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &BltFx); BltFx.dwSize = sizeof(BltFx); BltFx.dwFillColor = 255; ddreturn = lpPrimary->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &BltFx); } while (1) { if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { if (!GetMessage(&msg, NULL, 0, 0)) return msg.wParam; TranslateMessage(&msg); DispatchMessage(&msg); } else { if (ActiveApp && RealTime) { // Simulation Iteration should go here. // Only do this when running Realtime. SimLoop(); } else { WaitMessage(); } } } }