int DDraw_Draw_Surface_Scaled(LPDIRECTDRAWSURFACE7 source, // source surface to draw int x, int y, // position to draw at int width_src, int height_src,// size of source surface int width_dest, int height_dest,// size of dest surface LPDIRECTDRAWSURFACE7 dest, // surface to draw the surface on int transparent = 1) // transparency flag { // draw the surface at the x,y defined by dest, send both the original // source size of surface, along with the desired size, if they are // different then directdraw will scale the bitmap for you // note that we are sending // the size of the surface, we could query for it, but that takes time // basically, we are really lacking datastructure as this point, since // you would create a datastructure that keep important info about the // surface, so you did't have to query it from directdraw RECT dest_rect, // the destination rectangle source_rect; // the source rectangle // fill in the destination rect dest_rect.left = x; dest_rect.top = y; dest_rect.right = x+width_dest-1; dest_rect.bottom = y+height_dest-1; // fill in the source rect source_rect.left = 0; source_rect.top = 0; source_rect.right = width_src-1; source_rect.bottom = height_src-1; // test transparency flag if (transparent) { // enable color key blit // blt to destination surface if (FAILED(dest->Blt(&dest_rect, source, &source_rect,(DDBLT_WAIT | DDBLT_KEYSRC), NULL))) return(0); } // end if else { // perform blit without color key // blt to destination surface if (FAILED(dest->Blt(&dest_rect, source, &source_rect,(DDBLT_WAIT), NULL))) return(0); } // end if // return success return(1); } // end DDraw_Draw_Surface_Scaled
int DDraw_Draw_Surface(LPDIRECTDRAWSURFACE7 source, // source surface to draw int x, int y, // position to draw at int width, int height, // size of source surface LPDIRECTDRAWSURFACE7 dest, // surface to draw the surface on int transparent = 1) // transparency flag { // draw a bob at the x,y defined in the BOB // on the destination surface defined in dest RECT dest_rect, // the destination rectangle source_rect; // the source rectangle // fill in the destination rect // 目标表面、也就是需要填充的表面 dest_rect.left = x; dest_rect.top = y; dest_rect.right = x+width-1; dest_rect.bottom = y+height-1; // fill in the source rect // 源表面、也就是需要拷贝数据的表面、这里将拷贝的表面 // 由传递过来的高宽决定 source_rect.left = 0; source_rect.top = 0; source_rect.right = width-1; source_rect.bottom = height-1; // test transparency flag // 设置是否为透明、要就必须设置色彩键 if (transparent) { // enable color key blit // blt to destination surface if (FAILED(dest->Blt(&dest_rect, source, &source_rect,(DDBLT_WAIT | DDBLT_KEYSRC), NULL))) return(0); } // end if else { // perform blit without color key // blt to destination surface if (FAILED(dest->Blt(&dest_rect, source, &source_rect,(DDBLT_WAIT), NULL))) return(0); } // end if // return success return(1); } // end DDraw_Draw_Surface
void DDDrawBorder() { DDBLTFX ddbltfx; if (FScreen.Stretch) return; ddbltfx.dwSize=sizeof(ddbltfx); ddbltfx.dwFillColor = LetterBoxColour; //RGB(250, 25, 5); m_pddsFrontBuffer->Blt(&BorderTop, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); m_pddsFrontBuffer->Blt(&BorderBottom, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); m_pddsFrontBuffer->Blt(&BorderRight, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); m_pddsFrontBuffer->Blt(&BorderLeft, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx); }
void CPage::Blt(LPDIRECTDRAWSURFACE7 lpSurf) { if (childwindow) { childwindow->Blt(lpSurf); return; } PreBlt(); RECT d={0,0,sx,sy}; RECT s={0,0,w,h}; lpSurf->Blt(&d,surf,&s,DDBLT_WAIT,NULL); { // Cursor malen POINT mp; GetCursorPos(&mp); if (WindowFromPoint(mp)==hWnd) { ::ScreenToClient(hWnd,&mp); lpCursor->SetPos(mp.x,mp.y); lpCursor->Draw(lpSurf,sx,sy); } } }
//----------------------------------------------------------------------------- // Name: dx_Affiche() // Desc: Affiche le contenu du buffer à l'écran //----------------------------------------------------------------------------- bool dx_Affiche () { if (PleinEcran) { ErrDd = SurfacePrimaire->Flip (0, DDFLIP_WAIT); } else { RECT tRectSrc; RECT tRectDest; POINT tPosition = {0,0}; // Copie de Surface suivant la position de la fenêtre ClientToScreen (Fenetre, &tPosition); GetClientRect (Fenetre, &tRectDest); if (TailleFenetre) SetRect (&tRectSrc, 0, 0, tRectDest.right-tRectDest.left, tRectDest.bottom-tRectDest.top); else SetRect (&tRectSrc, 0, 0, ResolutionX, ResolutionY); OffsetRect (&tRectDest, tPosition.x, tPosition.y); ErrDd = SurfacePrimaire->Blt (&tRectDest,SurfaceBack,&tRectSrc,DDBLT_WAIT,NULL); } return dx_Test (); };
HRESULT STDMETHODCALLTYPE Blt(LPDIRECTDRAWSURFACE7 surface, LPRECT lpDestRect, LPDIRECTDRAWSURFACE7 lpDDSrcSurface, LPRECT lpSrcRect, DWORD dwFlags, LPDDBLTFX lpDDBltFx) { //logOutput << CurrentTimeString() << "Hooked Blt()" << endl; EnterCriticalSection(&ddrawMutex); ddrawSurfaceBlt.Unhook(); HRESULT hr = surface->Blt(lpDestRect, lpDDSrcSurface, lpSrcRect, dwFlags, lpDDBltFx); ddrawSurfaceBlt.Rehook(); if (SUCCEEDED(hr)) { if (!g_bUseFlipMethod) { if (getFrontSurface(surface)) { CaptureDDraw(); } } } LeaveCriticalSection(&ddrawMutex); return hr; }
int Draw_Rectangle(int x1, int y1, int x2, int y2, int color, LPDIRECTDRAWSURFACE7 lpdds) { // this function uses directdraw to draw a filled rectangle DDBLTFX ddbltfx; // this contains the DDBLTFX structure RECT fill_area; // this contains the destination rectangle // clear out the structure and set the size field DD_INIT_STRUCT(ddbltfx); // set the dwfillcolor field to the desired color ddbltfx.dwFillColor = color; // fill in the destination rectangle data (your data) fill_area.top = y1; fill_area.left = x1; fill_area.bottom = y2+1; fill_area.right = x2+1; // ready to blt to surface, in this case blt to primary lpdds->Blt(&fill_area, // ptr to dest rectangle NULL, // ptr to source surface, NA NULL, // ptr to source rectangle, NA DDBLT_COLORFILL | DDBLT_WAIT | DDBLT_ASYNC, // fill and wait &ddbltfx); // ptr to DDBLTFX structure // return success return(1); } // end Draw_Rectangle
//----------------------------------------------------------------------------- // Name: dx_Efface() // Desc: Efface le buffer d'affichage //----------------------------------------------------------------------------- bool dx_Efface (uint8 Rouge, uint8 Vert, uint8 Bleu) { ZeroMemory (&BlitFX, sizeof(BlitFX)); BlitFX.dwSize = sizeof (BlitFX); BlitFX.dwFillColor = RGB (Rouge,Vert,Bleu); SurfaceBack->Blt (NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &BlitFX); return dx_Test (); }
//----------------------------------------------------------------------------- // Name: CopySurface() // Desc: this function copies one surface to another //----------------------------------------------------------------------------- int CopySurface(LPDIRECTDRAWSURFACE7 lpddsDestSurface, RECT *destRect,LPDIRECTDRAWSURFACE7 lpddsSorSurface, RECT *sorRect) {// this function flips a surface onto the primary surface //Blt the frame ddReturnVal = lpddsDestSurface->Blt(destRect/*dest rect*/,lpddsSorSurface, //pointer to source surface sorRect, //pointer to the source rectangle DDBLT_WAIT | DDBLT_KEYSRC, NULL/*ddbltfx struct*/);//NULL means entire surface if (DDFailedCheck(ddReturnVal, "CopySurface(), Blt failed", cpErrorBuf )) { MessageBox(NULL, cpErrorBuf, "DrawSprite()", MB_ICONEXCLAMATION); return(0); } return 1; }
//----------------------------------------------------------------------------- // Name: dx_SurfaceCopie(...) // Desc: Copie le contenu d'une surface dans le buffer d'affichage //----------------------------------------------------------------------------- bool dx_SurfaceCopie (uint8 pNoSurface, uint16 pPosX, uint16 pPosY) { DDSURFACEDESC2 ddsd; ZeroMemory ((void*)&ddsd, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_HEIGHT | DDSD_WIDTH; Surfaces[pNoSurface]->GetSurfaceDesc (&ddsd); RECT rDest = {pPosX, pPosY, pPosX+ddsd.dwWidth-1, pPosY+ddsd.dwHeight-1}; return (ErrDd = SurfaceBack->Blt (&rDest, Surfaces[pNoSurface], NULL, DDBLT_WAIT, NULL)) == DD_OK; }
void CCursor::Draw(LPDIRECTDRAWSURFACE7 lpSurf,const int w,const int h)const { //#define STRETCHCURSOR if (lpSurface[curframe]==NULL)return; if ((CursorPos.x<0)||(CursorPos.y<0)||(CursorPos.x>w)||(CursorPos.y>w))return; const int hotspotx=10; const int hotspoty=5; #ifdef STRETCHCURSOR const int cw=(width*w)/800; const int ch=(height*h)/600; RECT s={0,0,width,height}; RECT d={x,y,x+cw,y+ch}; if (d.right>w) { s.right-=((d.right-w)*800)/w; d.right=w; } if (d.bottom>h) { s.bottom-=((d.bottom-h)*600)/h; d.bottom=h; } lpSurf->Blt(&d,lpSurface[curframe],&s,DDBLT_WAIT|DDBLT_KEYSRC,NULL); #else RECT src={0,0,width,height}; int mx=CursorPos.x-hotspotx; int my=CursorPos.y-hotspoty; if (mx<0) { src.left-=mx; mx=0; } if (my<0) { src.top-=my; my=0; } if (mx+src.right>w) src.right=w-mx; if (my+src.bottom>h) src.bottom=h-my; lpSurf->BltFast(mx,my,lpSurface[curframe],&src,DDBLTFAST_SRCCOLORKEY); #endif }
//----------------------------------------------------------------------------- // Name: DrawSprite() // Desc: Draws a list of sprites to a surface using internal (x,y) //----------------------------------------------------------------------------- int CSPRITE::DrawSprite(LPDIRECTDRAWSURFACE7 lpddsSurface) { static RECT destRect; //static int j=0; //static DWORD start=GetTickCount(); //static CTIMER timer; if( (m_iState != SPRITE_STATE_DEAD) && ( m_iAttr == SPRITE_ATTR_LOADED) ) { //Fill in dest rect destRect.top = m_iY; destRect.left = m_iX; destRect.bottom = m_iY + m_iHeight; destRect.right = m_iX + m_iWidth; //Setup the time between frames drawn if( m_Timer.Elapsed(m_iTimeBetweenFrames) && (m_ipAnimAttr[m_iCurrentAnimSequence] != SPRITE_ANIM_DONE) ) { m_Counter++; m_Timer.StartTimer();//m_StartTime=GetTickCount(); //Check to see if reached last frame in sequence if( m_Counter > m_ipAnimSeqMax[m_iCurrentAnimSequence]) if(m_ipAnimAttr[m_iCurrentAnimSequence] == SPRITE_ANIM_CONT) //check to see if sprite is supposed to be cont animated m_Counter=0; else //animate it once if( m_ipAnimAttr[m_iCurrentAnimSequence] == SPRITE_ANIM_ONCE ) { m_Counter = m_ipAnimSeqMax[m_iCurrentAnimSequence]; m_ipAnimAttr[m_iCurrentAnimSequence] = SPRITE_ANIM_DONE; } } //Get the next frame from the anim sequence m_iCurrentFrame = m_ipAnimations[m_iCurrentAnimSequence][m_Counter]; //Blt the frame ddReturnVal = lpddsSurface->Blt(&destRect/*dest rect*/,m_lpddsImage[m_iCurrentFrame], //pointer to source surface &m_Rect, //pointer to the source rectangle DDBLT_WAIT | DDBLT_KEYSRC, NULL/*ddbltfx struct*/); if(ddReturnVal != DD_OK) if(ddReturnVal==DDERR_SURFACELOST) { this->RestoreSurface(); lpddsPrimary->Restore();OutputDebugString("Surfacelost DrawSprite()\n"); return(1); } else if (DDFailedCheck(ddReturnVal, "DrawSprite(), Blt failed", cpErrorBuf )) { MessageBox(main_window_handle, cpErrorBuf, "DrawSprite()", MB_ICONEXCLAMATION); return(0); } }//End if( (m_iState != SPRITE_STATE_DEAD) && ( m_iAttr == SPRITE_ATTR_LOADED) ) return(1); }
//----------------------------------------------------------------------------- // Name: Flip() // Desc: this function flips a surface onto the primary surface //----------------------------------------------------------------------------- int Flip(LPDIRECTDRAWSURFACE7 lpddsSurface, RECT destrect) {// this function flips a surface onto the primary surface //Blt the frame ddReturnVal = lpddsPrimary->Blt(&destrect/*dest rect*/,lpddsSurface, //pointer to source surface NULL, //pointer to the source rectangle DDBLT_WAIT | DDBLT_KEYSRC, NULL/*ddbltfx struct*/);//NULL means entire surface if(ddReturnVal!=DD_OK) if(ddReturnVal==DDERR_SURFACELOST) { OutputDebugString("Surfacelost Flip(RECT)\n"); lpddsSurface->Restore(); lpddsPrimary->Restore(); return(1); } else if (DDFailedCheck(ddReturnVal, "Flip(lpddsSurface, RECT), Blt failed", cpErrorBuf )) { MessageBox(NULL, cpErrorBuf, "SurfaceFuncs", MB_ICONEXCLAMATION); return(0); } return 1; }
BOOL Test_PrivateData (INT* passed, INT* failed) { LPDIRECTDRAWSURFACE7 Surface; DWORD size, dummy = 0xBAADF00D; GUID guid = { 0 }; GUID guid2 = { 0x1 }; if(!CreateSurface(&Surface)) return FALSE; // General test TEST(Surface->SetPrivateData(guid, NULL, 0, 0) == DDERR_INVALIDPARAMS); TEST(Surface->SetPrivateData(guid, (LPVOID)&dummy, 0, 0) == DDERR_INVALIDPARAMS); TEST(Surface->SetPrivateData(guid, (LPVOID)0xdeadbeef, sizeof(DWORD), 0) == DDERR_INVALIDPARAMS); TEST(Surface->SetPrivateData(guid, (LPVOID)&dummy, sizeof(DWORD), 0) == DD_OK); TEST(Surface->GetPrivateData(guid, NULL, 0) == DDERR_INVALIDPARAMS); TEST(Surface->GetPrivateData(guid, &dummy, 0) == DDERR_INVALIDPARAMS); size = 0; TEST(Surface->GetPrivateData(guid, &dummy, &size) == DDERR_MOREDATA && size == sizeof(DWORD)); size = 2; TEST(Surface->GetPrivateData(guid, NULL, &size) == DDERR_MOREDATA && size == sizeof(DWORD)); TEST(Surface->GetPrivateData(guid, NULL, &size) == DDERR_INVALIDPARAMS); TEST(Surface->GetPrivateData(guid, &dummy, &size) == DD_OK && dummy == 0xBAADF00D); TEST(Surface->GetPrivateData(guid2, NULL, 0) == DDERR_NOTFOUND); TEST(Surface->FreePrivateData(guid) == DD_OK); TEST(Surface->FreePrivateData(guid) == DDERR_NOTFOUND); // Test for DDSPD_VOLATILE flag TEST(Surface->SetPrivateData(guid, (LPVOID)&dummy, sizeof(DWORD), DDSPD_VOLATILE) == DD_OK); size = 0; TEST(Surface->GetPrivateData(guid, NULL, &size) == DDERR_MOREDATA && size == sizeof(DWORD)); TEST(Surface->GetPrivateData(guid, &dummy, &size) == DD_OK && dummy == 0xBAADF00D); DDBLTFX bltfx; bltfx.dwSize = sizeof(DDBLTFX); bltfx.dwFillColor = RGB(0, 0, 0); if(Surface->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &bltfx) != DD_OK) printf("ERROR: Failed to draw to surface !"); TEST(Surface->GetPrivateData(guid, &dummy, &size) == DDERR_EXPIRED); // TODO: Test for DDSPD_IUNKNOWNPOINTER (see http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/ddraw7/directdraw7/ddref_5qyf.asp) Surface->Release(); return TRUE; }
HRESULT GameDisplayLoop(HWND hWnd, PFPImage pImage, LONG destX, LONG destY) { HRESULT hResult; DDBLTFX ddBltFx; memset(&ddBltFx, 0, sizeof(ddBltFx)); ddBltFx.dwSize = sizeof(ddBltFx); ddBltFx.dwROP = SRCCOPY; RECT rcMain = { 0 }; GetClientRect(hWnd, &rcMain); ClientToScreen(hWnd, ((LPPOINT)&rcMain) + 0); ClientToScreen(hWnd, ((LPPOINT)&rcMain) + 1); //FP_DEBUG_MSG(_T("CLINET RECT: (%d, %d) - (%d, %d)\n"), rcMain.top, rcMain.bottom, rcMain.left, rcMain.right); RECT rcBack = { 0 }; DDSURFACEDESC2 ddsd; DDRAW_INIT_STRUCT(ddsd); if (FAILED(hResult = lpddsBack->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL))) { FP_DEBUG_MSG(_T("Lock Error: 0x%08x\n"), hResult); return E_FAIL; } LPPALETTEENTRY lpPalet = NULL; if (FAILED(gameGraphics->ChangePalette(FP_PALETTE_DAY, &lpPalet))) { return E_FAIL; } LPBYTE lpPixel = (LPBYTE)ddsd.lpSurface; LPBYTE lpData = (LPBYTE)pImage->data; LONG n = 0; for (LONG i = 0; i < pImage->height; i++) { n = (i + destY) * ddsd.lPitch + destX * sizeof(PALETTEENTRY); for (LONG j = 0; j < pImage->width; j++, n += 4) { LPBYTE lpPtr = &lpPixel[n]; *(lpPtr + 0) = lpPalet[lpData[(pImage->height - i - 1) * pImage->width + j]].peRed; *(lpPtr + 1) = lpPalet[lpData[(pImage->height - i - 1) * pImage->width + j]].peGreen; *(lpPtr + 2) = lpPalet[lpData[(pImage->height - i - 1) * pImage->width + j]].peBlue; *(lpPtr + 3) = 0; } } lpddsBack->Unlock(NULL); lpddsMain->Blt(&rcMain, lpddsBack, NULL, DDBLT_WAIT, &ddBltFx); return S_OK; }
BOOL jcdd_colorFillSurface(LPDIRECTDRAWSURFACE7 lpdds, INT width, INT height, UINT color) { if(lpdds == NULL) { return FALSE; } RECT destRect = {0, 0, width, height}; DDBLTFX ddbltfx; jcdd_initStruct(&ddbltfx); ddbltfx.dwFillColor = color; if(FAILED(lpdds->Blt(&destRect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx))) { return FALSE; } return TRUE; }
BOOL JCDD_Wrapper::drawBitmapData(INT surfaceID, LPRECT srcRect, LPRECT destRect) { if(!lpjcdd->containsTheOffscreenSurface(surfaceID)) { return FALSE; } LPDIRECTDRAWSURFACE7 dest = lpjcdd->getBackBufferSurface(); LPDIRECTDRAWSURFACE7 src = lpjcdd->getOffscreenSurface(surfaceID)->getSurface(); DWORD bltFlags = lpjcdd->getUseColorKey() ? DDBLT_WAIT | DDBLT_KEYSRC : DDBLT_WAIT; if(FAILED(dest->Blt(destRect, src, srcRect, bltFlags, NULL))) { return FALSE; } return TRUE; }
/** * vdraw_ddraw_clear_back_screen(): Clear the back buffer. * @return 0 on success; non-zero on error. */ int WINAPI vdraw_ddraw_clear_back_screen(void) { if (!lpDD || !lpDDS_Back) return -1; DDSURFACEDESC2 ddsd; DDBLTFX ddbltfx; memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); memset(&ddbltfx, 0, sizeof(ddbltfx)); ddbltfx.dwSize = sizeof(ddbltfx); ddbltfx.dwFillColor = 0; lpDDS_Back->Blt(NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx); return 1; }
int DDraw_Fill_Surface(LPDIRECTDRAWSURFACE7 lpdds,int color) { DDBLTFX ddbltfx; // this contains the DDBLTFX structure // clear out the structure and set the size field DDRAW_INIT_STRUCT(ddbltfx); // set the dwfillcolor field to the desired color ddbltfx.dwFillColor = color; // ready to blt to surface lpdds->Blt(NULL, // ptr to dest rectangle NULL, // ptr to source surface, NA NULL, // ptr to source rectangle, NA DDBLT_COLORFILL | DDBLT_WAIT, // fill and wait &ddbltfx); // ptr to DDBLTFX structure // return success return(1); } // end DDraw_Fill_Surface
void DDAccurateUpdateDisplay(bool singlestep) { static int framecounter=0; HRESULT hRet; RECT rDest; if (++framecounter > zx81.frameskip || singlestep) framecounter=0; else return; DDFrame->Unlock(NULL); POINT p = {0, 0}; if(!Form1->FullScreen) p=Form1->ClientToScreen(p); rDest=rcdest; rDest.left += p.x; rDest.top += p.y; rDest.right += p.x; rDest.bottom += p.y; //if (Form1->FullScreen) DDDrawBorder(); while(1) { hRet = m_pddsFrontBuffer->Blt(&rDest, DDFrame, &rcsource, DDBLT_WAIT, NULL); if (hRet == DD_OK) break; else if(hRet == DDERR_SURFACELOST) { m_pddsFrontBuffer->Restore(); m_pddsFrame->Restore(); } else if(hRet != DDERR_WASSTILLDRAWING) return; } DDFrame->Lock(NULL, &DDFrameSurface, DDLOCK_WAIT | DDLOCK_NOSYSLOCK, NULL); dest=buffer= (BYTE*)DDFrameSurface.lpSurface; }
//----------------------------------------------------------------------------- // Name: Flip() // Desc: this function flips a surface onto the primary surface // primary surface expected to be a normal window (non-fullscreen). // flips to client area only //----------------------------------------------------------------------------- int FlipToClient(LPDIRECTDRAWSURFACE7 lpddsSurface) {// this function flips a surface onto the primary surface static RECT temp; GetWindowRect(main_window_handle, &temp); temp.top +=20; temp.left +=4; temp.right -=4; temp.bottom -=4; //Blt the frame ddReturnVal = lpddsPrimary->Blt(&temp/*dest rect*/,lpddsSurface, //pointer to source surface NULL, //pointer to the source rectangle DDBLT_WAIT | DDBLT_KEYSRC, NULL/*ddbltfx struct*/);//NULL means entire surface if(ddReturnVal!=DD_OK) if(ddReturnVal==DDERR_SURFACELOST) { OutputDebugString("Surfacelost FlipToClient()\n"); lpddsSurface->Restore(); lpddsPrimary->Restore(); return(1); } else if (DDFailedCheck(ddReturnVal, "FlipToClient(lpddsSurface), Blt failed", cpErrorBuf )) { MessageBox(NULL, cpErrorBuf, "SurfaceFuncs", MB_ICONEXCLAMATION); return(0); } return 1; }
// Draw video to DirectDraw surface. BOOL CDShow::Draw(LPDIRECTDRAWSURFACE7 lpDDSurface7) { // Return FALSE if media was not open if (!m_bMediaOpen) { return FALSE; } // Update media stream. // If it does not return S_OK, we are not playing. if (m_pSample->Update(0,NULL,NULL,0)!=S_OK) { m_bPlaying=FALSE; } // Now blit video to specified surface and rect. // Restore surface if lost. if (lpDDSurface7->Blt(NULL,m_pDDSurface7, &m_rSrcRect,DDBLT_WAIT,NULL)==DDERR_SURFACELOST) lpDDSurface7->Restore(); // Ok. return TRUE. return TRUE; }
int Game_Main(void *parms = NULL, int num_parms = 0) { // this is the main loop of the game, do all your processing // here DDBLTFX ddbltfx; // the blitter fx structure static int feeling_counter = 0; // tracks how we feel :) static int happy = 1; // let's start off being happy // make sure this isn't executed again if (window_closed) return(0); // for now test if user is hitting ESC and send WM_CLOSE if (KEYDOWN(VK_ESCAPE)) { PostMessage(main_window_handle,WM_CLOSE,0,0); window_closed = 1; } // end if // use the blitter to erase the back buffer // first initialize the DDBLTFX structure DDRAW_INIT_STRUCT(ddbltfx); // now set the color word info to the color we desire ddbltfx.dwFillColor = 0; // make the blitter call if (FAILED(lpddsback->Blt(NULL, // pointer to dest RECT, NULL for whole thing NULL, // pointer to source surface NULL, // pointer to source RECT DDBLT_COLORFILL | DDBLT_WAIT, // do a color fill and wait if you have to &ddbltfx))) // pointer to DDBLTFX holding info return(0); // initialize ddsd DDRAW_INIT_STRUCT(ddsd); // lock the back buffer surface if (FAILED(lpddsback->Lock(NULL,&ddsd, DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR, NULL))) return(0); // increment how we feel if (++feeling_counter > 200) { feeling_counter = 0; happy = -happy; } // end if // draw all the happy faces for (int face=0; face < 100; face++) { // are we happy or sad? if (happy==1) // we are happy :) Blit_Clipped(happy_faces[face].x, happy_faces[face].y, 8,8, happy_bitmap, (UCHAR *)ddsd.lpSurface, ddsd.lPitch); else // we must be sad :( Blit_Clipped(happy_faces[face].x, happy_faces[face].y, 8,8, sad_bitmap, (UCHAR *)ddsd.lpSurface, ddsd.lPitch); } // end face // move all happy faces for (face=0; face < 100; face++) { // move happy_faces[face].x+=happy_faces[face].xv; happy_faces[face].y+=happy_faces[face].yv; // check for off screen, if so wrap if (happy_faces[face].x > SCREEN_WIDTH) happy_faces[face].x = -8; else if (happy_faces[face].x < -8) happy_faces[face].x = SCREEN_WIDTH; if (happy_faces[face].y > SCREEN_HEIGHT) happy_faces[face].y = -8; else if (happy_faces[face].y < -8) happy_faces[face].y = SCREEN_HEIGHT; } // end face // unlock surface if (FAILED(lpddsback->Unlock(NULL))) return(0); // flip the pages while (FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT))); // wait a sec Sleep(30); // return success or failure or your own return code here return(1); } // end Game_Main
/** * vdraw_ddraw_clear_primary_screen(): Clear the primary screen. * @return 0 on success; non-zero on error. */ int WINAPI vdraw_ddraw_clear_primary_screen(void) { if (!lpDD || !lpDDS_Primary) return -1; DDSURFACEDESC2 ddsd; DDBLTFX ddbltfx; RECT rd; POINT p; memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); memset(&ddbltfx, 0, sizeof(ddbltfx)); ddbltfx.dwSize = sizeof(ddbltfx); ddbltfx.dwFillColor = 0; // Black if (vdraw_get_fullscreen()) { if (Video.VSync_FS) { lpDDS_Flip->Blt(NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx); lpDDS_Primary->Flip(NULL, DDFLIP_WAIT); lpDDS_Flip->Blt(NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx); lpDDS_Primary->Flip(NULL, DDFLIP_WAIT); lpDDS_Flip->Blt(NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx); lpDDS_Primary->Flip(NULL, DDFLIP_WAIT); } else { lpDDS_Primary->Blt(NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx); } } else { p.x = p.y = 0; GetClientRect(gens_window, &rd); ClientToScreen(gens_window, &p); rd.left = p.x; rd.top = p.y; rd.right += p.x; rd.bottom += p.y; // Clip the destination rectangle to the screen. if (rd.bottom > vdraw_rectDisplay.bottom) rd.bottom += (vdraw_rectDisplay.bottom - rd.bottom); if (rd.top < vdraw_rectDisplay.top) rd.top += (vdraw_rectDisplay.top - rd.top); if (rd.left < vdraw_rectDisplay.left) rd.left += (vdraw_rectDisplay.left - rd.left); if (rd.right > vdraw_rectDisplay.right) rd.right += (vdraw_rectDisplay.right - rd.right); if (rd.top < rd.bottom) lpDDS_Primary->Blt(&rd, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &ddbltfx); } return 0; }
/** * vdraw_ddraw_flip(): Flip the screen buffer. [Called by vdraw_flip().] * @return 0 on success; non-zero on error. */ int vdraw_ddraw_flip(void) { if (!lpDD) return -1; HRESULT rval = DD_OK; DDSURFACEDESC2 ddsd; ddsd.dwSize = sizeof(ddsd); RECT RectSrc; // Calculate the source rectangle. vdraw_ddraw_calc_RectSrc(RectSrc); if (vdraw_get_fullscreen()) { // Fullscreen. if (vdraw_ddraw_is_hw_render()) { // Hardware rendering. // 1x rendering. // TODO: Test this with border color stuff. // Wine doesn't seem to have a 320x240 fullscreen mode available... // TODO: Test this on a system that supports 1x in fullscreen on DirectDraw. vdraw_ddraw_draw_text(&ddsd, lpDDS_Back, true); if (Video.VSync_FS) { lpDDS_Flip->Blt(&RectDest, lpDDS_Back, &RectSrc, DDBLT_WAIT | DDBLT_ASYNC, NULL); lpDDS_Primary->Flip(NULL, DDFLIP_WAIT); } else { lpDDS_Primary->Blt(&RectDest, lpDDS_Back, &RectSrc, DDBLT_WAIT | DDBLT_ASYNC, NULL); //lpDDS_Primary->Blt(&RectDest, lpDDS_Back, &RectSrc, NULL, NULL); } } else { // Software rendering. LPDIRECTDRAWSURFACE7 curBlit = lpDDS_Blit; rval = curBlit->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL); if (FAILED(rval)) goto cleanup_flip; vdraw_rInfo.destScreen = (void*)ddsd.lpSurface; vdraw_rInfo.width = 320; vdraw_rInfo.height = 240; vdraw_rInfo.destPitch = ddsd.lPitch; if (vdraw_needs_conversion) { // Color depth conversion is required. vdraw_rgb_convert(&vdraw_rInfo); } else { // Color conversion is not required. vdraw_blitFS(&vdraw_rInfo); } // Draw the text. vdraw_ddraw_draw_text(&ddsd, curBlit, false); curBlit->Unlock(NULL); if (curBlit == lpDDS_Back) // note: this can happen in windowed fullscreen, or if CORRECT_256_ASPECT_RATIO is defined and the current display mode is 256 pixels across { if (Video.VSync_FS) { int vb; lpDD->GetVerticalBlankStatus(&vb); if (!vb) lpDD->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, 0); } lpDDS_Primary->Blt(&RectDest, lpDDS_Back, &RectSrc, DDBLT_WAIT | DDBLT_ASYNC, NULL); } else { if (Video.VSync_FS) { lpDDS_Primary->Flip(NULL, DDFLIP_WAIT); } } } } else { // Windowed mode. if (!vdraw_ddraw_is_hw_render()) { rval = lpDDS_Blit->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL); if (FAILED(rval)) goto cleanup_flip; vdraw_rInfo.destScreen = (void*)ddsd.lpSurface; vdraw_rInfo.width = 320; vdraw_rInfo.height = 240; vdraw_rInfo.destPitch = ddsd.lPitch; if (vdraw_needs_conversion) { // Color depth conversion is required. vdraw_rgb_convert(&vdraw_rInfo); } else { // Color conversion is not required. vdraw_blitW(&vdraw_rInfo); } // Draw the text. vdraw_ddraw_draw_text(&ddsd, lpDDS_Blit, false); lpDDS_Blit->Unlock(NULL); } else { // Draw the text. vdraw_ddraw_draw_text(&ddsd, lpDDS_Blit, true); } if (RectDest.top < RectDest.bottom) { if (Video.VSync_W) { int vb; lpDD->GetVerticalBlankStatus(&vb); if (!vb) lpDD->WaitForVerticalBlank(DDWAITVB_BLOCKBEGIN, 0); } // Blit the image. rval = lpDDS_Primary->Blt(&RectDest, lpDDS_Back, &RectSrc, DDBLT_WAIT | DDBLT_ASYNC, NULL); //rval = lpDDS_Primary->Blt(&RectDest, lpDDS_Back, &RectSrc, NULL, NULL); } } cleanup_flip: if (rval == DDERR_SURFACELOST) rval = vdraw_ddraw_restore_graphics(); return 1; }
////FUNCTIONS////////////////// //----------------------------------------------------------------------------- // Name: Main() // Desc: Whwere all work is done //----------------------------------------------------------------------------- bool main() { static SCCOLOR col; static UCHAR* back_buf; static HDC hDC; static int iFrames=0; static int x=0; col.b = col.r = col.g = 255; if(GetKeyStatus(VK_ESCAPE) == true) return(0); //Clear the surface if(!ClrS(lpddsSecondary,wndRect))//can't be within a lock-Unlock block or u can't blt return(0); //Write text to the Secondary surface remember to Release the DC ddReturnVal = lpddsSecondary->GetDC(&hDC); if (DDFailedCheck(ddReturnVal, "GetDC() failed", cpErrorBuf )) { if(ddReturnVal == DDERR_SURFACELOST) { lpddsSecondary->Restore(); lpddsSecondary->GetDC(&hDC); } else { MessageBox(main_window_handle, cpErrorBuf, "main()", MB_ICONEXCLAMATION); return(0); } } static char buffer[1024]; SetBkColor(hDC,RGB(0,0,0)); SetBkMode(hDC,OPAQUE); sprintf(buffer, "Time elapsed(s)= %d", (int)(gametimer.GetStartElapsedTime()*0.001) );//0.00001666666f static DWORD starttime=GetTickCount(); if( gametimer.Elapsed(starttime,(60/0.001)) ) sprintf(buffer,"TIME!"," 1 minute"); SetTextColor(hDC,RGB(255,255,255)); iFrames++; static int FramesPerSec=0; FramesPerSec = iFrames/( ((int)(gametimer.GetStartElapsedTime()*0.001)+1) ); sprintf(buffer, "Frames/s = %d", FramesPerSec); TextOut(hDC, 100,100, buffer, strlen(buffer)); sprintf(buffer, "X= %d", x); TextOut(hDC, 100,140, buffer, strlen(buffer)); ddReturnVal = lpddsSecondary->ReleaseDC(hDC); if (DDFailedCheck(ddReturnVal, "ReleaseDC() failed", cpErrorBuf )) { MessageBox(main_window_handle, cpErrorBuf, "main()", MB_ICONEXCLAMATION); return(0); } //Lock the surface for drawing if(!Lock(lpddsSecondary)) return(0); back_buf = (UCHAR*)ddsd.lpSurface; //test drawing pixels DrawPixel(ddsd,x+200,100,col); DrawPixel(ddsd,x+200,101,col); DrawPixel(ddsd,x+200,102,col); DrawPixel(ddsd,x+200,103,col); DrawPixel(ddsd,x+200,104,col); DrawPixel(ddsd,x+200,105,col); DrawPixel(ddsd,x+200,106,col); DrawPixel(ddsd,x+200,107,col); DrawPixel(ddsd,x+200,108,col); x++; if(x>780) x=0; //test bitmap class for (int y=0; y < bitmap1.GetHeight(); y++) { // copy the line memcpy(&back_buf[100+(y+200)*ddsd.lPitch], // dest address &bitmap1.GetImageData()[y*bitmap1.GetWidth()*2], // src address bitmap1.GetWidth()*2); // bytes to copy } // end for y //Unlock the surface if(!UnLock(lpddsSecondary)) return(0); if(!Lock(Temp)) return(0); back_buf = (UCHAR*)ddsd.lpSurface; for (int y=0; y < bitmap2.GetHeight(); y++) { // copy the line memcpy(&back_buf[y*ddsd.lPitch], // dest address &bitmap2.GetImageData()[y*bitmap2.GetWidth()*2], // src address bitmap2.GetWidth()*2); // bytes to copy } // end for y if(!UnLock(Temp)) return(0); static RECT temprect= {200,200,520,400}; static RECT sorc_rect= {0,0,320,200}; ddReturnVal = lpddsSecondary->Blt(&temprect/*dest rect*/,Temp, //pointer to source surface &sorc_rect, //pointer to the source rectangle DDBLT_WAIT | DDBLT_KEYSRC,NULL); if (DDFailedCheck(ddReturnVal, "Blt failed", cpErrorBuf )) { MessageBox(main_window_handle, cpErrorBuf, "Main()", MB_ICONEXCLAMATION); return(0); } static RECT temprect2; temprect2.top=200; temprect2.left=500; temprect2.right=sprite.GetWidth()+500; temprect2.bottom=sprite.GetHeight()+200; static int i=0; ddReturnVal = lpddsSecondary->Blt(&temprect2/*dest rect*/,sprite.GetFrame(i), //pointer to source surface NULL, //pointer to the source rectangle DDBLT_WAIT | DDBLT_KEYSRC,NULL/*ddbltfx struct*/); if (DDFailedCheck(ddReturnVal, "Blt failed", cpErrorBuf )) { MessageBox(main_window_handle, cpErrorBuf, "Main()", MB_ICONEXCLAMATION); return(0); } static DWORD start = GetTickCount(); if(gametimer.Elapsed(start,120)) { i++; start = GetTickCount(); } if(i>13) i=0; static int size=0; temprect2.top=500+size; temprect2.left=300+size; temprect2.bottom=500+myface.GetWidth()+size; temprect2.right=300+myface.GetWidth()+size; ddReturnVal = lpddsSecondary->Blt(&temprect2/*dest rect*/,myface.GetFrame(0), //pointer to source surface NULL, //pointer to the source rectangle DDBLT_WAIT | DDBLT_KEYSRC,NULL/*ddbltfx struct*/); if (DDFailedCheck(ddReturnVal, "Blt failed", cpErrorBuf )) { MessageBox(main_window_handle, cpErrorBuf, "Main()", MB_ICONEXCLAMATION); return(0); } static int what=0; what++; size= sin(what)+cos(what+5); static int j=0; static DWORD start2=GetTickCount(); if(gametimer.Elapsed(start2,50)) { j++; start2=GetTickCount(); } if(j>=3)j=0; temprect2.top=500; temprect2.left=100; temprect2.bottom=500+ship.GetHeight(); temprect2.right=100+ship.GetWidth(); ddReturnVal = lpddsSecondary->Blt(&temprect2/*dest rect*/,ship.GetFrame(j), //pointer to source surface NULL, //pointer to the source rectangle DDBLT_WAIT | DDBLT_KEYSRC,NULL/*ddbltfx struct*/); if (DDFailedCheck(ddReturnVal, "Blt failed", cpErrorBuf )) { MessageBox(main_window_handle, cpErrorBuf, "Main()", MB_ICONEXCLAMATION); return(0); } temprect2.top=400; temprect2.left=500; temprect2.bottom=400+recttest.GetHeight()+50; temprect2.right=500+recttest.GetWidth()+50; ddReturnVal = lpddsSecondary->Blt(&temprect2/*dest rect*/,recttest.GetFrame(0), //pointer to source surface &recttest.GetRect(), //pointer to the source rectangle DDBLT_WAIT | DDBLT_KEYSRC,NULL/*ddbltfx struct*/); if (DDFailedCheck(ddReturnVal, "Blt failed", cpErrorBuf )) { MessageBox(main_window_handle, cpErrorBuf, "Main()", MB_ICONEXCLAMATION); return(0); } temprect2.top=485; temprect2.left=160; temprect2.bottom=485+ship2.GetHeight(); temprect2.right=160+ship2.GetWidth(); static int k=0; static DWORD start3; if(gametimer.Elapsed(start3,0)) { k++; start3=GetTickCount(); } if(k>=11)k=0; ddReturnVal = lpddsSecondary->Blt(&temprect2/*dest rect*/,ship2.GetFrame(0), //pointer to source surface &ship2.GetRect(), //pointer to the source rectangle DDBLT_WAIT | DDBLT_KEYSRC,NULL/*ddbltfx struct*/); if (DDFailedCheck(ddReturnVal, "Blt failed", cpErrorBuf )) { MessageBox(main_window_handle, cpErrorBuf, "Main()", MB_ICONEXCLAMATION); return(0); } Flip(); return(1); }
BOOL CH264Decode::PreviewDraw(H264_DEC_FRAME_S DecodeData) { if (!m_bPreEnable) { return true; } DDSURFACEDESC2 ddsd; const HI_U8 *pY = DecodeData.pY; const HI_U8 *pU = DecodeData.pU; const HI_U8 *pV = DecodeData.pV; HI_U32 width = DecodeData.uWidth; HI_U32 height = DecodeData.uHeight; HI_U32 yStride = DecodeData.uYStride; HI_U32 uvStride = DecodeData.uUVStride; if (0 == width || 0 == height) { return true; } ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2)); ddsd.dwSize = sizeof(DDSURFACEDESC2); HRESULT hr; hr = m_pOffscreenSurface->Lock(NULL,&ddsd,DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,NULL); if (FAILED(hr)) { m_dwLastError = hr;//GetLastError(); switch(hr) { case DDERR_SURFACELOST: g_pDirectDraw7->RestoreAllSurfaces(); break; case DDERR_SURFACEBUSY: m_pOffscreenSurface->Unlock(NULL); break; default: break; } return FALSE; } PBYTE pDestY = (PBYTE)ddsd.lpSurface; PBYTE pDestV = (PBYTE)ddsd.lpSurface + ddsd.lPitch * ddsd.dwHeight; PBYTE pDestU = (PBYTE)ddsd.lpSurface + ddsd.lPitch * ddsd.dwHeight*5/4; for (HI_U32 i = 0;i<height;i++) { memcpy(pDestY,pY,yStride); pDestY += ddsd.lPitch; pY += yStride; } for (i = 0;i<height/2;i++) { memcpy(pDestU,pU,uvStride); pDestU += ddsd.lPitch/2; pU += uvStride; } for (i = 0;i<height/2;i++) { memcpy(pDestV,pV,uvStride); pDestV += ddsd.lPitch/2; pV += uvStride; } hr = m_pOffscreenSurface->Unlock(NULL); EnterCriticalSection(&m_csCritial); if (m_PlayWnd != NULL) { RECT rcDsp; ::GetClientRect( m_PlayWnd,&rcDsp); POINT ptTL; POINT ptRB; ptTL.x = rcDsp.left + 1; ptTL.y = rcDsp.top + 1; ptRB.x = rcDsp.right - 1; ptRB.y = rcDsp.bottom - 1; ::ClientToScreen( m_PlayWnd,&ptTL); ::ClientToScreen( m_PlayWnd,&ptRB); SetRect(&rcDsp,ptTL.x,ptTL.y,ptRB.x,ptRB.y); //写OSD /* HDC dcTemp; hr = m_pOSDSurface->GetDC(&dcTemp); DDSURFACEDESC2 ddsdOsd = {0}; ddsdOsd.dwSize = sizeof(ddsdOsd); m_pOSDSurface->GetSurfaceDesc(&ddsdOsd); HBRUSH BackBrush = CreateSolidBrush(RGB(0,0,0)); RECT rcOsd; SetRect(&rcOsd,0,0,ddsdOsd.dwWidth,ddsdOsd.dwHeight); FillRect(dcTemp,&rcOsd,BackBrush); DeleteObject(BackBrush); EnterCriticalSection(&m_csDcCallback); if (NULL != dccallbackFun) { dccallbackFun(dcTemp,m_nDcChl,lpDcUser); } LeaveCriticalSection(&m_csDcCallback); m_pOSDSurface->ReleaseDC(dcTemp); DDSURFACEDESC2 ddsdFin = {0}; ddsdFin.dwSize = sizeof(ddsdFin); m_pFinSurface->GetSurfaceDesc(&ddsdFin); RECT rcFin; SetRect(&rcFin,0,0,ddsdFin.dwWidth,ddsdFin.dwHeight); hr = m_pFinSurface->Blt(&rcFin,m_pOffscreenSurface,&rcSrc,DDBLT_WAIT,NULL); hr = m_pFinSurface->Blt(&rcFin,m_pOSDSurface,NULL,DDBLT_WAIT | DDBLT_KEYSRC,NULL);*/ RECT rcSrc; SetRect(&rcSrc,0,0,width,height); EnterCriticalSection(&g_csClipper); g_pClipper->SetHWnd(NULL,m_PlayWnd); if (::IsWindowVisible(m_PlayWnd)) { g_pPrimarySurface->Blt(&rcDsp,m_pOffscreenSurface,&rcSrc,DDBLT_WAIT,0); } LeaveCriticalSection(&g_csClipper); } LeaveCriticalSection(&m_csCritial); return TRUE; }
int Game_Main(void *parms = NULL, int num_parms = 0) { // this is the main loop of the game, do all your processing // here // lookup for proper walking sequence // 动画帧、先播放站立动作、然后是摆左手、然后再恢复站立动作、然后是摆右手 // 如此重复播放 // 声明为静态、所以不会随着Game_Main的调用而重复初始化 static int animation_seq[4] = {0,1,0,2}; int index; // general looping variable // make sure this isn't executed again if (window_closed) return(0); // for now test if user is hitting ESC and send WM_CLOSE if (KEYDOWN(VK_ESCAPE)) { PostMessage(main_window_handle,WM_CLOSE,0,0); window_closed = 1; } // end if DDRAW_INIT_STRUCT(ddbltfx); if(lpddsback->Blt(NULL, lpddsbackground, NULL, DDBLT_WAIT, &ddbltfx)) return 0; // move objects around // 这里是移动异形 for (index=0; index < 3; index++) { // move each object to the right at its given velocity // 移动异形向右走 aliens[index].x++; // =aliens[index].velocity; // 测试异形的位置是否已经到达了右边界已经完全看不着了 // 就把它又扔会左边从头走过来 // 因为x是左上角的坐标、所以x超过了屏幕宽度刚好完全看不见 // 而因为异形图片的人物宽度刚好为80、所以重置到左边时设置为-80 // test if off screen edge, and wrap around if (aliens[index].x > SCREEN_WIDTH) aliens[index].x = - 80; // animate bot if (++aliens[index].counter >= (8 - aliens[index].velocity)) { // reset counter aliens[index].counter = 0; // advance to next frame // 如果超过第三帧、则重置为第0帧、这里是由前面的结构所决定的、只有三个动作 // 由于采用了先自增再比较的办法、所以条件这里current_frame的范围恒为1~4 // 所谓的第零帧、也就是标准的站立动作、可以从位图图片得知、 if (++aliens[index].current_frame > 3) aliens[index].current_frame = 0; } // end if } // end for index // draw all the bots for (index=0; index < 3; index++) { /* 原型 int DDraw_Draw_Surface(LPDIRECTDRAWSURFACE7 source, // source surface to draw int x, int y, // position to draw at int width, int height, // size of source surface LPDIRECTDRAWSURFACE7 dest, // surface to draw the surface on int transparent = 1) // transparency flag */ // draw objects // 把相应的三个异形的每帧动作拷贝进缓冲表面中 // 其中animation_seq[aliens[index].current_frame]决定了产生哪些动作帧 // 在Game_Main函数就已经有定义了static int animation_seq[4] = {0,1,0,2}; // 这里current_frame的范围就是0~3 DDraw_Draw_Surface(aliens[index].frames[animation_seq[aliens[index].current_frame]], aliens[index].x, aliens[index].y, 72,80, lpddsback); } // end for index while(FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT))); // 每秒30帧 Sleep(33); // do nothing -- look at pretty picture // return success or failure or your own return code here return(1); } // end Game_Main
int Game_Main(void *parms = NULL, int num_parms = 0) { DDBLTFX ddbltfx; RECT dest_rect; static short curr_color = 0; static short top = 0; static short left = 0; if (window_closed) { return (0); } // for now test if user is hitting ESC and send WM_CLOSE if (KEYDOWN(VK_ESCAPE)) { window_closed = true; SendMessage(main_window_handle,WM_CLOSE,0,0); } // just blast pixels here.. #if 0 // this is the main loop of the game, do all your processing // here memset(&ddsd,0,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); if (FAILED(lpddsprimary->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL) ) ) { // BAD SHIT HAPPENED HERE... g_ddStepFailure = DDSF_LOCKFAILED; SendMessage(main_window_handle,WM_CLOSE,0,0); } int mempitch = (ddsd.lPitch >> 1); // adjust for words.. WORD *video_buffer = (WORD *) ddsd.lpSurface; #endif // prefigure mPitchlookup for even greater speed. // x1,y1 dest_rect.left = left; dest_rect.top = top; // x2,y2 dest_rect.right = dest_rect.left+20; dest_rect.bottom = dest_rect.top+20; // setup structure!!!! memset(&ddbltfx,0,sizeof(ddbltfx)); ddbltfx.dwSize = sizeof(ddbltfx); // color to fill. ddbltfx.dwFillColor = colors16[curr_color]; // blit it baby! if (FAILED(lpddsprimary->Blt(&dest_rect, NULL, // no source surface.. its just a fill NULL, // no source RECT, since no source surface.. DDBLT_COLORFILL | DDBLT_WAIT, &ddbltfx ))) { return(0); } #if 0 lpddsprimary->Unlock(NULL); #endif top = top + 10; left = left + 10; if (top > SCREEN_HEIGHT - 20) { top = 0; } if (left > SCREEN_WIDTH - 20) { left = 0; } curr_color++; if (curr_color > 5000) { curr_color = 0; } // return success or failure or your own return code here return(1); } // end Game_Main
void CDDrawRecord::DDsfDrawToDDsf(LPDIRECTDRAWSURFACE7 lpDDsfd, RECT& dst, LPDIRECTDRAWSURFACE7 lpDDSfr, RECT& rt) { HRESULT hr = lpDDsfd->Blt(&dst, lpDDSfr, &rt, DDBLT_WAIT, NULL); }