void dd_Window::flip_fullscreen() { int i=0; HRESULT hr; //hack for 320x200 letterboxing if(xres == 320 && yres == 200) { hr = dx_bs->BltFast(0,20,dx_os,NULL,DDBLTFAST_WAIT | DDBLTFAST_NOCOLORKEY); DDBLTFX ddbltfx; memset(&ddbltfx, 0, sizeof(DDBLTFX)); ddbltfx.dwSize = sizeof(DDBLTFX); ddbltfx.dwFillColor = 0; RECT rBlit; rBlit.left = 0; rBlit.top = 0; rBlit.right = 320; rBlit.bottom = 20; dx_bs->Blt(&rBlit, 0, 0, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); rBlit.left = 0; rBlit.top = 220; rBlit.right = 320; rBlit.bottom = 240; dx_bs->Blt(&rBlit, 0, 0, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); } //regular case else hr = dx_bs->BltFast(0,0,dx_os,NULL,DDBLTFAST_WAIT | DDBLTFAST_NOCOLORKEY); if(hr==DDERR_SURFACELOST) { dx_bs->Restore(); dx_os->Restore(); dx_bs->BltFast(0,0,dx_os,NULL,DDBLTFAST_WAIT | DDBLTFAST_NOCOLORKEY); } hr=dx_ps->Flip(0,DDFLIP_WAIT | DDFLIP_NOVSYNC); //dx_ps->Flip(0,0); if(hr==DDERR_SURFACELOST) { dx_ps->Restore(); hr=dx_ps->Flip(0,DDFLIP_WAIT | DDFLIP_NOVSYNC); } hr=dx_os->Lock(0,&dx_osd,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WRITEONLY | DDLOCK_WAIT,0); if(hr==DDERR_SURFACELOST) { dx_os->Restore(); hr=dx_os->Lock(0,&dx_osd,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WRITEONLY | DDLOCK_WAIT,0); } dx_os->Unlock(0); img->data=(quad*)dx_osd.lpSurface; img->pitch=dx_osd.lPitch/vid_bytesperpixel; }
void CALLBACK _GameProc(HWND hWnd, UINT message, UINT wParam, DWORD lParam) { static int Frame = 0, Count = 0; RECT BackRect = { 0, 0, 640, 480 }, SpriteRect; BackScreen -> BltFast( 0, 0, BackGround, &BackRect, DDBLTFAST_WAIT | DDBLTFAST_NOCOLORKEY ); SpriteRect.left = Frame * 100; SpriteRect.top = 0; SpriteRect.right = SpriteRect.left + 100; SpriteRect.bottom = 70; BackScreen -> BltFast( MouseX - 50, MouseY - 35, SpriteImage, &SpriteRect, DDBLTFAST_WAIT | DDBLTFAST_SRCCOLORKEY ); // enter animation code here! if(gFullScreen) RealScreen->Flip(NULL, DDFLIP_WAIT); else{ RECT WinRect, SrcRect={0, 0, gWidth, gHeight}; GetWindowRect(MainHwnd, &WinRect); RealScreen->Blt(&WinRect, BackScreen, &SrcRect, DDBLT_WAIT, NULL ); } }
bool flip(long bltWidth,long bltHeight){ if (m_ddsback==0) return true; if (m_IS_USER_BACK_BUFFER){ if ((bltWidth>0)&&(bltHeight>0)){ RECT rt; rt.left=0; rt.top=0; rt.right=bltWidth; rt.bottom=bltHeight; #ifdef WINCE HRESULT ddrval=m_ddsprimary->Blt(&rt,m_ddsback, &rt,DDBLT_WAITNOTBUSY, NULL); #else HRESULT ddrval=m_ddsprimary->BltFast(0,0, m_ddsback, &rt, NULL); #endif return (ddrval == DD_OK); }else return true; }else{ //flip while( true ) { HRESULT ddrval= m_ddsprimary->Flip( NULL, DDFLIP_WAIT );// 交换表面 if( ddrval == DD_OK ) return true; if( ddrval == DDERR_SURFACELOST ) { ddrval = m_ddsprimary->Restore(); if( ddrval!= DD_OK ) return false; } if( ddrval != DDERR_WASSTILLDRAWING ){ return false; } ::Sleep(0); } } }
HRESULT DDFlip(void) { #ifndef DOD_WINDOWED HRESULT ddrval; ddrval = lpDDSPrimary->Flip(NULL, DDFLIP_WAIT); // flip the surfaces return ddrval; #else RECT rect = { 0, 0, 640, 480 }; lpDDSPrimary->Blt(&rcWindow, lpDDSBack, &rect, DDBLT_WAIT, NULL); return 1; #endif }
//----------------------------------------------------------------------------- // Name: FlipScreen() // Desc: //----------------------------------------------------------------------------- VOID FlipScreen() { // Flip the surfaces if( g_bFullscreen ) { while( 1 ) { HRESULT hr = g_pddsFrontBuffer->Flip( NULL, 0 ); if( hr == DDERR_SURFACELOST ) { if( FAILED( RestoreSurfaces() ) ) return; } if( hr != DDERR_WASSTILLDRAWING ) return; } } else { g_pddsFrontBuffer->Blt( &g_rcWindow, g_pddsBackBuffer, NULL, DDBLT_WAIT, NULL ); } }
BOOL PageFlip(){ //return TRUE if page flip succeeds if(lpPrimary->Flip(NULL,DDFLIP_WAIT)==DDERR_SURFACELOST) return RestoreSurfaces(); return TRUE; } //PageFlip
void UpdateFrame2(HWND hWnd, void* videoMem) { static BYTE phase = 0; HRESULT hRet; LPDIRECTDRAWSURFACE pdds; DDBLTFX ddbltfx; static int cnt = 0; memset(&ddbltfx, 0, sizeof(ddbltfx)); ddbltfx.dwSize = sizeof(ddbltfx); ddbltfx.dwROP = SRCCOPY; if (phase) { pdds = g_pDDSTwo; phase = 0; } else { pdds = g_pDDSOne; phase = 1; } #if 1 DDSURFACEDESC ddsd; ddsd.dwSize = sizeof(ddsd); while (true) { WaitForSingleObject(g_hRefreshScreen, INFINITE); hRet = g_pDDSPrimary->Lock(NULL, &ddsd, DDLOCK_WAITNOTBUSY | DDLOCK_DISCARD | DDLOCK_WRITEONLY, NULL); if (hRet == DD_OK) { //memcpy((char*)ddsd.lpSurface, g_videoMem, (ddsd.dwHeight - 26) * ddsd.lPitch); memcpy((char*)ddsd.lpSurface + ddsd.lPitch * 26, g_videoMem, (ddsd.dwHeight - 26) * ddsd.lPitch); //memcpy((char*)ddsd.lpSurface, videoMem, ddsd.dwHeight * ddsd.lPitch); hRet = g_pDDSPrimary->Unlock(NULL); } } //hRet = g_pDDSPrimary->Blt(NULL, g_pDDSBack, NULL, DDBLT_ROP, &ddbltfx);//dwTransType, NULL); #else while (TRUE) { hRet = g_pDDSBack->Blt(NULL, pdds, NULL, DDBLT_ROP, &ddbltfx); if (hRet == DD_OK) break; if (hRet == DDERR_SURFACELOST) { hRet = RestoreAll(); if (hRet != DD_OK) break; } if (hRet != DDERR_WASSTILLDRAWING) break; Sleep(10); } while (TRUE) { hRet = g_pDDSPrimary->Flip(NULL, 0); if (hRet == DD_OK) break; if (hRet == DDERR_SURFACELOST) { hRet = RestoreAll(); if (hRet != DD_OK) break; } if (hRet != DDERR_WASSTILLDRAWING) break; Sleep(10); } #endif }
/******************************************************************** * Function : SimLoop() * Purpose : Performs a single Simulation Loop iteration. Includes * drawing. ********************************************************************/ int SimLoop(void) { static int nFramesPerSecond = 0; static int nFramesSinceLastTick; static DWORD LastTicks = 0; DWORD Ticks; HDC hDC; HFONT hOldFont; char s[80]; int slen; DDSURFACEDESC ddsd; DDBLTFX BltFx; HRESULT ddreturn; /* Perform a single step in our world. */ if (StepWorld(bForwardKey, bBackKey, bLeftKey, bRightKey, nState, nGauge)) { if (lpPrimary->IsLost() == DDERR_SURFACELOST) lpPrimary->Restore(); /* Clear the backbuffer. */ #if CLEARBCKGRND BltFx.dwSize = sizeof(BltFx); BltFx.dwFillColor = 255; ddreturn = lpBackbuffer->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &BltFx); #else ddreturn = DD_OK; #endif if (ddreturn == DD_OK) { /* While this is running, prepare * the drawing. */ if (PrepDrawWorld()) { /* Lock the surface. */ memset(&ddsd, 0, sizeof(DDSURFACEDESC)); ddsd.dwSize = sizeof(ddsd); ddreturn = lpBackbuffer->Lock(NULL, &ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL); if (ddreturn == DD_OK) { DrawWorld((unsigned char *)ddsd.lpSurface, (int)ddsd.lPitch); int nX, nY; static unsigned char dummy; unsigned char ni; ni = 0; for (nY = 0; nY < 16; nY++) for (nX = 0; nX < 16; nX++) { /* Draw a small block at (nX * 3, nY * 3) */ ((unsigned char *)ddsd.lpSurface)[(nY * 3 * ddsd.lPitch) + (nX * 3)] = ni; ((unsigned char *)ddsd.lpSurface)[(nY * 3 * ddsd.lPitch) + (nX * 3 + 1)] = ni; ((unsigned char *)ddsd.lpSurface)[((nY * 3 + 1) * ddsd.lPitch) + (nX * 3)] = ni; ((unsigned char *)ddsd.lpSurface)[((nY * 3 + 1) * ddsd.lPitch) + (nX * 3 + 1)] = ni; ni++; } lpBackbuffer->Unlock(NULL); /* And now write Frames per second. */ /* Increment Frame counter. */ nFramesSinceLastTick++; /* Get system tick count. */ Ticks = GetTickCount(); /* Update fps value every second. */ if (Ticks > (LastTicks + 1000)) { nFramesPerSecond = nFramesSinceLastTick; nFramesSinceLastTick = 0; LastTicks = Ticks; } /* Get a DC to the buffer & write count. */ if (DD_OK == lpBackbuffer->GetDC(&hDC)) { SetBkMode(hDC, TRANSPARENT); hOldFont = SelectObject(hDC, AppFont); /* Build a string for display. */ slen = wsprintf(s, "FPS : %d", nFramesPerSecond); /* And draw the text. */ SetTextColor(hDC, RGB(0,0,0)); SIZE sz; GetTextExtentPoint32(hDC, s, slen, &sz); RECT rc; rc.top = 0; rc.left = 16 * 3; rc.right = 16 * 3 + sz.cx + 10; rc.bottom = sz.cy + 10; DrawFrameControl(hDC, &rc, DFC_BUTTON, DFCS_BUTTONPUSH); TextOut(hDC, 16*3 + 5, 5, s, slen); SelectObject(hDC, hOldFont); lpBackbuffer->ReleaseDC(hDC); } /* Perform required pageflipping to make the surface * we drawed visible. */ ddreturn = lpPrimary->Flip(NULL, DDFLIP_WAIT); if (ddreturn == DD_OK) { return 1; } } } } } return 0; }