本文整理汇总了C++中LPDIRECTDRAWSURFACE7::GetAttachedSurface方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECTDRAWSURFACE7::GetAttachedSurface方法的具体用法?C++ LPDIRECTDRAWSURFACE7::GetAttachedSurface怎么用?C++ LPDIRECTDRAWSURFACE7::GetAttachedSurface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECTDRAWSURFACE7
的用法示例。
在下文中一共展示了LPDIRECTDRAWSURFACE7::GetAttachedSurface方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InitDirectDraw
int InitDirectDraw()
{
DDSURFACEDESC2 ddsd;
DDSCAPS2 ddscaps;
HRESULT hRet;
// Create the main DirectDraw object.
hRet = DirectDrawCreateEx(NULL, (VOID**)&g_pDD, IID_IDirectDraw7, NULL);
if( hRet != DD_OK )
return -1;
// Get exclusive mode.
hRet = g_pDD->SetCooperativeLevel(g_hMainWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
if( hRet != DD_OK )
return -2;
// Set the video mode to 640x480x16.
hRet = g_pDD->SetDisplayMode(640, 480, 16, 0, 0);
if( hRet != DD_OK )
return -3;
// Prepare to create the primary surface by initializing
// the fields of a DDSURFACEDESC2 structure.
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP |
DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount = 1;
// Create the primary surface.
hRet = g_pDD->CreateSurface(&ddsd, &g_pDDSFront, NULL);
if( hRet != DD_OK )
return -1;
// Get a pointer to the back buffer.
ZeroMemory(&ddscaps, sizeof(ddscaps));
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
hRet = g_pDDSFront->GetAttachedSurface(&ddscaps, &g_pDDSBack);
if( hRet != DD_OK )
return -1;
return 0;
}
示例2: InitDD
//-----------------------------------------------------------------------------
// Name: InitDD()
// Desc: Initializes Driect draw and anything that needs to be inited
//-----------------------------------------------------------------------------
int InitDD()
{// this function is where i do all the initialization
// for the game
// create dd object and test for error
ddReturnVal = DirectDrawCreateEx(NULL, (void **)&lpddObj, IID_IDirectDraw7, NULL);
if(DDFailedCheck(ddReturnVal, "DirectDrawCreateEx() failed", cpErrorBuf ))
{ MessageBox(main_window_handle, cpErrorBuf, "Init()", MB_ICONEXCLAMATION); return (0); }
/*
//set cooperation level to windowed mode normal
ddReturnVal = lpddObj->SetCooperativeLevel(main_window_handle, DDSCL_NORMAL);
if (DDFailedCheck(ddReturnVal, "SetCooperativeLevel() failed", cpErrorBuf ))
{ MessageBox(main_window_handle, cpErrorBuf, "Init()", MB_ICONEXCLAMATION); return(0); }
*/
//set cooperation level to full screen
ddReturnVal = lpddObj->SetCooperativeLevel(main_window_handle, DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN |
DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT);
if (DDFailedCheck(ddReturnVal, "SetCooperativeLevel() failed", cpErrorBuf ))
{ MessageBox(main_window_handle, cpErrorBuf, "Init()", MB_ICONEXCLAMATION); return(0); }
// set the display mode
ddReturnVal = lpddObj->SetDisplayMode(WINDOW_WIDTH,WINDOW_HEIGHT,BPP,0,0);
if (DDFailedCheck(ddReturnVal, "SetDisplayMode() failed", cpErrorBuf ))
{ MessageBox(main_window_handle, cpErrorBuf, "Init()", MB_ICONEXCLAMATION); return(0); }
// Create the primary surface first set the fields
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; //set the flags to validate both capabilites field adn the backbuffer count field
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; //tell dd that u have a complex flippable surface
ddsd.dwBackBufferCount = 1; //set the back buffer count
//Createt the primary surface
ddReturnVal = lpddObj->CreateSurface(&ddsd,&lpddsPrimary,NULL);
if (DDFailedCheck(ddReturnVal, "SetCooperativeLevel() failed", cpErrorBuf ))
{ MessageBox(main_window_handle, cpErrorBuf, "Init()", MB_ICONEXCLAMATION); return(0); }
//Query for the backbuffer, use the ddscaps to indicate what you're requesting
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
//get the surface
ddReturnVal = lpddsPrimary->GetAttachedSurface(&ddscaps, &lpddsSecondary);
if (DDFailedCheck(ddReturnVal, "GetAttachedSurface() failed", cpErrorBuf ))
{ MessageBox(main_window_handle, cpErrorBuf, "Init()", MB_ICONEXCLAMATION); return(0); }
//Attach a clipper
RECT cliplist[1];
cliplist[0].top = 0; cliplist[0].left = 0;
cliplist[0].bottom = GetSystemMetrics(SM_CYSCREEN);
cliplist[0].right = GetSystemMetrics(SM_CXSCREEN);
AttachClipper(lpddsSecondary,1,cliplist);
AttachClipper(lpddsPrimary,main_window_handle);
//attack a color key
// set color key to TransparentColor
DDCOLORKEY color_key; // used to set color key
if(BPP == 16)
{
color_key.dwColorSpaceLowValue = BIULDCOLOR(TransColor.r,TransColor.g,TransColor.b);
color_key.dwColorSpaceHighValue = BIULDCOLOR(TransColor.r,TransColor.g,TransColor.b);
}
else
if(BPP == 32)
{
color_key.dwColorSpaceLowValue = _ARGB24BIT(0,TransColor.r,TransColor.g,TransColor.b);
color_key.dwColorSpaceHighValue = _ARGB24BIT(0,TransColor.r,TransColor.g,TransColor.b);
}
// now set the color key for source blitting
ddReturnVal = lpddsSecondary->SetColorKey(DDCKEY_SRCBLT, &color_key);
if (DDFailedCheck(ddReturnVal, "SetColorKey() failed", cpErrorBuf ))
{ MessageBox(main_window_handle, cpErrorBuf, "Init()", MB_ICONEXCLAMATION); return(0); }
//Fill in the wndRect struct
wndRect.top = 0;
wndRect.left = 0;
wndRect.bottom = WINDOW_HEIGHT;
wndRect.right = WINDOW_WIDTH;
return(1);
}
示例3: 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
// seed random number generator
srand(GetTickCount());
// 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);
// 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);
// clear the surfaces out
DDraw_Fill_Surface(lpddsprimary, 0 );
DDraw_Fill_Surface(lpddsback, 0 );
// define points of asteroid
VERTEX2DF asteroid_vertices[8] = {33,-3, 9,-18, -12,-9, -21,-12, -9,6, -15,15, -3,27, 21,21};
// loop and initialize all asteroids
for (int curr_index = 0; curr_index < NUM_ASTEROIDS; curr_index++)
{
// initialize the asteroid
asteroids[curr_index].state = 1; // turn it on
asteroids[curr_index].num_verts = 8;
asteroids[curr_index].x0 = rand()%SCREEN_WIDTH; // position it
asteroids[curr_index].y0 = rand()%SCREEN_HEIGHT;
//.........这里部分代码省略.........
示例4: 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);
// 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 = 0;
palette[color].peGreen = 0;
palette[color].peBlue = color;
// 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);
// return success or failure or your own return code here
return(1);
} // end Game_Init
示例5: 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
//.........这里部分代码省略.........
示例6: CreateFullScreenDisplay
static HRESULT CreateFullScreenDisplay(HWND hWnd, DWORD dwWidth, DWORD dwHeight, DWORD dwBPP)
{
RECT rc;
DWORD dwStyle;
// Set app window's style to WS_POPUP so that it can fit for full screen mode.
dwStyle = GetWindowLong(hWnd, GWL_STYLE);
dwStyle &= ~(WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX);
dwStyle |= WS_POPUP;
SetWindowLong(hWnd, GWL_STYLE, dwStyle);
// Adapt window size
SetRect(&rc, 0, 0, dwWidth, dwHeight);
AdjustWindowRectEx(&rc, GetWindowStyle(hWnd), GetMenu(hWnd) != NULL, GetWindowExStyle(hWnd));
// Set cooperative level
if (FAILED(lpdd->SetCooperativeLevel(hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT)))
{
return E_FAIL;
}
// Set the display mode
if (FAILED(lpdd->SetDisplayMode(dwWidth, dwHeight, dwBPP, 0, 0)))
{
return E_FAIL;
}
// Create primary surface (with backbuffer attached)
DDSURFACEDESC2 ddsd;
DDRAW_INIT_STRUCT(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT | DDSD_CKSRCBLT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP |
DDSCAPS_COMPLEX | DDSCAPS_3DDEVICE;
ddsd.dwBackBufferCount = 1;
if (FAILED(lpdd->CreateSurface(&ddsd, &lpddsMain, NULL)))
{
return E_FAIL;
}
// Get a pointer to the back buffer
DDSCAPS2 ddscaps;
ZeroMemory(&ddscaps, sizeof(ddscaps));
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
if (FAILED(lpddsMain->GetAttachedSurface(&ddscaps, &lpddsBack)))
{
return E_FAIL;
}
//lpddsBack->AddRef();
// Set surface color key
DDCOLORKEY ddCK;
ddCK.dwColorSpaceLowValue = 0;
ddCK.dwColorSpaceHighValue = 0;
if (lpddsBack->SetColorKey(DDCKEY_SRCBLT, &ddCK))
{
return E_FAIL;
}
// Update window flag
SetClassLong(hWnd, GCL_HICONSM, NULL);
SendMessage(hWnd, WM_SETICON, ICON_SMALL, NULL);
UpdateWindow(hWnd);
return S_OK;
}
示例7: InitializeEnvironment
//-------------------------------------------------------------------------
// 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;
}
示例8: Prog_Init
//////////////////////////////////////////////////////////////////////////////
//INITIALIZATION
//////////////////////////////////////////////////////////////////////////////
bool Prog_Init()
{
lpdd=LPDD_Create(hWndMain,DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT);
//set the display mode
lpdd->SetDisplayMode(SCREENWIDTH,SCREENHEIGHT,SCREENBPP,0,0);
//create primary surface
DDSURFACEDESC2 ddsd;
memset(&ddsd,0,sizeof(DDSURFACEDESC2));
ddsd.dwSize=sizeof(DDSURFACEDESC2);
ddsd.dwFlags=DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.dwBackBufferCount=1;
ddsd.ddsCaps.dwCaps=DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX | DDSCAPS_3DDEVICE;
lpdd->CreateSurface(&ddsd,&lpddsPrime,NULL);
//create back buffer
DDSCAPS2 ddscaps;
memset(&ddscaps,0,sizeof(DDSCAPS2));
ddscaps.dwCaps=DDSCAPS_BACKBUFFER | DDSCAPS_3DDEVICE;
lpddsPrime->GetAttachedSurface(&ddscaps,&lpddsBack);
//create the texture surface
memset(&ddsd,0,sizeof(DDSURFACEDESC2));
ddsd.dwSize=sizeof(DDSURFACEDESC2);
ddsd.dwFlags=DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
ddsd.dwWidth=64;
ddsd.dwHeight=64;
ddsd.ddsCaps.dwCaps=DDSCAPS_TEXTURE;
lpdd->CreateSurface(&ddsd,&lpddsTex,NULL);
//used ddfuncs to load a bitmap onto the texture
LPDDS_ReloadFromFile(lpddsTex,"texture.bmp");
//get the idirect3d pointer
lpdd->QueryInterface(IID_IDirect3D7,(void**)&lpd3d);//ICKY COM STUFF!
//create the idirect3ddevice(hack method)
if(FAILED(lpd3d->CreateDevice(IID_IDirect3DTnLHalDevice,lpddsBack,&lpd3ddev)))//try tnl
if(FAILED(lpd3d->CreateDevice(IID_IDirect3DHALDevice,lpddsBack,&lpd3ddev)))//no tnl, try hal
if(FAILED(lpd3d->CreateDevice(IID_IDirect3DMMXDevice,lpddsBack,&lpd3ddev)))//no hal, try mmp
if(FAILED(lpd3d->CreateDevice(IID_IDirect3DRGBDevice,lpddsBack,&lpd3ddev)))//no mmx, resort to rgb
return(false);//problem, return false
//set up viewport
D3DVIEWPORT7 vp;
vp.dwX=0;
vp.dwY=0;
vp.dwWidth=SCREENWIDTH;
vp.dwHeight=SCREENHEIGHT;
vp.dvMinZ=0.0;
vp.dvMaxZ=1.0;
//set viewport for device
lpd3ddev->SetViewport(&vp);
//initialize the vertices(partially, anyway)
vert[0].color=D3DRGB(0.25,0.25,0.25);//set the color for this vertex
vert[0].specular=0;//zero for specular
vert[0].rhw=1.0;//rhw is 1.0
vert[0].tu=0.0;//0.0 for both texture coordinates
vert[0].tv=0.0;
vert[0].sz=0.5;//static z value
vert[1].color=D3DRGB(0.5,0.5,0.5);//set the color for this vertex
vert[1].specular=0;//zero for specular
vert[1].rhw=1.0;//rhw is 1.0
vert[1].tu=1.0;//0.0 for both texture coordinates
vert[1].tv=0.0;
vert[1].sz=0.5;//static z value
vert[2].color=D3DRGB(0.5,0.5,0.5);//set the color for this vertex
vert[2].specular=0;//zero for specular
vert[2].rhw=1.0;//rhw is 1.0
vert[2].tu=0.0;//0.0 for both texture coordinates
vert[2].tv=1.0;
vert[2].sz=0.5;//static z value
vert[3].color=D3DRGB(1.0,1.0,1.0);//set the color for this vertex
vert[3].specular=0;//zero for specular
vert[3].rhw=1.0;//rhw is 1.0
vert[3].tu=1.0;//0.0 for both texture coordinates
vert[3].tv=1.0;
vert[3].sz=0.5;//static z value
//set the texture
lpd3ddev->SetTexture(0,lpddsTex);
return(true);//return success
}
示例9: 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 640x480x24
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;
ddsd.dwBackBufferCount = 1;
//
// request primary surface
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;
// create the primary surface
if (FAILED(lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL)))
return(0);
ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
if(FAILED(lpddsprimary->GetAttachedSurface(&ddsd.ddsCaps, &lpddsback))) return 0;
// 把主屏和缓冲屏都填充为黑色初始化
DDraw_Fill_Surface(lpddsprimary, _RGB32BIT(0, 0,0,0));
DDraw_Fill_Surface(lpddsback, _RGB32BIT(0, 0,0,0));
// load the 24-bit image
char* bmp_wc = "WarCraft24.bmp";
char* bmp_b8 = "bitmap8b.bmp";
char* bmp_b24 = "bitmap24.bmp";
char* bmp_b24e = "bitmap24_edit.bmp";
char* bmp_mo24 = "mosaic-600x.bmp";
char* bmp_ni24 = "nightelf-640x.bmp";
char* bmp_alley24 = "alley8_24bit.bmp";
// 载入背景图片
if (!Load_Bitmap_File(&bitmap, bmp_ni24))
return(0);
// 创建背景表面、但实际上不是直接用背景表面来显示的、而是拷贝去缓冲表面和人物动作混合
// 后才一次性打到显示表面
// 这里头两个参数是指在屏幕的高和宽、第二个是指表面建立的地点、0指在显存建立、其它表示在
// 系统内存建立、当然速度自然是在显存建立快了、最后一个参数是是否设置为色彩键、这里设定为-1
// 也就是不设定任何色彩过滤、因为这个是背景表面、所以不需要任何透明的色彩键
lpddsbackground = DDraw_Create_Surface(640,480,0,-1);
// 把bmp的内容拷贝至缓冲表面中
Bmp2Surface(lpddsbackground, SCREEN_WIDTH, SCREEN_HEIGHT);
// 从现在开始创建人物动作了
if (!Load_Bitmap_File(&bitmap, "Dedsp0_24bit.bmp"))
return(0);
// seed random number generator
// GetTickCount是一个系统启动至今的毫秒数、
// 配合srandg来产生一个随机数
srand(GetTickCount());
// initialize all the aliens
// alien on level 1 of complex
//.........这里部分代码省略.........
示例10: DD_Init
int DD_Init(int width, int height, int bpp)
{
// this function initializes directdraw
int index; // looping variable
// create object and test for error
if (DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)!=DD_OK)
return(0);
// set cooperation level to windowed mode normal
if (lpdd->SetCooperativeLevel(main_window_handle,
DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN |
DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)!=DD_OK)
return(0);
// set the display mode
if (lpdd->SetDisplayMode(width,height,bpp,0,0)!=DD_OK)
return(0);
// set globals
screen_height = height;
screen_width = width;
screen_bpp = bpp;
// Create the primary surface
memset(&ddsd,0,sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
// we need to let dd know that we want a complex
// flippable surface structure, set flags for that
ddsd.ddsCaps.dwCaps =
DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
// set the backbuffer count to 1
ddsd.dwBackBufferCount = 1;
// create the primary surface
lpdd->CreateSurface(&ddsd,&lpddsprimary,NULL);
// query for the backbuffer i.e the secondary surface
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
lpddsprimary->GetAttachedSurface(&ddscaps,&lpddsback);
// create and attach palette
// create palette data
// clear all entries defensive programming
memset(palette,0,256*sizeof(PALETTEENTRY));
// create a R,G,B,GR gradient palette
for (index=0; index < 256; index++)
{
// set each entry
if (index < 64)
palette[index].peRed = index*4;
else // shades of green
if (index >= 64 && index < 128)
palette[index].peGreen = (index-64)*4;
else // shades of blue
if (index >= 128 && index < 192)
palette[index].peBlue = (index-128)*4;
else // shades of grey
if (index >= 192 && index < 256)
palette[index].peRed = palette[index].peGreen =
palette[index].peBlue = (index-192)*4;
// set flags
palette[index].peFlags = PC_NOCOLLAPSE;
} // end for index
// now create the palette object
if (lpdd->CreatePalette(DDPCAPS_8BIT | DDPCAPS_INITIALIZE | DDPCAPS_ALLOW256,
palette,&lpddpal,NULL)!=DD_OK)
return(0);
// attach the palette to the primary
if (lpddsprimary->SetPalette(lpddpal)!=DD_OK)
return(0);
// clear out both primary and secondary surfaces
DD_Fill_Surface(lpddsprimary,0);
DD_Fill_Surface(lpddsback,0);
// attach a clipper to the screen
RECT screen_rect = {0,0,screen_width,screen_height};
lpddclipper = DD_Attach_Clipper(lpddsback,1,&screen_rect);
// return success
return(1);
} // end DD_Init
示例11: vdraw_ddraw_init
//.........这里部分代码省略.........
// Clear ddsd.
memset(&ddsd, 0x00, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
if (vdraw_get_fullscreen() && Video.VSync_FS)
{
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount = 2;
}
else
{
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
}
// Create the primary surface.
rval = lpDD->CreateSurface(&ddsd, &lpDDS_Primary, NULL);
if (FAILED(rval))
{
vdraw_ddraw_free_all(false);
LOG_MSG(video, LOG_MSG_LEVEL_ERROR,
"lpDD->CreateSurface(&lpDDS_Primary) failed: 0x%08X", rval);
return -5;
}
if (vdraw_get_fullscreen())
{
if (Video.VSync_FS)
{
ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;
rval = lpDDS_Primary->GetAttachedSurface(&ddsd.ddsCaps, &lpDDS_Flip);
if (FAILED(rval))
{
vdraw_ddraw_free_all(false);
LOG_MSG(video, LOG_MSG_LEVEL_ERROR,
"lpDDS_Primary->GetAttachSurface() failed: 0x%08X", rval);
return -6;
}
lpDDS_Blit = lpDDS_Flip;
}
else
{
lpDDS_Blit = lpDDS_Primary;
}
}
else
{
rval = lpDD->CreateClipper(0, &lpDDC_Clipper, NULL);
if (FAILED(rval))
{
vdraw_ddraw_free_all(false);
LOG_MSG(video, LOG_MSG_LEVEL_ERROR,
"lpDD->CreateClipper() failed: 0x%08X", rval);
return -7;
}
rval = lpDDC_Clipper->SetHWnd(0, gens_window);
if (FAILED(rval))
{
vdraw_ddraw_free_all(false);
LOG_MSG(video, LOG_MSG_LEVEL_ERROR,
"lpDDC_Clipper->SetHWnd() failed: 0x%08X", rval);
示例12: dx_Initialise
//-----------------------------------------------------------------------------
// Name: dx_Initialise (...)
// Desc: Initialise et configure DirectX (DirectDraw)
//-----------------------------------------------------------------------------
bool dx_Initialise (uint8 pNombreSurfaces,
HWND pFenetre,
uint16 pResolutionX,
uint16 pResolutionY,
uint16 pBitsParPixel,
uint16 pFrequence,
bool pPleinEcran,
bool pTailleFenetre,
void (*pRestaure)())
{
// InitialiseDX a déjà été appelé
if (DirectDraw7 != NULL) {
return dx_Finalise (ERR_NO_UTILISATEUR);
}
dx_InitVars ();
// Initialise toutes les variables
Fenetre = pFenetre;
NombreSurfaces = pNombreSurfaces;
ResolutionX = pResolutionX;
ResolutionY = pResolutionY;
BitsParPixel = pBitsParPixel;
Frequence = pFrequence;
PleinEcran = pPleinEcran;
TailleFenetre = pTailleFenetre;
Restaure = pRestaure;
Surfaces = new LPDIRECTDRAWSURFACE7[NombreSurfaces];
// Initialisation de directdraw
ErrDd = DirectDrawCreateEx (0,(LPVOID*)&DirectDraw7,IID_IDirectDraw7,0);
if (ErrDd != DD_OK) return dx_Finalise (ERR_NO_CREATION);
ModeCoop = PleinEcran ? COOP_PLEIN_ECRAN : COOP_FENETRE;
// Utilisation de la résolution active ou donnée
if (ResolutionX == 0 || ResolutionY == 0 ||
BitsParPixel == 0 || Frequence == 0)
{
DDSURFACEDESC2 ModeActif;
ZeroMemory (&ModeActif, sizeof(ModeActif));
ModeActif.dwSize = sizeof(ModeActif);
ErrDd = DirectDraw7->GetDisplayMode (&ModeActif);
if (ErrDd != DD_OK) return dx_Finalise (ERR_NO_MODE_ACTIF);
if (ResolutionX == 0) ResolutionX = ModeActif.dwWidth;
if (ResolutionY == 0) ResolutionY = ModeActif.dwHeight;
if (BitsParPixel == 0) BitsParPixel = ModeActif.
ddpfPixelFormat.dwRGBBitCount;
if (Frequence == 0) Frequence = ModeActif.dwRefreshRate;
}
// Sélection du mode de coopération
ErrDd = DirectDraw7->SetCooperativeLevel (Fenetre, ModeCoop);
if (ErrDd != DD_OK) return dx_Finalise (ERR_NO_COOPERATION);
ErrDd = DirectDraw7->SetDisplayMode (ResolutionX,
ResolutionY,BitsParPixel,0,0);
if (ErrDd != DD_OK) return dx_Finalise (ERR_NO_MODE_AFFICHAGE);
// Création des surfaces d'affichage
SurfaceDesc.dwFlags = DDSD_CAPS;
SurfaceDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
if (PleinEcran)
{ // Surface avec backbuffer
SurfaceDesc.dwFlags |= DDSD_BACKBUFFERCOUNT;
SurfaceDesc.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX;
SurfaceDesc.dwBackBufferCount = 1;
}
ErrDd = DirectDraw7->CreateSurface (&SurfaceDesc,&SurfacePrimaire,NULL);
if (ErrDd != DD_OK) return dx_Finalise (ERR_NO_PRIMAIRE);
if (PleinEcran)
{
SurfaceCaps.dwCaps = DDSCAPS_BACKBUFFER;
ErrDd = SurfacePrimaire->GetAttachedSurface (&SurfaceCaps,&SurfaceBack);
//.........这里部分代码省略.........