本文整理汇总了C++中LPDIRECT3D8::GetAdapterDisplayMode方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECT3D8::GetAdapterDisplayMode方法的具体用法?C++ LPDIRECT3D8::GetAdapterDisplayMode怎么用?C++ LPDIRECT3D8::GetAdapterDisplayMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECT3D8
的用法示例。
在下文中一共展示了LPDIRECT3D8::GetAdapterDisplayMode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InitD3D
//-----------------------------------------------------------------------------
// Name: InitD3D()
// Desc: Initializes Direct3D
//-----------------------------------------------------------------------------
HRESULT InitD3D( HWND hWnd )
{
// Create the D3D object.
if( NULL == ( g_pD3D = Direct3DCreate8( D3D_SDK_VERSION ) ) )
return E_FAIL;
// Get the current desktop display mode, so we can set up a back
// buffer of the same format
D3DDISPLAYMODE d3ddm;
if( FAILED( g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) )
return E_FAIL;
// Set up the structure used to create the D3DDevice
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
// Create the D3DDevice
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) )
{
return E_FAIL;
}
// Turn off culling, so we see the front and back of the triangle
g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
// Turn off D3D lighting, since we are providing our own vertex colors
g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
return S_OK;
}
示例2: InitD3D
//-----------------------------------------------------------------------------
// Name: InitD3D()
// Desc: Initializes Direct3D
//-----------------------------------------------------------------------------
HRESULT InitD3D( HWND hWnd )
{
// Create the D3D object, which is needed to create the D3DDevice.
if( NULL == ( g_pD3D = Direct3DCreate8( D3D_SDK_VERSION ) ) )
return E_FAIL;
// Get the current desktop display mode
D3DDISPLAYMODE d3ddm;
if( FAILED( g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) )
return E_FAIL;
// Set up the structure used to create the D3DDevice. Most parameters are
// zeroed out. We set Windowed to TRUE, since we want to do D3D in a
// window, and then set the SwapEffect to "discard", which is the most
// efficient method of presenting the back buffer to the display. And
// we request a back buffer format that matches the current desktop display
// format.
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
// Create the Direct3D device. Here we are using the default adapter (most
// systems only have one, unless they have multiple graphics hardware cards
// installed) and requesting the HAL (which is saying we want the hardware
// device rather than a software one). Software vertex processing is
// specified since we know it will work on all cards. On cards that support
// hardware vertex processing, though, we would see a big performance gain
// by specifying hardware vertex processing.
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) )
{
return E_FAIL;
}
// Device state would normally be set here
return S_OK;
}
示例3: InitD3D
//-----------------------------------------------------------------------------
// Name: InitD3D()
// Desc: Initializes Direct3D
//-----------------------------------------------------------------------------
HRESULT InitD3D( HWND hWnd )
{
// Create the D3D object.
if( NULL == ( g_pD3D = Direct3DCreate8( D3D_SDK_VERSION ) ) )
return E_FAIL;
// Get the current desktop display mode, so we can set up a back
// buffer of the same format
D3DDISPLAYMODE d3ddm;
if( FAILED( g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ) ) )
return E_FAIL;
// Set up the structure used to create the D3DDevice. Since we are now
// using more complex geometry, we will create a device with a zbuffer.
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
// Create the D3DDevice
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) )
{
return E_FAIL;
}
// Turn off culling
g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
// Turn off D3D lighting
g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
// Turn on the zbuffer
g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
return S_OK;
}
示例4: WinMain
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
HWND hwnd;
MSG msg;
char appname[6];
strcpy(appname,"test1");
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = appname;
RegisterClass(&wc);
hwnd = CreateWindowEx(0/*WS_EX_TOPMOST*/,appname,NULL,WS_VISIBLE | WS_BORDER | WS_SYSMENU,0,0,800,600,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOW);
SetFocus(hwnd);
if(NULL == (pd3d = Direct3DCreate8( D3D_SDK_VERSION )))
{
MessageBox(hwnd,"Failed to create D3D object",ERROR,MB_ICONERROR | MB_OK | MB_SYSTEMMODAL);
//PostQuitMessage(0);
return false;
}
D3DPRESENT_PARAMETERS d3dpp;
D3DDISPLAYMODE d3ddm;
/*d3ddm.Width = 800;
d3ddm.Height = 600;
d3ddm.RefreshRate = 0;
d3ddm.Format = D3DFMT_A8R8G8B8;
*/pd3d->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm );
ZeroMemory( &d3dpp, sizeof(d3dpp) );
/*d3dpp.BackBufferWidth = 800;
d3dpp.BackBufferHeight = 600;
d3dpp.BackBufferCount = 1;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.Windowed = FALSE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.hDeviceWindow = NULL;
d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER ;
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_ONE;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
*/d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
if(FAILED(pd3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &d3ddevice )))
{
MessageBox(hwnd,"Failed to Initialize D3D object",ERROR,MB_ICONERROR | MB_OK | MB_SYSTEMMODAL);
//PostQuitMessage(0);
return false;
}
setup();
SetTimer(hwnd,1,20,NULL);
//ShowCursor(false);
while(!done)
{
while(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//if(msg.message == WM_QUIT) break;
StartFrame();
Render();
EndFrame();
}
KillTimer(hwnd,1);
shutdown();
if( d3ddevice != NULL)
d3ddevice->Release();
if( pd3d != NULL)
pd3d->Release();
//ShowCursor(true);
return 0;
}
示例5: main
int main(int argc, char* argv[])
{
int NoProtect = 0;
AllowLinear = true;
double MaxMSE = 4.0;
CmdLineArgs args;
if (args.size() == 1)
{
Usage();
return 1;
}
const char* InputDir = NULL;
const char* OutputFilename = "Textures.xpr";
for (unsigned int i = 1; i < args.size(); ++i)
{
if (!stricmp(args[i], "-help") || !stricmp(args[i], "-h") || !stricmp(args[i], "-?"))
{
Usage();
return 1;
}
else if (!stricmp(args[i], "-input") || !stricmp(args[i], "-i"))
{
InputDir = args[++i];
}
else if (!stricmp(args[i], "-output") || !stricmp(args[i], "-o"))
{
OutputFilename = args[++i];
}
else if (!stricmp(args[i], "-noprotect") || !stricmp(args[i], "-p"))
{
NoProtect = 1;
}
else if (!stricmp(args[i], "-onlyswizzled") || !stricmp(args[i], "-s"))
{
AllowLinear = false;
}
else if (!stricmp(args[i], "-quality") || !stricmp(args[i], "-q"))
{
++i;
if (!stricmp(args[i], "min"))
{
MaxMSE = DBL_MAX;
}
else if (!stricmp(args[i], "low"))
{
MaxMSE = 20.0;
}
else if (!stricmp(args[i], "normal"))
{
MaxMSE = 4.0;
}
else if (!stricmp(args[i], "high"))
{
MaxMSE = 1.5;
}
else if (!stricmp(args[i], "max"))
{
MaxMSE = 0.0;
}
else
{
printf("Unrecognised quality setting: %s\n", args[i]);
}
}
else
{
printf("Unrecognised command line flag: %s\n", args[i]);
}
}
// Initialize DirectDraw
pD3D = Direct3DCreate8(D3D_SDK_VERSION);
if (pD3D == NULL)
{
puts("Cannot init D3D");
return 1;
}
HRESULT hr;
D3DDISPLAYMODE dispMode;
D3DPRESENT_PARAMETERS presentParams;
pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dispMode);
ZeroMemory(&presentParams, sizeof(presentParams));
presentParams.Windowed = TRUE;
presentParams.hDeviceWindow = GetConsoleWindow();
presentParams.SwapEffect = D3DSWAPEFFECT_COPY;
presentParams.BackBufferWidth = 8;
presentParams.BackBufferHeight = 8;
presentParams.BackBufferFormat = dispMode.Format;
hr = pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentParams, &pD3DDevice);
if (FAILED(hr))
{
printf("Cannot init D3D device: %08x\n", hr);
//.........这里部分代码省略.........
示例6: SetVideoMode
CString RageDisplay_D3D::Init( VideoModeParams p )
{
GraphicsWindow::Initialize();
LOG->Trace( "RageDisplay_D3D::RageDisplay_D3D()" );
LOG->MapLog("renderer", "Current renderer: Direct3D");
typedef IDirect3D8 * (WINAPI * Direct3DCreate8_t) (UINT SDKVersion);
Direct3DCreate8_t pDirect3DCreate8;
#if defined(XBOX)
pDirect3DCreate8 = Direct3DCreate8;
#else
g_D3D8_Module = LoadLibrary("D3D8.dll");
if(!g_D3D8_Module)
return D3D_NOT_INSTALLED;
pDirect3DCreate8 = (Direct3DCreate8_t) GetProcAddress(g_D3D8_Module, "Direct3DCreate8");
if(!pDirect3DCreate8)
{
LOG->Trace( "Direct3DCreate8 not found" );
return D3D_NOT_INSTALLED;
}
#endif
g_pd3d = pDirect3DCreate8( D3D_SDK_VERSION );
if(!g_pd3d)
{
LOG->Trace( "Direct3DCreate8 failed" );
return D3D_NOT_INSTALLED;
}
if( FAILED( g_pd3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &g_DeviceCaps) ) )
return
"Your system is reporting that Direct3D hardware acceleration is not available. "
"Please obtain an updated driver from your video card manufacturer.\n\n";
D3DADAPTER_IDENTIFIER8 identifier;
g_pd3d->GetAdapterIdentifier( D3DADAPTER_DEFAULT, 0, &identifier );
LOG->Trace(
"Driver: %s\n"
"Description: %s\n"
"Max texture size: %d\n"
"Alpha in palette: %s\n",
identifier.Driver,
identifier.Description,
g_DeviceCaps.MaxTextureWidth,
(g_DeviceCaps.TextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE) ? "yes" : "no" );
LOG->Trace( "This display adaptor supports the following modes:" );
D3DDISPLAYMODE mode;
for( UINT u=0; u<g_pd3d->GetAdapterModeCount(D3DADAPTER_DEFAULT); u++ )
if( SUCCEEDED( g_pd3d->EnumAdapterModes( D3DADAPTER_DEFAULT, u, &mode ) ) )
LOG->Trace( " %ux%u %uHz, format %d", mode.Width, mode.Height, mode.RefreshRate, mode.Format );
g_PaletteIndex.clear();
for( int i = 0; i < 256; ++i )
g_PaletteIndex.push_back(i);
// Save the original desktop format.
g_pd3d->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &g_DesktopMode );
/* Up until now, all we've done is set up g_pd3d and do some queries. Now,
* actually initialize the window. Do this after as many error conditions
* as possible, because if we have to shut it down again we'll flash a window
* briefly. */
bool bIgnore = false;
return SetVideoMode( p, bIgnore );
}
示例7: init3D
//*******
// this function initializes Direct3D...
bool init3D(HWND hWnd)
{
D3DDISPLAYMODE d3ddm; // Direct3D Display Mode..
D3DPRESENT_PARAMETERS d3dpp; // d3d present parameters..details on how it should present
// a scene.. such as swap effect.. size.. windowed or full screen..
HFONT fnt;
// create D3D8.. if error (like that ever happens..) return false..
if (NULL == (lpD3D8 = Direct3DCreate8(D3D_SDK_VERSION)))
return false;
// get display adapter mode.. if error return false..
if (FAILED(lpD3D8->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
return false;
// NOTE: it's possible that this example will not work as is
// in windowed mode due to display format and depth buffer format
ZeroMemory(&d3dpp, sizeof(d3dpp)); // blank the memory for good measure..
// d3dpp.Windowed = true; // use this for window mode..
d3dpp.Windowed = false; // use this for full screen... it's that easy!
d3dpp.BackBufferWidth = 1024; // rather useless for windowed version
d3dpp.BackBufferHeight = 768; // ditto..but left it in anyway for full screen
d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP; // flip using a back buffer...easy performance
d3dpp.BackBufferFormat = D3DFMT_R5G6B5; // just set back buffer format from display mode
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16; // 16 bit depth buffer..
// Create the D3DDevice
if (FAILED(lpD3D8->CreateDevice(D3DADAPTER_DEFAULT, // which display adapter..
D3DDEVTYPE_HAL,
hWnd, D3DCREATE_MIXED_VERTEXPROCESSING, // mixed, software, or hardware..
&d3dpp, &lpD3DDevice8))) // sends stuff.. and to receive
{ // if it fails to create with HAL, then try (usually succeeds) to create
// with ref (software) using a much lower screen res
d3dpp.BackBufferWidth = 320;
d3dpp.BackBufferHeight = 240;
d3dpp.Windowed = false;
if (FAILED(lpD3D8->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_REF,
hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &lpD3DDevice8)))
{
return false;
}
else
{ // create smaller font for software... lower res..
fnt = CreateFont(20, 10, 2, 0, 500, 0, 0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_MODERN, 0);
// disable dithering for software..
lpD3DDevice8->SetRenderState( D3DRS_DITHERENABLE, false);
}
}
else
{ // create larger font for hardware.. higher res
fnt = CreateFont(50, 22, 2, 0, 500, 0, 0, 0, ANSI_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_MODERN, 0);
// enable dithering for hardware...
lpD3DDevice8->SetRenderState( D3DRS_DITHERENABLE, true);
}
lpD3DDevice8->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
lpD3DDevice8->SetRenderState( D3DRS_ZENABLE, false);
lpD3DDevice8->SetRenderState( D3DRS_LIGHTING, false );
// create a D3DXFont from a windows font created above...
// for use in drawing text with D3D
D3DXCreateFont(lpD3DDevice8, fnt, &lpD3DXFont);
lpD3DDevice8->SetRenderState(D3DRS_ALPHABLENDENABLE , true);
lpD3DDevice8->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
lpD3DDevice8->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_SRCALPHA);
return true;
}
示例8: D3DM_ChangeF2W
BOOL D3DM_ChangeF2W( void )
{
int i;
if(!D3DMain.m_WindowModeChange) return FALSE;
D3DMain.m_WindowModeChange = FALSE;
if( pD3DDevice && pD3D ){
D3DMain.m_DisplayModeChange=2;
if( D3DMain.m_FullScreenOnly ){
SetWindowLong(D3DMain.m_DrawHwnd, GWL_STYLE, FullModeStyle);
SetMenu(D3DMain.m_DrawHwnd, NULL);
return FALSE;
}
D3DMain.m_WindowMode = !D3DMain.m_WindowMode;
if( D3DMain.m_WindowMode==TRUE ){
D3DD_ResetAllRenderTargetTexture();
ZeroMemory(&d3dppApp,sizeof(d3dppApp));
d3dppApp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
d3dppApp.Windowed = D3DMain.m_WindowMode;
d3dppApp.SwapEffect = D3DSWAPEFFECT_COPY;
d3dppApp.BackBufferFormat = D3DCapsStruct.m_WindowDisplayMode.Format;
d3dppApp.BackBufferCount = 1;
d3dppApp.BackBufferWidth = WinWidth;
d3dppApp.BackBufferHeight = WinHeight;
if( FAILED(pD3DDevice->Reset(&d3dppApp)) ){
D3DMain.m_FlipActive=FALSE;
ZeroMemory(&d3dppApp,sizeof(d3dppApp));
d3dppApp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
d3dppApp.Windowed = D3DMain.m_WindowMode=FALSE;
d3dppApp.SwapEffect = FULL_FLIP;
d3dppApp.BackBufferFormat = D3DCapsStruct.m_NowDisplayMode.Format;
d3dppApp.BackBufferCount = 1;
d3dppApp.BackBufferWidth = WinWidth;
d3dppApp.BackBufferHeight = WinHeight;
pD3DDevice->Reset(&d3dppApp);
return FALSE;
}
if( FAILED(pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&D3DCapsStruct.m_NowDisplayMode)) ){
MessageBox(NULL,"ディスプレイモードの取得に失敗しました。[なにゆえ?]","致命的なエラー", MB_OK | MB_ICONSTOP);
return FALSE;
}
SetWindowLong(D3DMain.m_DrawHwnd, GWL_STYLE, WindowStyle);
SetMenu(D3DMain.m_DrawHwnd, D3DMain.m_MenuHwnd );
RECT rect;
SetRect( &rect, 0, 0, WinWidth, WinHeight );
AdjustWindowRect( &rect, WindowStyle, !!D3DMain.m_MenuHwnd );
int wx = (GetSystemMetrics(SM_CXFULLSCREEN)-(rect.right-rect.left))/2;
int wy = (GetSystemMetrics(SM_CYFULLSCREEN)-(rect.bottom-rect.top))/2;
wx = WinX;
wy = WinY;
SetWindowPos( D3DMain.m_DrawHwnd, HWND_NOTOPMOST, wx, wy, rect.right-rect.left, rect.bottom-rect.top , SWP_SHOWWINDOW|SWP_DRAWFRAME );
}else{
D3DMain.m_FlipActive=FALSE;
if( FAILED(pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&D3DCapsStruct.m_WindowDisplayMode)) ){
MessageBox(NULL,"ディスプレイモードの取得に失敗しました。[なにゆえ?]","致命的なエラー", MB_OK | MB_ICONSTOP);
return FALSE;
}
D3DD_ResetAllRenderTargetTexture();
ZeroMemory(&d3dppApp,sizeof(d3dppApp));
d3dppApp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
d3dppApp.Windowed = D3DMain.m_WindowMode;
d3dppApp.SwapEffect = D3DSWAPEFFECT_COPY;
d3dppApp.BackBufferCount = 1;
d3dppApp.BackBufferWidth = WinWidth;
d3dppApp.BackBufferHeight = WinHeight;
if(DrawSetting.full_16bit){
d3dppApp.BackBufferFormat=D3DFMT_UNKNOWN;
for(i=0;i<D3DCapsStruct.m_DisplayModeNum;i++){
if( D3DCapsStruct.m_DisplayMode[i].Width == 800 && D3DCapsStruct.m_DisplayMode[i].Height == 600 ){
switch( D3DCapsStruct.m_DisplayMode[i].Format ){
case D3DFMT_R5G6B5: case D3DFMT_X1R5G5B5:
//.........这里部分代码省略.........
示例9: D3DM_InitDevices
int D3DM_InitDevices( HWND hwnd, int w, int h, int full, HMENU menu )
{
char buf[256];
int i,j;
LPDIRECTDRAW7 pDD = NULL;
HRESULT hr;
if( FAILED( hr = DirectDrawCreateEx( NULL, (VOID**)&pDD, IID_IDirectDraw7, NULL ) ) )
return DDENUMRET_CANCEL;
D3DCapsStruct.m_ddCaps.dwSize = sizeof(DDCAPS);
pDD->GetCaps( &D3DCapsStruct.m_ddCaps, NULL );
if(pDD) {
pDD->Release();
pDD = NULL;
}
ZeroMemory( d3dTexture, sizeof(D3DD_TEXTURE)*D3DD_MAX_TEXTURE_AMOUNT );
ZeroMemory( d3dText, sizeof(D3DD_TEXT)*D3DD_MAX_TEXT_AMOUNT );
ZeroMemory( d3dDisp, sizeof(D3DD_DISP)*D3DD_MAX_DISP_AMOUNT );
pD3D = Direct3DCreate8(D3D_SDK_VERSION);
if(pD3D == NULL){
MessageBox(NULL,"Direct3Dオブジェクトの生成に失敗しました。[DirectX8.1が入っていない?]","致命的なエラー", MB_OK | MB_ICONSTOP);
return FALSE;
}
if( FAILED(pD3D->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &D3DCapsStruct.m_d3dCaps)) ){
MessageBox(NULL,"デバイス能力の取得に失敗しました","致命的なエラー", MB_OK | MB_ICONSTOP);
return FALSE;
}
EnumAdapters(D3DADAPTER_DEFAULT);
if( (int)D3DCapsStruct.m_d3dCaps.MaxTextureWidth < D3DD_TEXTURE_CONTROL_SIZE ){
DebugBox( NULL, "このビデオカードは、幅 %d pixel 以上のサイズのテクスチャを生成できません。[%s]", D3DD_TEXTURE_CONTROL_SIZE);
return FALSE;
}else if( (int)D3DCapsStruct.m_d3dCaps.MaxTextureHeight < D3DD_TEXTURE_CONTROL_SIZE ){
DebugBox( NULL, "このビデオカードは、高さ %d pixel 以上のサイズのテクスチャを生成できません。[%s]", D3DD_TEXTURE_CONTROL_SIZE );
return FALSE;
}
if( !(D3DCapsStruct.m_d3dCaps.ShadeCaps&D3DPSHADECAPS_ALPHAGOURAUDBLEND) ){
MessageBox(NULL,"このビデオデバイスはグーロブレンディングに対応していません。\nゲームの画像が乱れることがあります","警告", MB_OK | MB_ICONSTOP);
}
if( !(D3DCapsStruct.m_d3dCaps.ShadeCaps&D3DPSHADECAPS_COLORGOURAUDRGB) ){
MessageBox(NULL,"このビデオデバイスはグーロシェーディングに対応していません。\nゲームの画像が乱れることがあります","警告", MB_OK | MB_ICONSTOP);
}
if( D3DCapsStruct.m_d3dCaps.TextureCaps&D3DPTEXTURECAPS_SQUAREONLY ){
DebugBox( NULL, "このビデオカードは長方形テクスチャを生成できません。[デバッグ用ダイアログ]" );
}
if( FAILED(pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&D3DCapsStruct.m_NowDisplayMode)) ){
MessageBox(NULL,"ディスプレイモードの取得に失敗しました。[なにゆえ?]","致命的なエラー", MB_OK | MB_ICONSTOP);
return FALSE;
}
D3DCapsStruct.m_WindowDisplayMode = D3DCapsStruct.m_NowDisplayMode;
D3DMain.m_DrawHwnd = hwnd;
D3DMain.m_MenuHwnd = menu;
if( GetSystemMetrics(SM_CXFULLSCREEN)<=800 || GetSystemMetrics(SM_CYFULLSCREEN)<=600){
D3DMain.m_FullScreenOnly = TRUE;
D3DMain.m_WindowMode = FALSE;
}else{
D3DMain.m_FullScreenOnly = FALSE;
D3DMain.m_WindowMode = !full;
}
ZeroMemory(&d3dppApp,sizeof(d3dppApp));
WinWidth = w;
WinHeight = h;
d3dppApp.SwapEffect = D3DSWAPEFFECT_COPY;
d3dppApp.BackBufferFormat = D3DCapsStruct.m_NowDisplayMode.Format;
d3dppApp.BackBufferCount = 1;
d3dppApp.BackBufferWidth = WinWidth;
d3dppApp.BackBufferHeight = WinHeight;
d3dppApp.Windowed = TRUE;
d3dppApp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
HRESULT ret;
ret = pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dppApp,&pD3DDevice);
if( FAILED(ret) ){
ret = pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dppApp,&pD3DDevice);
//.........这里部分代码省略.........