本文整理汇总了C++中LPDIRECTDRAWSURFACE7类的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTDRAWSURFACE7类的具体用法?C++ LPDIRECTDRAWSURFACE7怎么用?C++ LPDIRECTDRAWSURFACE7使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LPDIRECTDRAWSURFACE7类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AttachClipper
//-----------------------------------------------------------------------------
// Name: AttachClipper()
// Desc: creates and attaches a clipper to a surface
//-----------------------------------------------------------------------------
LPDIRECTDRAWCLIPPER AttachClipper(LPDIRECTDRAWSURFACE7 lpddsSurface, int iNumRects, LPRECT cliplist)
{
int index; //loop va
LPDIRECTDRAWCLIPPER lpddClipper; //pointer to the newly created dd clipper
LPRGNDATA regionData; //pointer to the region data that contains the header and clip list
//first create the DD clipper
ddReturnVal = lpddObj->CreateClipper(0,&lpddClipper, NULL);
if (DDFailedCheck(ddReturnVal, "CreateClipper() failed", cpErrorBuf ))
{ MessageBox(main_window_handle, cpErrorBuf, "AttachClipper()", MB_ICONEXCLAMATION); return(NULL); }
//now create the clip list from the sent data
//first allocate memory for region data
regionData = (LPRGNDATA)malloc(sizeof(RGNDATAHEADER) + iNumRects*sizeof(RECT));
//now copy the rects into region data
memcpy(regionData->Buffer, cliplist, sizeof(RECT)*iNumRects);
// set up fields of header
regionData->rdh.dwSize = sizeof(RGNDATAHEADER);
regionData->rdh.iType = RDH_RECTANGLES;
regionData->rdh.nCount = iNumRects;
regionData->rdh.nRgnSize = iNumRects*sizeof(RECT);
regionData->rdh.rcBound.left = 64000;
regionData->rdh.rcBound.top = 64000;
regionData->rdh.rcBound.right = -64000;
regionData->rdh.rcBound.bottom = -64000;
// find bounds of all clipping regions
for (index=0; index<iNumRects; index++)
{
// test if the next rectangle unioned with the current bound is larger
if (cliplist[index].left < regionData->rdh.rcBound.left)
regionData->rdh.rcBound.left = cliplist[index].left;
if (cliplist[index].right > regionData->rdh.rcBound.right)
regionData->rdh.rcBound.right = cliplist[index].right;
if (cliplist[index].top < regionData->rdh.rcBound.top)
regionData->rdh.rcBound.top = cliplist[index].top;
if (cliplist[index].bottom > regionData->rdh.rcBound.bottom)
regionData->rdh.rcBound.bottom = cliplist[index].bottom;
} // end for index
// now we have computed the bounding rectangle region and set up the data
// now let's set the clipping list
ddReturnVal = lpddClipper->SetClipList(regionData, 0); //can also give lpddClipper a hWnd
if (DDFailedCheck(ddReturnVal, "SetClipList() failed", cpErrorBuf ))
{
MessageBox(main_window_handle, cpErrorBuf, "AttachClipper()", MB_ICONEXCLAMATION);
// release memory and return error
free(regionData);
return(NULL);
}
// now attach the clipper to the surface
ddReturnVal = lpddsSurface->SetClipper(lpddClipper);
if (DDFailedCheck(ddReturnVal, "SetClipper() failed", cpErrorBuf ))
{
MessageBox(main_window_handle, cpErrorBuf, "AttachClipper()", MB_ICONEXCLAMATION);
// release memory and return error
free(regionData);
return(NULL);
}
// all is well, so release memory and send back the pointer to the new clipper
free(regionData);
return(lpddClipper);
} // end AttachClipper
示例2: SAFE_RELEASE
HRESULT CTextureHolder::Restore( LPDIRECT3DDEVICE7 pd3dDevice )
{
// Release any previously created objects
SAFE_RELEASE( m_pddsSurface );
// Check params
if( NULL == pd3dDevice )
return DDERR_INVALIDPARAMS;
// Get the device caps
D3DDEVICEDESC7 ddDesc;
if( FAILED( pd3dDevice->GetCaps( &ddDesc) ) )
return E_FAIL;
// Setup the new surface desc
DDSURFACEDESC2 ddsd;
D3DUtil_InitSurfaceDesc( ddsd );
ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|
DDSD_PIXELFORMAT|DDSD_TEXTURESTAGE;
ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
ddsd.dwTextureStage = 0; //m_dwStage;
ddsd.dwWidth = m_dwWidth;
ddsd.dwHeight = m_dwHeight;
// Turn on texture management for hardware devices
if( ddDesc.deviceGUID == IID_IDirect3DHALDevice )
ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
else if( ddDesc.deviceGUID == IID_IDirect3DTnLHalDevice )
ddsd.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
else
ddsd.ddsCaps.dwCaps |= DDSCAPS_SYSTEMMEMORY;
// Adjust width and height to be powers of 2, if the device requires it
if( ddDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_POW2 )
{
for( ddsd.dwWidth=1; m_dwWidth>ddsd.dwWidth; ddsd.dwWidth<<=1 );
for( ddsd.dwHeight=1; m_dwHeight>ddsd.dwHeight; ddsd.dwHeight<<=1 );
}
// Limit max texture sizes, if the driver can't handle large textures
DWORD dwMaxWidth = ddDesc.dwMaxTextureWidth;
DWORD dwMaxHeight = ddDesc.dwMaxTextureHeight;
ddsd.dwWidth = min( ddsd.dwWidth, ( dwMaxWidth ? dwMaxWidth : 256 ) );
ddsd.dwHeight = min( ddsd.dwHeight, ( dwMaxHeight ? dwMaxHeight : 256 ) );
// Make the texture square, if the driver requires it
if( ddDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_SQUAREONLY )
{
if( ddsd.dwWidth > ddsd.dwHeight ) ddsd.dwHeight = ddsd.dwWidth;
else ddsd.dwWidth = ddsd.dwHeight;
}
// Setup the structure to be used for texture enumration.
TEXTURESEARCHINFO tsi;
tsi.bFoundGoodFormat = FALSE;
tsi.pddpf = &ddsd.ddpfPixelFormat;
tsi.dwDesiredBPP = m_dwBPP;
tsi.bUsePalette = ( m_dwBPP <= 8 );
tsi.bUseAlpha = m_bHasMyAlpha;
if( m_dwFlags & D3DTEXTR_16BITSPERPIXEL )
tsi.dwDesiredBPP = 16;
else if( m_dwFlags & D3DTEXTR_32BITSPERPIXEL )
tsi.dwDesiredBPP = 32;
if( m_dwFlags & (D3DTEXTR_TRANSPARENTWHITE|D3DTEXTR_TRANSPARENTBLACK) )
{
if( tsi.bUsePalette )
{
if( ddDesc.dpcTriCaps.dwTextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE )
{
tsi.bUseAlpha = TRUE;
tsi.bUsePalette = TRUE;
}
else
{
tsi.bUseAlpha = TRUE;
tsi.bUsePalette = FALSE;
}
}
}
// Enumerate the texture formats, and find the closest device-supported
// texture pixel format
pd3dDevice->EnumTextureFormats( TextureSearchCallback, &tsi );
// If we couldn't find a format, let's try a default format
if( FALSE == tsi.bFoundGoodFormat )
{
tsi.bUsePalette = FALSE;
tsi.dwDesiredBPP = 16;
pd3dDevice->EnumTextureFormats( TextureSearchCallback, &tsi );
// If we still fail, we cannot create this texture
if( FALSE == tsi.bFoundGoodFormat )
return E_FAIL;
}
// Get the DirectDraw interface for creating surfaces
LPDIRECTDRAW7 pDD;
LPDIRECTDRAWSURFACE7 pddsRender;
//.........这里部分代码省略.........
示例3: CreateDefaultAllocatorPresenter
//-------------------------------------------------------------------------
// InitializeEnvironment
// creates default allocator-presenter and sets D3D environment
//-------------------------------------------------------------------------
HRESULT CMultiSAP::InitializeEnvironment()
{
HRESULT hr;
// m_hMonitor = MonitorFromWindow(m_hwndApp, MONITOR_DEFAULTTOPRIMARY);
hr = CreateDefaultAllocatorPresenter();
if (hr != S_OK)
return hr;
BITMAPINFOHEADER bi =
{
sizeof(BITMAPINFOHEADER), // biSize
640, // biWidth
480, // biHeight
1, // biPlanes
0, // biBitCount
BI_RGB, // biCompression
0, // biSizeImage,
0, // biXpelsPerMeter
0, // biYPelsPerMeter
0, // biClrUsed
0 // biClrImportant
};
VMRALLOCATIONINFO ai =
{
AMAP_3D_TARGET, // dwFlags
&bi, // lpHdr
NULL, // lpPicFmt
{4, 3}, // szAspectRatio
1, // dwMinBuffers
1, // dwMaxBuffers
0, // dwInterlaceFlags
{640, 480} // szNativeSize
};
DWORD dwBuffers = 0;
LPDIRECTDRAWSURFACE7 lpDDSurf;
hr = m_pAlloc->AllocateSurface(0, &ai, &dwBuffers, &lpDDSurf);
if (hr != DD_OK)
return hr;
DDSURFACEDESC2 ddsd = {sizeof(DDSURFACEDESC2)};
hr = lpDDSurf->GetSurfaceDesc(&ddsd);
if (hr != DD_OK) {
return hr;
}
//
// Overlay surfaces have these flags set, we need to remove
// these flags prior to calling GetAttachedSurface
//
ddsd.ddsCaps.dwCaps &= ~(DDSCAPS_FRONTBUFFER | DDSCAPS_VISIBLE);
hr = lpDDSurf->GetAttachedSurface(&ddsd.ddsCaps, &m_lpBackBuffer);
m_lpBackBuffer->GetDDInterface((LPVOID *)&m_lpDDObj);
//
// get the h/w caps for this device
//
INITDDSTRUCT(m_ddHWCaps);
m_lpDDObj->GetCaps(&m_ddHWCaps, NULL);
//
// Create the device. The device is created off of our back buffer, which
// becomes the render target for the newly created device. Note that the
// z-buffer must be created BEFORE the device
//
m_pD3DHelper = new CD3DHelper(m_lpBackBuffer, &hr);
if(m_pD3DHelper == NULL || hr != DD_OK)
{
if(m_pD3DHelper == NULL)
{
hr = E_OUTOFMEMORY;
}
delete m_pD3DHelper;
}
SetRect(&m_rcDst, 0, 0, 640, 480);
#ifdef SPARKLE
m_pSparkle = new CSparkle(m_lpDDObj);
if (m_pSparkle)
m_pSparkle->InitializeSparkle();
#endif
return hr;
}
示例4: INITDDSTRUCT
/******************************Public*Routine******************************\
* PresentImage
*
\**************************************************************************/
STDMETHODIMP
CMpegMovie::PresentImage(
DWORD_PTR dwUserID,
VMRPRESENTATIONINFO* lpPresInfo
)
{
#if 0
LPDIRECTDRAWSURFACE7 lpSurface = lpPresInfo->lpSurf;
const REFERENCE_TIME rtNow = lpPresInfo->rtStart;
const DWORD dwSurfaceFlags = lpPresInfo->dwFlags;
if(m_iDuration > 0)
{
HRESULT hr;
RECT rs, rd;
DDSURFACEDESC2 ddsdV;
INITDDSTRUCT(ddsdV);
hr = lpSurface->GetSurfaceDesc(&ddsdV);
DDSURFACEDESC2 ddsdP;
INITDDSTRUCT(ddsdP);
hr = m_pddsPriText->GetSurfaceDesc(&ddsdP);
FLOAT fPos = (FLOAT)m_iDuration / 30.0F;
FLOAT fPosInv = 1.0F - fPos;
SetRect(&rs, 0, 0,
MulDiv((int)ddsdV.dwWidth, 30 - m_iDuration, 30),
ddsdV.dwHeight);
SetRect(&rd, 0, 0,
MulDiv((int)ddsdP.dwWidth, 30 - m_iDuration, 30),
ddsdP.dwHeight);
hr = m_pddsRenderT->Blt(&rd, lpSurface,
&rs, DDBLT_WAIT, NULL);
SetRect(&rs, 0, 0,
MulDiv((int)ddsdP.dwWidth, m_iDuration, 30),
ddsdP.dwHeight);
SetRect(&rd,
(int)ddsdP.dwWidth - MulDiv((int)ddsdP.dwWidth, m_iDuration, 30),
0,
ddsdP.dwWidth,
ddsdP.dwHeight);
hr = m_pddsRenderT->Blt(&rd, m_pddsPriText,
&rs, DDBLT_WAIT, NULL);
//
// need to wait for VBlank before blt-ing
//
{
LPDIRECTDRAW lpdd;
hr = m_pddsPrimary->GetDDInterface((LPVOID*)&lpdd);
if(SUCCEEDED(hr))
{
DWORD dwScanLine;
for(; ;)
{
hr = lpdd->GetScanLine(&dwScanLine);
if(hr == DDERR_VERTICALBLANKINPROGRESS)
{
break;
}
if(FAILED(hr))
{
break;
}
if((LONG)dwScanLine>= rd.top)
{
if((LONG)dwScanLine <= rd.bottom)
{
continue;
}
}
break;
}
RELEASE(lpdd);
}
}
hr = m_pddsPrimary->Blt(NULL, m_pddsRenderT,
NULL, DDBLT_WAIT, NULL);
m_iDuration--;
if(m_iDuration == 0 && (ddsdV.ddsCaps.dwCaps & DDSCAPS_OVERLAY))
{
// need to get the color key visible again.
//.........这里部分代码省略.........
示例5: vdraw_ddraw_flip
/**
* 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))
//.........这里部分代码省略.........
示例6: vdraw_ddraw_draw_text
static inline void WINAPI vdraw_ddraw_draw_text(DDSURFACEDESC2* pddsd, LPDIRECTDRAWSURFACE7 lpDDS_Surface, const BOOL lock)
{
if (lock)
lpDDS_Surface->Lock(NULL, pddsd, DDLOCK_WAIT, NULL);
// Determine the window size using the scaling factor.
const int curHPix = vdp_getHPix();
// +(8*bytespp) is needed for the lpSurface pointer because the DDraw module
// includes the entire 336x240 MD_Screen. The first 8 pixels are offscreen,
// so they won't show up at all.
uint8_t bytespp = (bppOut == 15 ? 2 : bppOut / 8);
// NOTE: fullW must be (pddsd->lPitch / bytespp).
// DirectDraw likes to use absurdly large line lengths in full screen mode.
// (pddsd->lPitch / bytespp) does match pddsd->dwWidth in windowed mode, though.
uint8_t *start = (uint8_t*)pddsd->lpSurface;
int msg_height;
int msg_width;
if (vdraw_ddraw_is_hw_render())
{
// Hardware rendering uses 1x internally.
msg_height = VDP_Lines.Visible.Total;
msg_width = curHPix;
start += (pddsd->lPitch * VDP_Lines.Visible.Border_Size);
if (curHPix < 320)
start += (vdp_getHPixBegin() * bytespp);
// DirectDraw's hardware rendering uses MD_Screen / MD_Screen32 directly.
// Thus, it has an invisible 8px column at the beginning.
start += (8 * bytespp);
}
else
{
// Software rendering.
msg_height = VDP_Lines.Visible.Total * vdraw_scale;
msg_width = curHPix * vdraw_scale;
start += (pddsd->lPitch * (VDP_Lines.Visible.Border_Size * vdraw_scale));
if (curHPix < 320)
start += (vdp_getHPixBegin() * vdraw_scale * bytespp);
}
if (vdraw_msg_visible)
{
// Message is visible.
draw_text(start, pddsd->lPitch / bytespp,
msg_width, msg_height,
vdraw_msg_text, &vdraw_msg_style);
}
else if (vdraw_fps_enabled && (Game != NULL) && Settings.Active && !Settings.Paused && !IS_DEBUGGING())
{
// FPS is enabled.
draw_text(start, pddsd->lPitch / bytespp,
msg_width, msg_height,
vdraw_msg_text, &vdraw_fps_style);
}
if (lock)
lpDDS_Surface->Unlock(NULL);
}
示例7: GetObject
HRESULT CTextureHolder::CopyBitmapToSurface(){
// Get a DDraw object to create a temporary surface
LPDIRECTDRAW7 pDD;
m_pddsSurface->GetDDInterface( (VOID**)&pDD );
// Get the bitmap structure (to extract width, height, and bpp)
BITMAP bm;
GetObject( m_hbmBitmap, sizeof(BITMAP), &bm );
// Setup the new surface desc
DDSURFACEDESC2 ddsd;
ddsd.dwSize = sizeof(ddsd);
m_pddsSurface->GetSurfaceDesc( &ddsd );
ddsd.dwFlags = DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH|DDSD_PIXELFORMAT|
DDSD_TEXTURESTAGE;
ddsd.ddsCaps.dwCaps = DDSCAPS_TEXTURE|DDSCAPS_SYSTEMMEMORY;
ddsd.ddsCaps.dwCaps2 = 0L;
ddsd.dwWidth = bm.bmWidth;
ddsd.dwHeight = bm.bmHeight;
// Create a new surface for the texture
LPDIRECTDRAWSURFACE7 pddsTempSurface;
HRESULT hr;
if( FAILED( hr = pDD->CreateSurface( &ddsd, &pddsTempSurface, NULL ) ) )
{
pDD->Release();
return hr;
}
// Get a DC for the bitmap
HDC hdcBitmap = CreateCompatibleDC( NULL );
if( NULL == hdcBitmap )
{
pddsTempSurface->Release();
pDD->Release();
return hr; // bug? return E_FAIL?
}
SelectObject( hdcBitmap, m_hbmBitmap );
// Handle palettized textures. Need to attach a palette
if( ddsd.ddpfPixelFormat.dwRGBBitCount == 8 )
{
LPDIRECTDRAWPALETTE pPalette;
DWORD dwPaletteFlags = DDPCAPS_8BIT|DDPCAPS_ALLOW256;
DWORD pe[256];
WORD wNumColors = GetDIBColorTable( hdcBitmap, 0, 256, (RGBQUAD*)pe );
// Create the color table
for( WORD i=0; i<wNumColors; i++ )
{
pe[i] = RGB( GetBValue(pe[i]), GetGValue(pe[i]), GetRValue(pe[i]) );
// Handle textures with transparent pixels
if( m_dwFlags & (D3DTEXTR_TRANSPARENTWHITE|D3DTEXTR_TRANSPARENTBLACK) )
{
// Set alpha for opaque pixels
if( m_dwFlags & D3DTEXTR_TRANSPARENTBLACK )
{
if( pe[i] != 0x00000000 )
pe[i] |= 0xff000000;
}
else if( m_dwFlags & D3DTEXTR_TRANSPARENTWHITE )
{
if( pe[i] != 0x00ffffff )
pe[i] |= 0xff000000;
}
}
}
// Add DDPCAPS_ALPHA flag for textures with transparent pixels
if( m_dwFlags & (D3DTEXTR_TRANSPARENTWHITE|D3DTEXTR_TRANSPARENTBLACK) )
dwPaletteFlags |= DDPCAPS_ALPHA;
// Create & attach a palette
pDD->CreatePalette( dwPaletteFlags, (PALETTEENTRY*)pe, &pPalette, NULL );
pddsTempSurface->SetPalette( pPalette );
m_pddsSurface->SetPalette( pPalette );
SAFE_RELEASE( pPalette );
}
// Copy the bitmap image to the surface.
HDC hdcSurface;
if( SUCCEEDED( pddsTempSurface->GetDC( &hdcSurface ) ) )
{
BitBlt( hdcSurface, 0, 0, bm.bmWidth, bm.bmHeight, hdcBitmap, 0, 0,
SRCCOPY );
pddsTempSurface->ReleaseDC( hdcSurface );
}
DeleteDC( hdcBitmap );
// Copy the temp surface to the real texture surface
m_pddsSurface->Blt( NULL, pddsTempSurface, NULL, DDBLT_WAIT, NULL );
// Done with the temp surface
pddsTempSurface->Release();
// For textures with real alpha (not palettized), set transparent bits
if( ddsd.ddpfPixelFormat.dwRGBAlphaBitMask )
{
if( m_dwFlags & (D3DTEXTR_TRANSPARENTWHITE|D3DTEXTR_TRANSPARENTBLACK) )
//.........这里部分代码省略.........
示例8: getFrontSurface
// set frontSurface to lpDDSurface if lpDDSurface is primary
// returns true if frontSurface is set
// returns false if frontSurface is NULL and lpDDSurface is not primary
bool getFrontSurface(LPDIRECTDRAWSURFACE7 lpDDSurface)
{
//logOutput << CurrentTimeString() << "called getFrontSurface" << endl;
if (!lpDDSurface)
{
//logOutput << CurrentTimeString() << "lpDDSurface null" << endl;
return false;
}
if (!g_ddInterface)
{
LPDIRECTDRAWSURFACE7 dummy;
if (lpDDSurface->QueryInterface(IID_IDirectDrawSurface7, (LPVOID*)&dummy) == S_OK)
{
IUnknown* Unknown;
HRESULT err;
if (FAILED(err = dummy->GetDDInterface((LPVOID*)&Unknown)))
{
logOutput << CurrentTimeString() << "getFrontSurface: could not get DirectDraw interface" << endl;
printDDrawError(err, "getFrontSurface");
}
else
{
if (Unknown->QueryInterface(IID_IDirectDraw7, (LPVOID*)&g_ddInterface) == S_OK)
{
logOutput << CurrentTimeString() << "Got DirectDraw interface pointer" << endl;
}
else
{
logOutput << CurrentTimeString() << "Query of DirectDraw interface failed" << endl;
}
}
ddrawSurfaceRelease.Unhook();
dummy->Release();
ddrawSurfaceRelease.Rehook();
}
}
if (!bTargetAcquired)
{
DDSCAPS2 caps;
if (SUCCEEDED(lpDDSurface->GetCaps(&caps)))
{
//logOutput << CurrentTimeString() << "checking if surface is primary" << endl;
if (caps.dwCaps & DDSCAPS_PRIMARYSURFACE)
{
logOutput << CurrentTimeString() << "found primary surface" << endl;
g_frontSurface = lpDDSurface;
if (!SetupDDraw())
{
return false;
}
else
{
bTargetAcquired = true;
}
}
}
else
{
logOutput << CurrentTimeString() << "could not retrieve caps" << endl;
}
}
return lpDDSurface == g_frontSurface;
}
示例9: DD_Attach_Clipper
LPDIRECTDRAWCLIPPER DD_Attach_Clipper(LPDIRECTDRAWSURFACE7 lpdds,
int num_rects,
LPRECT clip_list)
{
// this function creates a clipper from the sent clip list and attaches
// it to the sent surface
int index; // looping var
LPDIRECTDRAWCLIPPER lpddclipper; // pointer to the newly created dd clipper
LPRGNDATA region_data; // pointer to the region data that contains
// the header and clip list
// first create the direct draw clipper
if ((lpdd->CreateClipper(0,&lpddclipper,NULL))!=DD_OK)
return(NULL);
// now create the clip list from the sent data
// first allocate memory for region data
region_data = (LPRGNDATA)malloc(sizeof(RGNDATAHEADER)+num_rects*sizeof(RECT));
// now copy the rects into region data
memcpy(region_data->Buffer, clip_list, sizeof(RECT)*num_rects);
// set up fields of header
region_data->rdh.dwSize = sizeof(RGNDATAHEADER);
region_data->rdh.iType = RDH_RECTANGLES;
region_data->rdh.nCount = num_rects;
region_data->rdh.nRgnSize = num_rects*sizeof(RECT);
region_data->rdh.rcBound.left = 64000;
region_data->rdh.rcBound.top = 64000;
region_data->rdh.rcBound.right = -64000;
region_data->rdh.rcBound.bottom = -64000;
// find bounds of all clipping regions
for (index=0; index<num_rects; index++)
{
// test if the next rectangle unioned with the current bound is larger
if (clip_list[index].left < region_data->rdh.rcBound.left)
region_data->rdh.rcBound.left = clip_list[index].left;
if (clip_list[index].right > region_data->rdh.rcBound.right)
region_data->rdh.rcBound.right = clip_list[index].right;
if (clip_list[index].top < region_data->rdh.rcBound.top)
region_data->rdh.rcBound.top = clip_list[index].top;
if (clip_list[index].bottom > region_data->rdh.rcBound.bottom)
region_data->rdh.rcBound.bottom = clip_list[index].bottom;
} // end for index
// now we have computed the bounding rectangle region and set up the data
// now let's set the clipping list
if ((lpddclipper->SetClipList(region_data, 0))!=DD_OK)
{
// release memory and return error
free(region_data);
return(NULL);
} // end if
// now attach the clipper to the surface
if ((lpdds->SetClipper(lpddclipper))!=DD_OK)
{
// release memory and return error
free(region_data);
return(NULL);
} // end if
// all is well, so release memory and send back the pointer to the new clipper
free(region_data);
return(lpddclipper);
} // end DD_Attach_Clipper
示例10: SetupDDraw
bool SetupDDraw()
{
logOutput << CurrentTimeString() << "called SetupDDraw()" << endl;
if (!g_ddInterface)
{
logOutput << CurrentTimeString() << "SetupDDraw: DirectDraw interface not set, returning" << endl;
return false;
}
bool bSuccess = true;
bKillThread = false;
if (hCopyThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)CopyDDrawTextureThread, NULL, 0, NULL))
{
if (!(hCopyEvent = CreateEvent(NULL, FALSE, FALSE, NULL)))
{
logOutput << CurrentTimeString() << "SetupDDraw: CreateEvent failed, GetLastError = " << GetLastError() << endl;
bSuccess = false;
}
}
else
{
logOutput << CurrentTimeString() << "SetupDDraw: CreateThread failed, GetLastError = " << GetLastError() << endl;
bSuccess = false;
}
if (bSuccess)
{
if (!ddUnlockFctMutex)
{
ddUnlockFctMutex = CreateMutex(NULL, FALSE, mutexName);
if (!ddUnlockFctMutex)
{
RUNEVERYRESET logOutput << CurrentTimeString() << "SetupDDraw: CreateMutex failed, GetLastError = " << GetLastError() << endl;
bSuccess = false;
}
}
}
if (bSuccess && !g_frontSurface)
{
RUNEVERYRESET logOutput << "SetupDDraw: frontSurface and surface descriptor not set, returning" << endl;
CleanUpDDraw();
return false;
}
else if (bSuccess)
{
LPDIRECTDRAWPALETTE palette = NULL;
HRESULT err;
if (SUCCEEDED(err = g_frontSurface->GetPalette(&palette)))
{
if (palette)
SetupPalette(palette);
}
else if (err == DDERR_NOPALETTEATTACHED)
{
//logOutput << CurrentTimeString() << "No palette attached to primary surface" << endl;
}
else
{
logOutput << CurrentTimeString() << "Error retrieving palette" << endl;
printDDrawError(err, "getFrontSurface");
}
}
if (bSuccess && !g_surfaceDesc)
{
logOutput << CurrentTimeString() << "SetupDDraw: no surface descriptor found, creating a new one (not an error)" << endl;
g_surfaceDesc = new DDSURFACEDESC2;
g_surfaceDesc->dwSize = sizeof(DDSURFACEDESC);
HRESULT hr;
if (FAILED(hr = ((LPDIRECTDRAWSURFACE)g_frontSurface)->GetSurfaceDesc((LPDDSURFACEDESC)g_surfaceDesc)))
{
g_surfaceDesc->dwSize = sizeof(DDSURFACEDESC2);
if (FAILED(g_frontSurface->GetSurfaceDesc(g_surfaceDesc)))
{
logOutput << CurrentTimeString() << "SetupDDraw: error getting surface descriptor" << endl;
printDDrawError(hr, "SetupDDraw");
bSuccess = false;
}
}
}
if (bSuccess && g_surfaceDesc)
{
const DDPIXELFORMAT& pf = g_surfaceDesc->ddpfPixelFormat;
if (pf.dwFlags & DDPF_RGB)
{
if (pf.dwRGBBitCount == 16)
{
logOutput << CurrentTimeString() << "SetupDDraw: found 16bit format (using R5G6B5 conversion)" << endl;
g_bConvert16to32 = true;
}
else if (pf.dwRGBBitCount == 32)
{
logOutput << CurrentTimeString() << "SetupDDraw: found 32bit format (using plain copy)" << endl;
//.........这里部分代码省略.........
示例11: Game_Init
int Game_Init(void *parms = NULL, int num_parms = 0)
{
// this is called once after the initial window is created and
// before the main event loop is entered, do all your initialization
// here
// create IDirectDraw interface 7.0 object and test for error
if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)))
return(0);
// set cooperation to full screen
if (FAILED(lpdd->SetCooperativeLevel(main_window_handle,
DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX |
DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
return(0);
// set display mode
if (FAILED(lpdd->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,0,0)))
return(0);
// clear ddsd and set size
DDRAW_INIT_STRUCT(ddsd);
// enable valid fields
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
// set the backbuffer count field to 1, use 2 for triple buffering
ddsd.dwBackBufferCount = 1;
// request a complex, flippable
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
// create the primary surface
if (FAILED(lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL)))
return(0);
// now query for attached surface from the primary surface
// this line is needed by the call
ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
// get the attached back buffer surface
if (FAILED(lpddsprimary->GetAttachedSurface(&ddsd.ddsCaps, &lpddsback)))
return(0);
// build up the palette data array
for (int color=1; color < 255; color++)
{
// fill with random RGB values
palette[color].peRed = rand()%256;
palette[color].peGreen = rand()%256;
palette[color].peBlue = rand()%256;
// set flags field to PC_NOCOLLAPSE
palette[color].peFlags = PC_NOCOLLAPSE;
} // end for color
// now fill in entry 0 and 255 with black and white
palette[0].peRed = 0;
palette[0].peGreen = 0;
palette[0].peBlue = 0;
palette[0].peFlags = PC_NOCOLLAPSE;
palette[255].peRed = 255;
palette[255].peGreen = 255;
palette[255].peBlue = 255;
palette[255].peFlags = PC_NOCOLLAPSE;
// make color 1 yellow
palette[1].peRed = 255;
palette[1].peGreen = 255;
palette[1].peBlue = 0;
palette[1].peFlags = PC_NOCOLLAPSE;
// create the palette object
if (FAILED(lpdd->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 |
DDPCAPS_INITIALIZE,
palette,&lpddpal, NULL)))
return(0);
// finally attach the palette to the primary surface
if (FAILED(lpddsprimary->SetPalette(lpddpal)))
return(0);
// initialize all the happy faces
for (int face = 0; face < 100; face++)
{
// set random position
happy_faces[face].x = rand()%SCREEN_WIDTH;
happy_faces[face].y = rand()%SCREEN_HEIGHT;
// set random velocity (-2,+2)
happy_faces[face].xv = -2 + rand()%5;
happy_faces[face].yv = -2 + rand()%5;
} // end for face
// return success or failure or your own return code here
return(1);
//.........这里部分代码省略.........
示例12: CreateWindowedDisplay
static HRESULT CreateWindowedDisplay(HWND hWnd, DWORD dwWidth, DWORD dwHeight)
{
// Set cooperative level
if (FAILED(lpdd->SetCooperativeLevel(hWnd, DDSCL_NORMAL)))
{
return E_FAIL;
}
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 = GetWindowLong(hWnd, GWL_STYLE);
dwStyle &= ~WS_POPUP;
dwStyle |= WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
SetWindowLong(hWnd, GWL_STYLE, dwStyle);
// Adapt window size
SetRect(&rc, 0, 0, dwWidth, dwHeight);
AdjustWindowRectEx(&rc, GetWindowStyle(hWnd), GetMenu(hWnd) != NULL, GetWindowExStyle(hWnd));
SetWindowPos(hWnd, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
SetWindowPos(hWnd, 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(hWnd, &rc);
if (rc.left < rcWork.left) rc.left = rcWork.left;
if (rc.top < rcWork.top) rc.top = rcWork.top;
SetWindowPos(hWnd, NULL, rc.left, rc.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
// Create the primary surface
DDSURFACEDESC2 ddsd;
DDRAW_INIT_STRUCT(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
if (FAILED(lpdd->CreateSurface(&ddsd, &lpddsMain, NULL)))
{
return E_FAIL;
}
// Create the backbuffer surface
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_CKSRCBLT;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
ddsd.dwWidth = dwWidth;
ddsd.dwHeight = dwHeight;
if (FAILED(lpdd->CreateSurface(&ddsd, &lpddsBack, NULL)))
{
return E_FAIL;
}
// Set surface color key
DDCOLORKEY ddCK;
ddCK.dwColorSpaceLowValue = 0;
ddCK.dwColorSpaceHighValue = 0;
if (lpddsBack->SetColorKey(DDCKEY_SRCBLT, &ddCK))
{
return E_FAIL;
}
// Create clipper for the primary surface
LPDIRECTDRAWCLIPPER lpClipper;
if (FAILED(lpdd->CreateClipper(0, &lpClipper, NULL)))
{
return E_FAIL;
}
if (FAILED(lpClipper->SetHWnd(0, hWnd)))
{
lpClipper->Release();
return E_FAIL;
}
if (FAILED(lpddsMain->SetClipper(lpClipper)))
{
lpClipper->Release();
return E_FAIL;
}
lpClipper->Release();
lpClipper = NULL;
// Update window flag
SetClassLong(hWnd, GCL_HICONSM, (LONG)LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICONSM)));
SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LONG)LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICONSM)));
UpdateWindow(hWnd);
return S_OK;
}
示例13: Game_Main
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
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
// copy background to back buffer
DDraw_Draw_Surface(lpddsbackground,0,0, SCREEN_WIDTH,SCREEN_HEIGHT, lpddsback,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;
// 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
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++)
{
// draw objects
DDraw_Draw_Surface(aliens[index].frames[animation_seq[aliens[index].current_frame]],
aliens[index].x, aliens[index].y,
72,80,
lpddsback);
} // end for index
// flip 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
示例14: Game_Init
int Game_Init(void *parms = NULL, int num_parms = 0)
{
// this is called once after the initial window is created and
// before the main event loop is entered, do all your initialization
// here
// create IDirectDraw interface 7.0 object and test for error
if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)))
return(0);
// set cooperation to full screen
if (FAILED(lpdd->SetCooperativeLevel(main_window_handle,
DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX |
DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)))
return(0);
// set display mode to 640x480x8
if (FAILED(lpdd->SetDisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP,0,0)))
return(0);
// we need a complex surface system with a primary and backbuffer
// clear ddsd and set size
DDRAW_INIT_STRUCT(ddsd);
// enable valid fields
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
// set the backbuffer count field to 1, use 2 for triple buffering
ddsd.dwBackBufferCount = 1;
// request a complex, flippable
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
// create the primary surface
if (FAILED(lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL)))
return(0);
// now query for attached surface from the primary surface
// this line is needed by the call
ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
// get the attached back buffer surface
if (FAILED(lpddsprimary->GetAttachedSurface(&ddsd.ddsCaps, &lpddsback)))
return(0);
// build up the palette data array
for (int color=1; color < 255; color++)
{
// fill with random RGB values
palette[color].peRed = rand()%256;
palette[color].peGreen = rand()%256;
palette[color].peBlue = rand()%256;
// set flags field to PC_NOCOLLAPSE
palette[color].peFlags = PC_NOCOLLAPSE;
} // end for color
// now fill in entry 0 and 255 with black and white
palette[0].peRed = 0;
palette[0].peGreen = 0;
palette[0].peBlue = 0;
palette[0].peFlags = PC_NOCOLLAPSE;
palette[255].peRed = 255;
palette[255].peGreen = 255;
palette[255].peBlue = 255;
palette[255].peFlags = PC_NOCOLLAPSE;
// create the palette object
if (FAILED(lpdd->CreatePalette(DDPCAPS_8BIT | DDPCAPS_ALLOW256 |
DDPCAPS_INITIALIZE,
palette,&lpddpal, NULL)))
return(0);
// finally attach the palette to the primary surface
if (FAILED(lpddsprimary->SetPalette(lpddpal)))
return(0);
// set clipper up on back buffer since that's where well clip
RECT screen_rect= {0,0,SCREEN_WIDTH-1,SCREEN_HEIGHT-1};
lpddclipper = DDraw_Attach_Clipper(lpddsback,1,&screen_rect);
// load the 8-bit image
if (!Load_Bitmap_File(&bitmap,"alley8.bmp"))
return(0);
// load it's palette into directdraw
if (FAILED(lpddpal->SetEntries(0,0,MAX_COLORS_PALETTE,bitmap.palette)))
return(0);
// clean the surfaces
DDraw_Fill_Surface(lpddsprimary,0);
DDraw_Fill_Surface(lpddsback,0);
// create the buffer to hold the background
lpddsbackground = DDraw_Create_Surface(640,480,0,-1);
// copy the background bitmap image to the background surface
//.........这里部分代码省略.........
示例15: vdraw_ddraw_clear_primary_screen
/**
* 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;
}