int DDInitFullscreen(int width, int height, int bpp, HWND hwnd) { HRESULT ret; // create object and test for error if (DirectDrawCreate(NULL, &lpDD, NULL) != DD_OK) { return(0); } // set cooperation level to windowed mode normal if (lpDD->SetCooperativeLevel(hwnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE) != DD_OK) { return(0); } // set the display mode if (lpDD->SetDisplayMode(width, height, bpp) != DD_OK) { return(0); } // set globals screen_height = height; screen_width = width; screen_bpp = bpp; // Create the primary surface memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; // we need to let dd know that we want a complex // flippable surface structure, set flags for that ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; // set the backbuffer count to 1 ddsd.dwBackBufferCount = 1; // create the primary surface ret = lpDD->CreateSurface(&ddsd, &lpDDSPrimary, NULL); // query for the backbuffer i.e the secondary surface ddscaps.dwCaps = DDSCAPS_BACKBUFFER; lpDDSPrimary->GetAttachedSurface(&ddscaps, &lpDDSBack); // clear out both primary and secondary surfaces DDFillSurface(lpDDSPrimary, 0); DDFillSurface(lpDDSBack, 0); DDGetRGB16(); return 1; }
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: InitGraphics() // Desc: //----------------------------------------------------------------------------- HRESULT InitGraphics() { DDCAPS ddcaps; HRESULT hr; DDSURFACEDESC ddsd; DDSCAPS ddscaps; // Create a window g_hwndMain = CreateWindowEx( WS_EX_APPWINDOW, TEXT("DuelClass"), TEXT("Duel"), WS_POPUP | WS_SYSMENU, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, g_hInst, NULL ); if( NULL == g_hwndMain ) return E_FAIL; UpdateWindow( g_hwndMain ); SetFocus( g_hwndMain ); // DDraw stuff begins here if( FAILED( hr = DirectDrawCreate( NULL, &g_pDD, NULL ) ) ) { ShowError(IDS_DDRAW_ERROR_DDC); return E_FAIL; } // Set access mode based on fullscreen/window if( g_bFullscreen ) { hr = g_pDD->SetCooperativeLevel( g_hwndMain, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN ); } else { hr = g_pDD->SetCooperativeLevel( g_hwndMain, DDSCL_NORMAL); } if( FAILED(hr) ) { ShowError(IDS_DDRAW_ERROR_SCL); return E_FAIL; } if( g_bFullscreen ) { // Set the mode to 640 by 480 by 8 if( FAILED( g_pDD->SetDisplayMode( 640, 480, 8 ) ) ) { ShowError(IDS_DDRAW_ERROR_SDM); return E_FAIL; } } else { RECT rcWork; RECT rc; DWORD dwStyle; // If we are still a WS_POPUP window we should convert to a // normal app window so we look like a windows app. dwStyle = GetWindowStyle(g_hwndMain); dwStyle &= ~WS_POPUP; dwStyle |= WS_OVERLAPPED | WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX; SetWindowLong( g_hwndMain, GWL_STYLE, dwStyle ); // Aet window size SetRect( &rc, 0, 0, MAX_DEFWIN_X, MAX_DEFWIN_Y ); AdjustWindowRectEx( &rc, GetWindowStyle(g_hwndMain), GetMenu(g_hwndMain) != NULL, GetWindowExStyle(g_hwndMain) ); SetWindowPos( g_hwndMain, NULL, 0, 0, rc.right-rc.left, rc.bottom-rc.top, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); SetWindowPos( g_hwndMain, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); // Make sure our window does not hang outside of the work area SystemParametersInfo( SPI_GETWORKAREA, 0, &rcWork, 0 ); GetWindowRect( g_hwndMain, &rc ); if( rc.left < rcWork.left ) rc.left = rcWork.left; if( rc.top < rcWork.top ) rc.top = rcWork.top; SetWindowPos( g_hwndMain, NULL, rc.left, rc.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE ); } // Check the color key hardware capabilities ddcaps.dwSize = sizeof( ddcaps ); memset( &ddsd, 0, sizeof( ddsd ) ); ddsd.dwSize = sizeof( ddsd ); if( g_bFullscreen ) { // Create surfaces ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 1; if( FAILED( hr = g_pDD->CreateSurface( &ddsd, &g_pddsFrontBuffer, NULL ) ) ) { ShowError(IDS_DDRAW_ERROR_CREATESURFACE); return E_FAIL; } // Get a pointer to the back buffer ddscaps.dwCaps = DDSCAPS_BACKBUFFER; if( FAILED( hr = g_pddsFrontBuffer->GetAttachedSurface( &ddscaps, &g_pddsBackBuffer ) ) ) { ShowError(IDS_DDRAW_ERROR_GAS); return E_FAIL; } } else { LPDIRECTDRAWCLIPPER pcClipper; // Window case, create the primary surface // and create a backbuffer in offscreen memory ddsd.dwFlags = DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; if( FAILED( g_pDD->CreateSurface( &ddsd, &g_pddsFrontBuffer, NULL ) ) ) { ShowError(IDS_DDRAW_ERROR_CREATESURFACE); return E_FAIL; } ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth = MAX_DEFWIN_X; ddsd.dwHeight = MAX_DEFWIN_Y; if( FAILED( hr = g_pDD->CreateSurface( &ddsd, &g_pddsBackBuffer, NULL ) ) ) { ShowError(IDS_DDRAW_ERROR_CREATESURFACE); return E_FAIL; } if( FAILED( hr = g_pDD->CreateClipper( 0, &pcClipper, NULL) ) ) { ShowError(IDS_DDRAW_ERROR_CC); return E_FAIL; } if( FAILED( hr = pcClipper->SetHWnd( 0, g_hwndMain) ) ) { pcClipper->Release(); ShowError(IDS_DDRAW_ERROR_SH); return E_FAIL; } if( FAILED( hr = g_pddsFrontBuffer->SetClipper( pcClipper) ) ) { pcClipper->Release(); ShowError(IDS_DDRAW_ERROR_SC); return E_FAIL; } // Done with clipper pcClipper->Release(); } ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth = 320; ddsd.dwHeight = 128; for( DWORD i=0; i<4; i++ ) { if( FAILED( hr = g_pDD->CreateSurface( &ddsd, &g_pddsShip[i], NULL ) ) ) { ShowError(IDS_DDRAW_ERROR_CREATESURFACE); return E_FAIL; } } ddsd.dwHeight = 16; if( FAILED( hr = g_pDD->CreateSurface( &ddsd, &g_pddsNumbers, NULL ) ) ) { ShowError(IDS_DDRAW_ERROR_CREATESURFACE); return E_FAIL; } if( FAILED( RestoreSurfaces() ) ) { ShowError(IDS_DDRAW_ERROR_RS); return E_FAIL; } g_dwKeys = 0; ShowWindow( g_hwndMain, SW_SHOW); return S_OK; }
//must be the game window int dd_Window::set_fullscreen(int w, int h, int bpp) { _ASSERTE(bGameWindow); quad ws; HRESULT hr; DX_RELEASE(dx_os); DX_RELEASE(dx_ps); DX_RELEASE(dx_win_ps); hr = dx_dd->SetCooperativeLevel(hMainWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); if (hr != DD_OK) { return 0; } //hack for 320x200 letterboxing if(w == 320 && h == 200) dx_dd->SetDisplayMode(320, 240, bpp); else dx_dd->SetDisplayMode(w, h, bpp); hr = dx_dd->CreateSurface(&dx_psd, &dx_ps, NULL); if (hr != DD_OK) { return 0; } dx_osd.dwWidth=w; dx_osd.dwHeight=h; hr=dx_dd->CreateSurface(&dx_osd,&dx_os,NULL); if(hr!=DD_OK) { return 0; } hr = dx_ps->GetAttachedSurface(&dx_bsd.ddsCaps, &dx_bs); if (hr != DD_OK) { DX_RELEASE(dx_os); return 0; } ws = GetWindowLong(hwnd, GWL_STYLE); ws &= ~WS_OVERLAPPEDWINDOW; ws |= WS_POPUP; SetWindowLong(hwnd, GWL_STYLE, ws); SetWindowPos(hwnd,0,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE|SWP_FRAMECHANGED | SWP_NOZORDER); //make window take up entire screen //choose one or the other //SetWindowPos(hwnd,0,0,0,w,h,SWP_NOACTIVATE | SWP_NOZORDER); ShowWindow(hwnd,SW_SHOWMAXIMIZED); //set pixelformat parameters { DDPIXELFORMAT ddpf; ddpf.dwSize = sizeof(ddpf); ddpf.dwFlags = DDPF_RGB; hr = dx_ps->GetPixelFormat(&ddpf); if (hr != DD_OK) err("Could not get pixel format!"); //if (ddpf.dwRBitMask == 0x7C00 && bpp == 16) // vid_bpp = 15, vid_bytesperpixel = 2; //else // vid_bpp = bpp, vid_bytesperpixel = bpp / 8; vid_bpp = 32; } if(img) delete img; img = new image(); img->shell = true; SetHandleImage(1,img); screen = img; // img->alphamap = 0; img->width = w; img->height = h; img->cx1 = 0; img->cx2 = w-1; img->cy1 = 0; img->cy2 = h-1; img->data=0; flip_fullscreen(); return 1; }
/******************************************************************** * 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(); } } } }