本文整理汇总了C++中LPDIRECTDRAWSURFACE7::Lock方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTDRAWSURFACE7::Lock方法的具体用法?C++ LPDIRECTDRAWSURFACE7::Lock怎么用?C++ LPDIRECTDRAWSURFACE7::Lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECTDRAWSURFACE7
的用法示例。
在下文中一共展示了LPDIRECTDRAWSURFACE7::Lock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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
// 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 the bitmap image to the primary buffer line by line
// notice the 24 to 16 bit conversion pixel by pixel
// lock the primary surface
lpddsprimary->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL);
// get video pointer to primary surfce
USHORT *primary_buffer = (USHORT *)ddsd.lpSurface;
// process each line and copy it into the primary buffer
for (int index_y = 0; index_y < SCREEN_HEIGHT; index_y++)
{
for (int index_x = 0; index_x < SCREEN_WIDTH; index_x++)
{
// get BGR values, note the scaling down of the channels, so that they
// fit into the 5.6.5 format
UCHAR blue = (bitmap.buffer[index_y*SCREEN_WIDTH*3 + index_x*3 + 0]) >> 3,
green = (bitmap.buffer[index_y*SCREEN_WIDTH*3 + index_x*3 + 1]) >> 3,
red = (bitmap.buffer[index_y*SCREEN_WIDTH*3 + index_x*3 + 2]) >> 3;
// this builds a 16 bit color value in 5.6.5 format (green dominant mode)
USHORT pixel = _RGB16BIT565(red,green,blue);
// write the pixel
primary_buffer[index_x + (index_y*ddsd.lPitch >> 1)] = pixel;
} // end for index_x
} // end for index_y
// now unlock the primary surface
if (FAILED(lpddsprimary->Unlock(NULL)))
return(0);
// do nothing -- look at pretty picture
// return success or failure or your own return code here
return(1);
} // end Game_Main
示例2: 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
// 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
// clear out the back buffer
DDraw_Fill_Surface(lpddsback, 0);
// lock primary buffer
DDRAW_INIT_STRUCT(ddsd);
if (FAILED(lpddsback->Lock(NULL,&ddsd,
DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,
NULL)))
return(0);
// do the graphics
Draw_Polygon2D(&asteroid, (UCHAR *)ddsd.lpSurface, ddsd.lPitch);
// test for scale
if (KEYDOWN('A')) // scale up
Scale_Polygon2D(&asteroid, 1.1, 1.1);
else
if (KEYDOWN('S')) // scale down
Scale_Polygon2D(&asteroid, 0.9, 0.9);
// rotate the polygon by 5 degrees
Rotate_Polygon2D(&asteroid, 5);
// unlock primary buffer
if (FAILED(lpddsback->Unlock(NULL)))
return(0);
// perform the flip
while (FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT)));
// wait a sec
Sleep(33);
// return success or failure or your own return code here
return(1);
} // end Game_Main
示例3: Lock
//-----------------------------------------------------------------------------
// Name: Lock()
// Desc: Fucntion to lock the entire surface
//-----------------------------------------------------------------------------
int Lock(LPDIRECTDRAWSURFACE7 lpddsSurface)
{
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddReturnVal = lpddsSurface->Lock(NULL,&ddsd,DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL);
if (DDFailedCheck(ddReturnVal, "Lock(), failed", cpErrorBuf ))
{ MessageBox(main_window_handle, cpErrorBuf, "SurfaceFuncs, Lock()", MB_ICONEXCLAMATION); return(0); }
return (1);
}
示例4: Scan_Image_Bitmap
int Scan_Image_Bitmap(BITMAP_FILE_PTR bitmap, // bitmap file to scan image data from
LPDIRECTDRAWSURFACE7 lpdds, // surface to hold data
int cx, int cy) // cell to scan image from
{
// this function extracts a bitmap out of a bitmap file
UCHAR *source_ptr, // working pointers
*dest_ptr;
DDSURFACEDESC2 ddsd; // direct draw surface description
// get the addr to destination surface memory
// set size of the structure
ddsd.dwSize = sizeof(ddsd);
// lock the display surface
lpdds->Lock(NULL,
&ddsd,
DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,
NULL);
// compute position to start scanning bits from
cx = cx*(ddsd.dwWidth+1) + 1;
cy = cy*(ddsd.dwHeight+1) + 1;
gwidth = ddsd.dwWidth;
gheight = ddsd.dwHeight;
// extract bitmap data
source_ptr = bitmap->buffer + cy*bitmap->bitmapinfoheader.biWidth+cx;
// assign a pointer to the memory surface for manipulation
dest_ptr = (UCHAR *)ddsd.lpSurface;
// iterate thru each scanline and copy bitmap
for (int index_y=0; index_y < ddsd.dwHeight; index_y++)
{
// copy next line of data to destination
memcpy(dest_ptr, source_ptr, ddsd.dwWidth);
// advance pointers
dest_ptr += (ddsd.lPitch);
source_ptr += bitmap->bitmapinfoheader.biWidth;
} // end for index_y
// unlock the surface
lpdds->Unlock(NULL);
// return success
return(1);
} // end Scan_Image_Bitmap
示例5: Bmp2Surface
int Bmp2Surface(LPDIRECTDRAWSURFACE7 lpdds, int SurfaceWidth, int SurfaceHeight)
{
// copy the bitmap image to the lpddsback buffer line by line
// notice the 24 to 32 bit conversion pixel by pixel
// 一个像素一个像素的逐粒拷贝至表面
// lock the lpddsback surface
lpdds->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL);
// get video pointer to primary surfce
DWORD *back_buffer = (DWORD *)ddsd.lpSurface;
// process each line and copy it into the lpddsback buffer
if (ddsd.lPitch == SurfaceWidth)
{
// copy memory from double buffer to lpddsback buffer
memcpy((void *)back_buffer, (void *)bitmap.buffer, SurfaceWidth*SurfaceHeight);
}
else
{
for (int index_y = 0; index_y < SurfaceHeight; index_y++)
{
for (int index_x = 0; index_x < SurfaceWidth; index_x++)
{
// get BGR values
UCHAR blue = (bitmap.buffer[index_y*SurfaceWidth*3 + index_x*3 + 0]),
green = (bitmap.buffer[index_y*SurfaceWidth*3 + index_x*3 + 1]),
red = (bitmap.buffer[index_y*SurfaceWidth*3 + index_x*3 + 2]);
// this builds a 32 bit color value in A.8.8.8 format (8-bit alpha mode)
DWORD pixel = _RGB32BIT(0,red,green,blue);
// write the pixel
back_buffer[index_x + (index_y*ddsd.lPitch >> 2)] = pixel;
} // end for index_x
} // end for index_y
}
// now unlock the lpddsback surface
if (FAILED(lpdds->Unlock(NULL)))
return(0);
} // end Bmp2Surface
示例6: GameDisplayLoop
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;
}
示例7: 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
// 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
// lock primary buffer
DDRAW_INIT_STRUCT(ddsd);
if (FAILED(lpddsprimary->Lock(NULL,&ddsd,
DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,
NULL)))
return(0);
// draw 1000 random lines
for (int index=0; index < 1000; index++)
{
Draw_Line(rand()%SCREEN_WIDTH, rand()%SCREEN_HEIGHT,
rand()%SCREEN_WIDTH, rand()%SCREEN_HEIGHT,
rand()%256,
(UCHAR *)ddsd.lpSurface, ddsd.lPitch);
} // end for index
// unlock primary buffer
if (FAILED(lpddsprimary->Unlock(NULL)))
return(0);
// wait a sec
Sleep(33);
// return success or failure or your own return code here
return(1);
} // end Game_Main
示例8: dx_AccessMemoire
//-----------------------------------------------------------------------------
// Name: dx_AccessMemoire(...)
// Desc: Vérouille/déverouille l'accès à la mémoire vidéo
//-----------------------------------------------------------------------------
bool dx_AccessMemoire (bool pVerrou)
{
if (pVerrou)
{
SurfaceBack->Lock (NULL, &SurfaceDesc, DDLOCK_WAIT, NULL);
Pitch = (int)SurfaceDesc.lPitch;
Ecran = (BVRA*)SurfaceDesc.lpSurface;
}
else
{
SurfaceBack->Unlock (NULL);
Pitch = 0;
Ecran = NULL;
}
return dx_Test ();
}
示例9: DrawOverlay
//! Load the bitmap and copy it to the overlay surface
bool DrawOverlay()
{
HRESULT hRet; // This is where we put return values from DirectDraw.
DDSURFACEDESC2 surfDesc;
// Setup structure
memset(&surfDesc, 0, sizeof(surfDesc)); surfDesc.dwSize = sizeof(surfDesc);
hRet = g_pDDSOverlay->Lock(NULL, &surfDesc, DDLOCK_SURFACEMEMORYPTR | DDLOCK_NOSYSLOCK | DDLOCK_WRITEONLY, NULL);
if (hRet != DD_OK || surfDesc.lpSurface == NULL)
return DisplayError("Can't lock overlay surface", hRet);
else {
g_pImg = (unsigned int *)surfDesc.lpSurface;
//g_pDDSOverlay->Unlock(NULL); is not needed?
}
// Setup effects structure
memset(&g_OverlayFX, 0, sizeof(g_OverlayFX)); g_OverlayFX.dwSize = sizeof(g_OverlayFX);
// Setup overlay flags.
g_OverlayFlags = DDOVER_SHOW;
// Check for destination color keying capability
if ((g_DDCaps.dwCKeyCaps & DDCKEYCAPS_DESTOVERLAY) && ((g_DDCaps.dwCaps & DDCAPS_OVERLAYCANTCLIP) || (g_DDCaps.dwCKeyCaps & DDCKEYCAPS_NOCOSTOVERLAY) ))
{
// If so, we'll use it to clip the bitmap when other windows go on top
// of us. Just for the record - this color range for color keying (the
// high/low values) are not heavily supported right now, so for almost
// all cards, just use the same color for both.
g_OverlayFX.dckDestColorkey.dwColorSpaceLowValue =
g_OverlayFX.dckDestColorkey.dwColorSpaceHighValue = DDColorMatch(g_pDDSPrimary, RGBKEY);
g_OverlayFlags |= DDOVER_DDFX | DDOVER_KEYDESTOVERRIDE;
} else {
// If not, we'll setup a clipper for the window. This will fix the
// problem on a few video cards - but the ones that don't shouldn't care.
hRet = g_pDD->CreateClipper(0, &g_pClipper, NULL);
if (hRet != DD_OK)
return DisplayError("Can't create clipper", hRet);
hRet = g_pClipper->SetHWnd(0, g_hAppWnd);
if (hRet != DD_OK)
return DisplayError("Can't attach clipper", hRet);
hRet = g_pDDSPrimary->SetClipper(g_pClipper);
if (hRet != DD_OK)
return DisplayError("Can't set clipper", hRet);
}
return true;
}
示例10: DDAccurateUpdateDisplay
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;
}
示例11: DDAccurateInit
//.........这里部分代码省略.........
OrigW=Form1->ClientWidth;
OrigH=Form1->ClientHeight;
if (Form1->StatusBar1->Visible) OrigH -= Form1->StatusBar1->Height;
if (Form1->BaseWidth==0) Form1->BaseWidth= NoWinR-NoWinL;
if (Form1->BaseHeight==0) Form1->BaseHeight= NoWinT-NoWinB;
ScaleW = OrigW / Form1->BaseWidth;
ScaleH = OrigH / Form1->BaseHeight;
RasterX=0;
RasterY=random(256);
//fill the DDpf structure and get the BytesPerPixel
ZeroMemory (&DDpf, sizeof(DDpf));
DDpf.dwSize = sizeof(DDpf);
m_pddsFrontBuffer->GetPixelFormat(&DDpf);
BPP = DDpf.dwRGBBitCount/8;
Paletteised = (BPP==1) ? true:false;
Scale= tv.AdvancedEffects?2:1;
//ScanLen=460*BPP;
ScanLen=(2+machine.tperscanline*2)*BPP;
switch(zx81.bordersize)
{
case BORDERNONE:
WinL=BlWinL; WinR=BlWinR; WinT=BlWinT; WinB=BlWinB;
if (zx81.NTSC) { WinT-=24; WinB-=24; }
break;
case BORDERSMALL:
WinL=SmWinL; WinR=SmWinR; WinT=SmWinT; WinB=SmWinB;
if (zx81.NTSC) { WinT-=24; WinB-=24; }
break;
case BORDERNORMAL:
WinL=NoWinL; WinR=NoWinR; WinT=NoWinT; WinB=NoWinB;
if (zx81.NTSC) { WinT-=24; WinB-=24; }
break;
case BORDERLARGE:
WinL=LaWinL; WinR=LaWinR; WinT=LaWinT; WinB=LaWinB;
if (zx81.NTSC) { WinB-=24; }
break;
case BORDERFULL:
WinL=FuWinL; WinR=FuWinR; WinT=FuWinT; WinB=FuWinB;
if (zx81.NTSC) WinB-=51;
break;
}
ZeroMemory( &ddsd, sizeof( ddsd ) );
ddsd.dwSize = sizeof( ddsd );
// Create the backbuffer surface
ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE;
if (tv.AdvancedEffects)
{
WinL*=2; WinR*=2; WinT*=2; WinB*=2; ScanLen*=2;
TVW=ddsd.dwWidth = 1024;
TVH=ddsd.dwHeight = 768;
HSYNC_TOLLERANCE=HTOL*2; HSYNC_MINLEN=10;
VSYNC_TOLLERANCE=VTOL*2; VSYNC_MINLEN=350;
}
else
{
TVW=ddsd.dwWidth = 520;
TVH=ddsd.dwHeight = 380;
HSYNC_TOLLERANCE=HTOL; HSYNC_MINLEN=10;
VSYNC_TOLLERANCE=VTOL; VSYNC_MINLEN=350;
}
m_pddsFrame->Release(); m_pddsFrame = NULL;
m_pDD->CreateSurface(&ddsd, &m_pddsFrame, NULL);
if (zx81.NTSC) VSYNC_TOLLERANCE-=60;
if ((resize) && (!Form1->FullScreen))
{
Form1->BaseWidth=WinR-WinL;
Form1->BaseHeight=WinB-WinT;
OrigW = Form1->BaseWidth * ScaleW;
OrigH = Form1->BaseHeight * ScaleH;
if (Form1->StatusBar1->Visible) OrigH += Form1->StatusBar1->Height;
Form1->ClientWidth = OrigW;
Form1->ClientHeight = OrigH;
}
DDFrame=m_pddsFrame;
ZeroMemory(&DDFrameSurface, sizeof(DDFrameSurface));
DDFrameSurface.dwSize = sizeof(DDFrameSurface);
DDFrame->Lock(NULL, &DDFrameSurface, DDLOCK_WAIT | DDLOCK_NOSYSLOCK, NULL);
dest=buffer= (BYTE*)DDFrameSurface.lpSurface;
TVP=DDFrameSurface.lPitch;
RecalcPalette();
RecalcWinSize();
}
示例12: if
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);
}
示例13: loadBitmapDataFromFile
BOOL JCDD_Wrapper::loadBitmapDataFromFile(INT surfaceID, LPWCH filePath)
{
if(lpjcdd->containsTheOffscreenSurface(surfaceID))
{
return FALSE;
}
JCDD_File file;
if(!file.loadData(filePath))
{
return FALSE;
}
JCDD_BitmapData bmpd;
if(!bmpd.create(file.getData()))
{
return FALSE;
}
BOOL reverseRow = bmpd.bmpInfoHeader.biHeight < 0;
INT biWidth = bmpd.bmpInfoHeader.biWidth;
INT biHeight = reverseRow ? -bmpd.bmpInfoHeader.biHeight : bmpd.bmpInfoHeader.biHeight;
if(bmpd.bmpInfoHeader.biBitCount != BitmapDataBitCount_8 &&
bmpd.bmpInfoHeader.biBitCount != BitmapDataBitCount_24 &&
bmpd.bmpInfoHeader.biBitCount != BitmapDataBitCount_32)
{
return FALSE;
}
if(!lpjcdd->createOffscreenSurface(surfaceID, bmpd.bmpInfoHeader.biWidth, biHeight))
{
return FALSE;
}
LPJCDD_Surface surface = lpjcdd->getOffscreenSurface(surfaceID);
LPDIRECTDRAWSURFACE7 lpdds = surface->getSurface();
DDSURFACEDESC2 ddsd;
jcdd_initStruct(&ddsd);
if(FAILED(lpdds->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL)))
{
lpjcdd->deleteOffscreenSurface(surfaceID);
return FALSE;
}
UINT* buffer = (UINT*)ddsd.lpSurface;
INT pixelWidth = bmpd.bmpInfoHeader.biWidth;
INT pixelHeight = biHeight;
INT pixelWidthCount = 0;
INT pixelHeightCount = biHeight - 1;
INT pitch = ddsd.lPitch >> 2;
if(bmpd.bmpInfoHeader.biBitCount == BitmapDataBitCount_8)
{
JCDD_BitmapDataColorIterator8Bit it(&bmpd);
while(it.hasNext())
{
PALETTEENTRY color = bmpd.palette[it.next()];
buffer[pixelWidthCount + pixelHeightCount * pitch] = jcdd_rgb32Bit(0x00, color.peRed, color.peGreen, color.peBlue);
if(++pixelWidthCount == pixelWidth)
{
pixelWidthCount = 0;
--pixelHeightCount;
}
}
}
else if(bmpd.bmpInfoHeader.biBitCount == BitmapDataBitCount_24)
{
JCDD_BitmapDataColorIterator24Bit it(&bmpd);
while(it.hasNext())
{
JCDD_BitmapDataRGB* color = it.next();
buffer[pixelWidthCount + pixelHeightCount * pitch] = jcdd_rgb32Bit(0x00, color->r, color->g, color->b);
if(++pixelWidthCount == pixelWidth)
{
pixelWidthCount = 0;
--pixelHeightCount;
}
}
}
else if(bmpd.bmpInfoHeader.biBitCount == BitmapDataBitCount_32)
{
JCDD_BitmapDataColorIterator32Bit it(&bmpd);
while(it.hasNext())
{
JCDD_BitmapDataXRGB* color = it.next();
buffer[pixelWidthCount + pixelHeightCount * pitch] = jcdd_rgb32Bit(0x00, color->r, color->g, color->b);
if(++pixelWidthCount == pixelWidth)
{
pixelWidthCount = 0;
--pixelHeightCount;
}
}
}
if(FAILED(lpdds->Unlock(NULL)))
{
lpjcdd->deleteOffscreenSurface(surfaceID);
return FALSE;
}
//.........这里部分代码省略.........
示例14: 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
// 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
// clear out the back buffer
DDraw_Fill_Surface(lpddsback, 0);
// lock primary buffer
DDRAW_INIT_STRUCT(ddsd);
if (FAILED(lpddsback->Lock(NULL,&ddsd,
DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,
NULL)))
return(0);
// draw all the asteroids
for (int curr_index = 0; curr_index < NUM_ASTEROIDS; curr_index++)
{
// do the graphics
Draw_Polygon2D(&asteroids[curr_index], (UCHAR *)ddsd.lpSurface, ddsd.lPitch);
// move the asteroid
Translate_Polygon2D(&asteroids[curr_index],
asteroids[curr_index].xv,
asteroids[curr_index].yv);
// rotate the polygon by 5 degrees
Rotate_Polygon2D(&asteroids[curr_index], 5);
// test for out of bounds
if (asteroids[curr_index].x0 > SCREEN_WIDTH+100)
asteroids[curr_index].x0 = - 100;
if (asteroids[curr_index].y0 > SCREEN_HEIGHT+100)
asteroids[curr_index].y0 = - 100;
if (asteroids[curr_index].x0 < -100)
asteroids[curr_index].x0 = SCREEN_WIDTH+100;
if (asteroids[curr_index].y0 < -100)
asteroids[curr_index].y0 = SCREEN_HEIGHT+100;
} // end for curr_asteroid
// unlock primary buffer
if (FAILED(lpddsback->Unlock(NULL)))
return(0);
// perform the flip
while (FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT)));
// wait a sec
Sleep(33);
// return success or failure or your own return code here
return(1);
} // end Game_Main
示例15: 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
// not doing this will cause occasional errors
// 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
// lock the back buffer
DDRAW_INIT_STRUCT(ddsd);
lpddsback->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL);
// alias pointer to back buffer surface
UCHAR *back_buffer = (UCHAR *)ddsd.lpSurface;
// now clear the back buffer out
// linear memory?
if (ddsd.lPitch == SCREEN_WIDTH)
{
memset(back_buffer,0,SCREEN_WIDTH*SCREEN_HEIGHT);
}
else
{
// non-linear memory
// make copy of video pointer
UCHAR *dest_ptr = back_buffer;
// clear out memory one line at a time
for (int y=0; y<SCREEN_HEIGHT; y++)
{
// clear next line
memset(dest_ptr,0,SCREEN_WIDTH);
// advance pointer to next line
dest_ptr+=ddsd.lPitch;
} // end for y
} // end else
// you would perform game logic...
// draw the next frame into the back buffer, notice that we
// must use the lpitch since it's a surface and may not be linear
// plot 5000 random pixels
for (int index=0; index < 5000; index++)
{
int x = rand()%SCREEN_WIDTH;
int y = rand()%SCREEN_HEIGHT;
UCHAR col = rand()%256;
back_buffer[x+y*ddsd.lPitch] = col;
} // end for index
// unlock the back buffer
if (FAILED(lpddsback->Unlock(NULL)))
return(0);
// perform the flip
while (FAILED(lpddsprimary->Flip(NULL, DDFLIP_WAIT)));
// return success or failure or your own return code here
return(1);
} // end Game_Main