bool DG8Graphics::SetupGraphics(void) { if((m_Direct3D = Direct3DCreate8(D3D_SDK_VERSION)) != NULL){ if(m_Direct3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&m_DisplayMode) == D3D_OK){ // Set up the structure used to create the D3DDevice D3DPRESENT_PARAMETERS d3dpp; memset(&d3dpp,0,sizeof(d3dpp) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = m_DisplayMode.Format; if(m_Direct3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_platform->m_hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &m_RenderDevice) == D3D_OK){ m_RenderDevice->SetRenderState(D3DRS_ZENABLE,D3DZB_TRUE); m_RenderDevice->SetRenderState(D3DRS_ZFUNC,D3DCMP_LESSEQUAL); Disable(IGraphics::LIGHTING); SetClearColour(0,0,0); return true; } } } return false; }
BOOL CDX8Disp::OnInitDialog() { CDialog::OnInitDialog(); d3d_interface = Direct3DCreate8( D3D_SDK_VERSION ); // User does not have DX8 installed; disable all functionality if( d3d_interface == NULL ) { GetDlgItem(IDC_DX8_NOT_INSTALLED)->ShowWindow(TRUE); GetDlgItem(IDC_GEN_CAPS)->ShowWindow(FALSE); GetDlgItem(IDC_ADAPTER_LIST)->ShowWindow(FALSE); GetDlgItem(IDC_RES_LIST)->ShowWindow(FALSE); GetDlgItem(IDC_CDEPTH_LIST)->ShowWindow(FALSE); GetDlgItem(IDC_ANTIALIAS_LIST)->ShowWindow(FALSE); MessageBox("You do not have DX8.1 installed; cannot offer D3D8 options", "Error", MB_ICONERROR); return TRUE; } color_depthDX[0].cdepth = 16; strcpy(color_depthDX[0].text, "16-bit"); color_depthDX[1].cdepth = 32; strcpy(color_depthDX[1].text, "32-bit"); m_dx8_initialised_ok = true; return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
bool CGraphicsDevice::Create() { m_pD3D = Direct3DCreate8(D3D_SDK_VERSION); if (!m_pD3D) { printf("Cannot init D3D\n"); return false; } HRESULT hr; D3DDISPLAYMODE dispMode; D3DPRESENT_PARAMETERS presentParams; m_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 = m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, NULL, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentParams, &m_pD3DDevice); if (FAILED(hr)) { printf("Cannot init D3D device: %08x\n", hr); m_pD3D->Release(); return false; } return true; }
HRESULT RacorX5::OneTimeSceneInit() { IDirect3D8* d3d = Direct3DCreate8(D3D_SDK_VERSION); if (d3d == nullptr) { MessageBox(m_hWnd, L"Direct3DCreate8 failed!", L"Error", 0); return E_FAIL; } m_spD3D.reset(d3d, [](IDirect3D8* d3d) { d3d->Release(); }); m_spD3D->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &m_D3DCaps); D3DXMatrixPerspectiveFovLH(&m_mtProj, D3DX_PI*0.5, static_cast<float>(m_iWidth) / m_iHeight, m_fObjectRadius / 64.0f, m_fObjectRadius*200.0f); D3DXMatrixTranslation(&m_mtWorld, -m_vObjectCenter.x, -m_vObjectCenter.x, -m_vObjectCenter.x); m_ArcBall.SetWindow(m_iWidth, m_iHeight, 0.85f); m_ArcBall.SetRadius(m_fObjectRadius); m_Viewport = { 0, 0, m_iWidth, m_iHeight }; m_spBPatch = std::make_shared<CD3DBPatch>(); m_vLightColor[0] = D3DXVECTOR4(0.3f, 0.1f, 0.1f, 1.0f); m_vLightColor[1] = D3DXVECTOR4(0.1f, 0.5f, 0.1f, 1.0f); m_vLightColor[2] = D3DXVECTOR4(0.0f, 0.1f, 0.4f, 1.0f); return S_OK; }
//----------------------------------------------------------------------------- // 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; }
Export int DX8Init(HWND Window) { Global = new DX8FXGlobal(); SoftFX::Load(); Global->D3D = Direct3DCreate8(D3D_SDK_VERSION); Global->Window = Window; InstallOverrides(); return (Global->D3D != 0); }
void MFRenderer_InitModulePlatformSpecific() { // create D3D interface d3d8 = Direct3DCreate8(D3D_SDK_VERSION); if(!d3d8) MFDebug_Assert(false ,"Unable to Create the D3D Device."); d3d8->GetDeviceCaps(0, D3DDEVTYPE_HAL, &deviceCaps); }
//--------------------------------------------------------------------- // Function: CDX8RenderCore // Description: Constructor // Parameters: objMan = pointer to external object manager // Returns: . //--------------------------------------------------------------------- BOOL CDX8RenderCore::Initialize() { // Create new Direct3D object m_pD3D = Direct3DCreate8( D3D_SDK_VERSION ); if (m_pD3D == NULL) { m_LastError = D3DERR_NOTAVAILABLE; gLogger->Print(_T("Unable to Create DirectX 8 3D object")); return FALSE; } return TRUE; }
HRESULT HelloShadowVolume::OneTimeSceneInit() { IDirect3D8* d3d = Direct3DCreate8(D3D_SDK_VERSION); if (!d3d) { MessageBox(0, L"Direct3DCreate8 error", 0, 0); return E_FAIL; } m_spD3D.reset(d3d, [](IDirect3D8* d3d) { d3d->Release(); }); return S_OK; }
bool CScene::initDirectX() { //First of all, create the main D3D object. If it is created successfully we //should get a pointer to an IDirect3D8 interface. g_pD3D = Direct3DCreate8(D3D_SDK_VERSION); if(g_pD3D == NULL) { return false; } //Get the current display mode D3DDISPLAYMODE d3ddm; if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm))) { return false; } //Create a structure to hold the settings for our device D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); //Fill the structure. //We want our program to be windowed, and set the back buffer to a format //that matches our current display mode d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC; d3dpp.BackBufferFormat = d3ddm.Format; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; d3dpp.EnableAutoDepthStencil = TRUE; //Create a Direct3D device. if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice))) { return false; } // Turn on back face culling. This is because we want to hide the back of our polygons g_pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); // Turn off lighting becuase we are specifying that our vertices have colour g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE); // Turn on depth-buffering g_pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); dxInit = true; return true; }
int32 CRenderLib::m_CreateDevice(int32 type) { HRESULT hr; p_D3D = Direct3DCreate8(D3D_SDK_VERSION); if (type==HARDWARE_DEVICE) p_DeviceType=D3DDEVTYPE_HAL; else if (type==SOFTWARE_DEVICE) p_DeviceType=D3DDEVTYPE_REF; hr=p_D3D->GetDeviceCaps(D3DADAPTER_DEFAULT, p_DeviceType, &p_DeviceInfo.Caps); if (hr != D3D_OK) return(0); // ---------- il device puo' disegnare in finestra ------------ if (p_DeviceInfo.Caps.Caps2 & D3DCAPS2_CANRENDERWINDOWED) p_DeviceInfo.CanDoWindowed=TRUE; else p_DeviceInfo.CanDoWindowed=FALSE; if (type==SOFTWARE_DEVICE) { p_DeviceInfo.Behavior=D3DCREATE_SOFTWARE_VERTEXPROCESSING; p_VSHardwareSupport=0; } else { // ----------- T&L e capacità di processo dei vertici ----------- if (p_DeviceInfo.Caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) { if (p_DeviceInfo.Caps.VertexShaderVersion >= D3DVS_VERSION(1, 1)) { // if (p_DeviceInfo.Caps.DevCaps & D3DDEVCAPS_PUREDEVICE) p_DeviceInfo.Behavior=D3DCREATE_HARDWARE_VERTEXPROCESSING; //| D3DCREATE_PUREDEVICE; p_VSHardwareSupport=(1<<16) | (1); } else { p_DeviceInfo.Behavior=D3DCREATE_MIXED_VERTEXPROCESSING; p_VSHardwareSupport=0; } } else { p_DeviceInfo.Behavior=D3DCREATE_SOFTWARE_VERTEXPROCESSING; p_VSHardwareSupport=0; } } p_IsDeviceCreated=1; return(1); }
int GameInit(){ HRESULT r = 0;//return values g_pD3D = Direct3DCreate8(D3D_SDK_VERSION);//COM object if( g_pD3D == NULL){ SetError("Could not create IDirect3D8 object"); return E_FAIL; } r = InitDirect3DDevice(g_hWndMain, 640, 480, FALSE, D3DFMT_X8R8G8B8, g_pD3D, &g_pDevice); if(FAILED(r)){//FAILED is a macro that returns false if return value is a failure - safer than using value itself SetError("Initialization of the device failed"); return E_FAIL; } return S_OK; }
void InitD3D() { ShutdownD3D(); RECT rcClient; GetClientRect( g_hWnd, &rcClient ); g_ScreenWidth = rcClient.right - rcClient.left; g_ScreenHeight = rcClient.bottom - rcClient.top; // Initialize D3D. g_pDirect3D = Direct3DCreate8( D3D_SDK_VERSION ); // Get the current desktop display mode, so we can set up a back // buffer of the same format D3DDISPLAYMODE d3ddm; g_pDirect3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ); // Set up the structure used to create the D3DDevice ZeroMemory( &d3dpp, sizeof(d3dpp) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = d3ddm.Format; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; HRESULT hr = g_pDirect3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pDevice); if( FAILED(hr) ) { Sys_Error( "CreateDevice failed (%s)", DXGetErrorString8(hr) ); } g_pDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); g_pDevice->SetRenderState( D3DRS_LIGHTING, FALSE ); }
//----------------------------------------------------------------------------- // Name: Create() // Desc: Create the app //----------------------------------------------------------------------------- HRESULT CXBApplication::Create() { HRESULT hr; // Create the Direct3D object // OUTPUT_DEBUG_STRING( "XBApp: Creating Direct3D...\n" ); if( NULL == ( m_pD3D = Direct3DCreate8(D3D_SDK_VERSION) ) ) { // OUTPUT_DEBUG_STRING( "XBApp: Unable to create Direct3D!\n" ); return E_FAIL; } // Create the device // OUTPUT_DEBUG_STRING( "XBApp: Creating the D3D device...\n" ); if( FAILED( hr = m_pD3D->CreateDevice( 0, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &m_d3dpp, &m_pd3dDevice ) ) ) { // OUTPUT_DEBUG_STRING( "XBApp: Could not create D3D device!\n" ); return hr; } // Allow global access to the device g_pd3dDevice = m_pd3dDevice; // Store pointers to the depth and back buffers m_pd3dDevice->GetDepthStencilSurface( &m_pDepthBuffer ); m_pd3dDevice->GetBackBuffer( 0, 0, &m_pBackBuffer ); // Initialize core peripheral port support. Note: If these parameters // are 0 and NULL, respectively, then the default number and types of // controllers will be initialized. XInitDevices( m_dwNumInputDeviceTypes, m_InputDeviceTypes ); // Initialize the app's device-dependent objects // OUTPUT_DEBUG_STRING( "XBApp: Initializing the app...\n" ); if( FAILED( hr = Initialize() ) ) { // OUTPUT_DEBUG_STRING( "XBApp: Call to Initialize() failed!\n" ); return hr; } return S_OK; }
HRESULT CRacorX::OneTimeSceneInit() { IDirect3D8* d3d = Direct3DCreate8(D3D_SDK_VERSION); m_spD3D.reset(d3d, [](IDirect3D8* d3d) { d3d->Release(); }); m_spD3D->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &m_D3DCaps); m_Viewport = { 0, 0, m_iWidth, m_iHeight }; D3DXVECTOR3 eye = { 0.0f, 0.0f, -200.0f }; D3DXVECTOR3 target = { 0.0f, 0.0f, 0.0f }; D3DXVECTOR3 up = { 0.0f, 1.0f, 0.0f }; D3DXMatrixLookAtLH(&m_mtView, &eye, &target, &up); float aspect = static_cast<float>(m_iWidth) / m_iHeight; D3DXMatrixPerspectiveFovLH(&m_mtProj, D3DX_PI*0.5, aspect, 1.0f, 1000.0f); D3DXMatrixIdentity(&m_mtWorld); return S_OK; }
void InitialiseD3D() { g_pD3D = Direct3DCreate8(D3D_SDK_VERSION); D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.BackBufferWidth = 640; d3dpp.BackBufferHeight = 480; d3dpp.BackBufferFormat = D3DFMT_LIN_X8R8G8B8; d3dpp.BackBufferCount = 1; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; g_pD3D->CreateDevice(0, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_pD3DDevice); g_pD3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE); g_pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); g_pD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); g_pD3DDevice->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_SELECTARG1); g_pD3DDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_DIFFUSE); g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORKEYOP, D3DTCOLORKEYOP_KILL); g_pD3DDevice->SetTextureStageState(0, D3DTSS_COLORKEYCOLOR, D3DCOLOR_XRGB( 150, 200, 250)); g_pD3DDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA); g_pD3DDevice->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_INVSRCALPHA); g_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE); g_pD3DDevice->SetTextureStageState(0,D3DTSS_MAGFILTER, D3DTEXF_ANISOTROPIC); g_pD3DDevice->SetTextureStageState(0,D3DTSS_MINFILTER, D3DTEXF_ANISOTROPIC); g_pD3DDevice->SetTextureStageState(0, D3DTSS_MAXANISOTROPY, 1 ); g_pD3DDevice->SetTextureStageState(0, D3DTSS_MIPMAPLODBIAS, *((LPDWORD)(&g_fMipMapLodBias))); g_pD3DDevice->SetTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_LINEAR); }
D3D::D3D(char *n,int w,int h){ Render=this; vb=new D3DVERTEX[256]; if(!vb) error("out of memory"); WNDCLASSEX wc={sizeof(WNDCLASSEX),CS_VREDRAW|CS_HREDRAW|CS_OWNDC,WndProc,0,0,hInst,0,0,0,0,n,0}; RegisterClassEx(&wc); hWnd=CreateWindowEx(WS_EX_APPWINDOW|WS_EX_TOPMOST,n,n,0,0,0,w,h,0,0,hInst,0); ShowWindow(hWnd,0); SetFocus(hWnd); ShowCursor(0); UpdateWindow(hWnd); d3d=Direct3DCreate8(D3D_SDK_VERSION); if(!d3d) error("can`t create d3d"); D3DDISPLAYMODE d3ddm; ZeroMemory(&d3ddm,sizeof(d3ddm)); d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddm); D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp,sizeof(d3dpp)); d3dpp.SwapEffect=D3DSWAPEFFECT_FLIP; d3dpp.BackBufferWidth=w; d3dpp.BackBufferHeight=h; d3dpp.BackBufferFormat=D3DFMT_A8R8G8B8; d3dpp.BackBufferCount=1; d3dpp.EnableAutoDepthStencil=1; d3dpp.AutoDepthStencilFormat=D3DFMT_D16; d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&d3dd); if(!d3dd) error("can`t create d3dd"); d3dd->SetVertexShader(D3DFVF_D3DVERTEX); d3dd->SetRenderState(D3DRS_LIGHTING,1); d3dd->SetRenderState(D3DRS_NORMALIZENORMALS,1); d3dd->SetRenderState(D3DRS_POINTSPRITEENABLE,1); d3dd->SetRenderState(D3DRS_POINTSCALEENABLE,1); d3dd->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE); d3dd->SetRenderState(D3DRS_ALPHABLENDENABLE,0); d3dd->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA); d3dd->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE); d3dd->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_BLENDDIFFUSEALPHA); d3dd->SetRenderState(D3DRS_ZWRITEENABLE,1); d3dd->SetRenderState(D3DRS_SHADEMODE,D3DSHADE_FLAT); d3dd->SetTexture(0,0); d3dd->SetTextureStageState(0,D3DTSS_MINFILTER,D3DTEXF_POINT); d3dd->SetTextureStageState(0,D3DTSS_MAGFILTER,D3DTEXF_POINT); }
//----------------------------------------------------------------------------- // 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; }
//----------------------------------------------------------------------------- // 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; }
//----------------------------------------------------------------------------- // Name: InitD3D() // Desc: Initializes Direct3D //----------------------------------------------------------------------------- HRESULT Renderer::InitD3D() { // Create the D3D object. if( nullptr == ( g_pD3D = Direct3DCreate8( D3D_SDK_VERSION ) ) ) return E_FAIL; // Set up the structure used to create the D3DDevice. D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( &d3dpp, sizeof(d3dpp) ); d3dpp.BackBufferWidth = 640; d3dpp.BackBufferHeight = 480; d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; d3dpp.BackBufferCount = 1; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // Create the Direct3D device. if( FAILED( g_pD3D->CreateDevice( 0, D3DDEVTYPE_HAL, nullptr, D3DCREATE_HARDWARE_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 ); g_pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE ); g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE ); //g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); //g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ); return S_OK; }
BOOL Init_DX( HWND hWnd ) { D3DPRESENT_PARAMETERS d3dpp; ZeroMemory ( &d3dpp, sizeof ( d3dpp ) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP; d3dpp.BackBufferWidth = SCREENWIDTH; d3dpp.BackBufferHeight = SCREENHEIGHT; d3dpp.BackBufferFormat = D3DFMT_R5G6B5; d3dpp.EnableAutoDepthStencil = TRUE; d3dpp.AutoDepthStencilFormat = D3DFMT_D16; lpD3D = Direct3DCreate8 ( D3D_SDK_VERSION ) ; if( FAILED( lpD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &lpDevice ) ) ) { d3dpp.BackBufferFormat = D3DFMT_X1R5G5B5; if ( FAILED ( lpD3D->CreateDevice ( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &lpDevice ) ) ) return false; } D3DCAPS8 DevCaps; ZeroMemory( &DevCaps, sizeof ( D3DCAPS8 ) ); lpDevice->GetDeviceCaps ( &DevCaps ); return TRUE; }
HRESULT RacorX8::OneTimeSceneInit() { IDirect3D8* d3d = Direct3DCreate8(D3D_SDK_VERSION); if (d3d == nullptr) { MessageBox(m_hWnd, L"Direct3DCreate8 failed!", L"Error", 0); return E_FAIL; } m_spD3D.reset(d3d, [](IDirect3D8* d3d) { d3d->Release(); }); m_spD3D->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &m_D3DCaps); D3DXMatrixPerspectiveFovLH(&m_mtProj,0.55f, static_cast<float>(m_iWidth) / m_iHeight, 1.0f, 10000.0f); //D3DXMatrixTranslation(&m_mtWorld, -m_vObjectCenter.x, -m_vObjectCenter.x, -m_vObjectCenter.x); D3DXMatrixIdentity(&m_mtWorld); D3DXMatrixRotationX(&m_mtWorld, D3DX_PI / 2); m_ArcBall.SetWindow(m_iWidth, m_iHeight, 0.85f); m_ArcBall.SetRadius(m_fObjectRadius); m_Viewport = { 0, 0, m_iWidth, m_iHeight }; return S_OK; }
void JRenderServer::Init() { m_hWnd = (HWND)g_pWindowServer->GetRootHandle(); if (m_bInited) return; SetName( "render" ); rlog.msg( "Creating d3d8 render device..." ); m_pD3D = Direct3DCreate8( D3D_SDK_VERSION ); if (m_pD3D == NULL) { rlog.err( "Could not initialize d3d8." ); return; } D3DDISPLAYMODE d3ddm; m_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm ); ZeroMemory( &m_PresParam, sizeof( m_PresParam ) ); JScreenMode mode = g_pWindowServer->GetScreenMode(); BOOL bWindowed = (mode == smWindow || mode == smDesktop); bool bHasStencil = true; m_PresParam.Windowed = bWindowed; m_PresParam.SwapEffect = bWindowed ? D3DSWAPEFFECT_COPY_VSYNC : D3DSWAPEFFECT_FLIP; m_PresParam.EnableAutoDepthStencil = TRUE; m_PresParam.AutoDepthStencilFormat = D3DFMT_D16; m_PresParam.BackBufferFormat = d3ddm.Format; m_PresParam.BackBufferCount = 1; m_PresParam.hDeviceWindow = m_hWnd; if (bHasStencil) { m_PresParam.AutoDepthStencilFormat = D3DFMT_D24S8; m_bHasStencil = true; } RECT cRect; GetClientRect( m_hWnd, &cRect ); m_PresParam.BackBufferWidth = cRect.right - cRect.left; m_PresParam.BackBufferHeight = cRect.bottom - cRect.top; DWORD flags = D3DCREATE_MIXED_VERTEXPROCESSING; D3DDEVTYPE devType = D3DDEVTYPE_HAL; rlog.msg( "Creating d3d8 render device..." ); /* // fixme: this takes precious startup time D3DADAPTER_IDENTIFIER8 adapterID; m_pD3D->GetAdapterIdentifier( 0, 0, &adapterID ); rlog.msg( "Adapter: %s", adapterID.Description ); rlog.msg( "Driver: %s, product: %d, ver: %d, subver: %d, build: %d", adapterID.Driver, HIWORD(adapterID.DriverVersion.HighPart), LOWORD(adapterID.DriverVersion.HighPart), HIWORD(adapterID.DriverVersion.LowPart), LOWORD(adapterID.DriverVersion.LowPart) ); rlog.msg( "Vendor ID: %d, Device ID: %d, Subsystem ID: %d, Revision: %d", adapterID.VendorId, adapterID.DeviceId, adapterID.SubSysId, adapterID.Revision ); */ // Create the D3DDevice HRESULT res = m_pD3D->CreateDevice( 0, devType, m_hWnd, flags, &m_PresParam, &m_pDevice ); if (!m_pDevice) { rlog.warn( "Could not create render device. Switching to software vertex processing." ); flags = D3DCREATE_SOFTWARE_VERTEXPROCESSING; res = m_pD3D->CreateDevice( 0, devType, m_hWnd, flags, &m_PresParam, &m_pDevice ); if (!m_pDevice) { rlog.err( "Could not create render device. %s", GetDXError( res ) ); return; } } rlog.msg( "Render device created OK." ); SAFE_RELEASE( m_pBackBuffer ); SAFE_RELEASE( m_pDepthStencil ); m_pDevice->GetBackBuffer( 0, D3DBACKBUFFER_TYPE_MONO, &m_pBackBuffer ); m_pDevice->GetDepthStencilSurface( &m_pDepthStencil ); m_bInited = true; // register stock vertex types for (int vtype = VertexType_Unknown; vtype < VertexType_Last; vtype++) { int typeID = GetVDeclID( GetStockVDecl( (VertexType)vtype ) ); assert( typeID == vtype ); } CreateQuadIB(); } // JRenderServer::Init
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); if( FAILED(ret) ){ D3DMain.m_FullScreenOnly = TRUE; } } if(D3DMain.m_FullScreenOnly==TRUE){ RELEASE_3D(pD3DDevice); D3DMain.m_WindowMode = FALSE; ZeroMemory(&d3dppApp,sizeof(d3dppApp)); 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: case D3DFMT_A1R5G5B5: case D3DFMT_A4R4G4B4: case D3DFMT_X4R4G4B4: D3DCapsStruct.m_FullModeNum=i; d3dppApp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER; d3dppApp.Windowed = D3DMain.m_WindowMode; d3dppApp.SwapEffect = FULL_FLIP; d3dppApp.BackBufferFormat = D3DCapsStruct.m_DisplayMode[i].Format; d3dppApp.BackBufferCount = 1; d3dppApp.BackBufferWidth = WinWidth; d3dppApp.BackBufferHeight = WinHeight; break; } } if(d3dppApp.SwapEffect) break; } if(!full){ wsprintf( buf, "このビデオカードの現在のモードではゲームを実行できません。フルスクリーン化しますか?\n[%d]", D3DCapsStruct.m_DisplayMode[i].RefreshRate ); if( MessageBox( NULL, buf, "問い合わせ", MB_YESNO )==IDNO ){ RELEASE_3D(pD3D); return FALSE; } } 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); if( FAILED(ret) ){ switch(ret){ default: case D3DERR_OUTOFVIDEOMEMORY: DebugBox( NULL, "Direct3D が処理を行うのに十分なディスプレイ メモリがありません。" ); RELEASE_3D(pD3D); return FALSE; case D3DERR_INVALIDCALL: DebugBox( NULL, "Direct3Dの初期化に失敗しました[D3DERR_INVALIDCALL]\nこのグラフィックカードは必要な機能をサポートしていないか、\nあるいはDirectX8に対応したドライバが入っていません。" ); RELEASE_3D(pD3D); return FALSE; case D3DERR_NOTAVAILABLE: DebugBox( NULL, "Direct3Dの初期化に失敗しました[D3DERR_NOTAVAILABLE]\nこのグラフィックカードは必要な機能をサポートしていないか、\nあるいはDirectX8に対応したドライバが入っていません。" ); RELEASE_3D(pD3D); return FALSE; } } } }else{ if(D3DMain.m_WindowMode){ }else{ RELEASE_3D(pD3DDevice); ZeroMemory(&d3dppApp,sizeof(d3dppApp)); d3dppApp.SwapEffect = FULL_FLIP; d3dppApp.BackBufferCount = 1; d3dppApp.BackBufferWidth = WinWidth; d3dppApp.BackBufferHeight = WinHeight; d3dppApp.Windowed = FALSE; d3dppApp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER; 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: case D3DFMT_A1R5G5B5: case D3DFMT_A4R4G4B4: case D3DFMT_X4R4G4B4: D3DCapsStruct.m_FullModeNum=i; d3dppApp.BackBufferFormat = D3DCapsStruct.m_DisplayMode[i].Format; break; } } if(d3dppApp.BackBufferFormat!=D3DFMT_UNKNOWN) break; } }else{ d3dppApp.BackBufferFormat = D3DCapsStruct.m_NowDisplayMode.Format; } 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); if( FAILED(ret) ){ switch(ret){ default: case D3DERR_OUTOFVIDEOMEMORY: DebugBox( NULL, "Direct3D が処理を行うのに十分なディスプレイ メモリがありません。" ); RELEASE_3D(pD3D); return FALSE; case D3DERR_INVALIDCALL: DebugBox( NULL, "Direct3Dの初期化に失敗しました[D3DERR_INVALIDCALL]\nこのグラフィックカードは必要な機能をサポートしていないか、\nあるいはDirectX8に対応したドライバが入っていません。" ); RELEASE_3D(pD3D); return FALSE; case D3DERR_NOTAVAILABLE: DebugBox( NULL, "Direct3Dの初期化に失敗しました[D3DERR_NOTAVAILABLE]\nこのグラフィックカードは必要な機能をサポートしていないか、\nあるいはDirectX8に対応したドライバが入っていません。" ); RELEASE_3D(pD3D); return FALSE; } } } } } if( FAILED(pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&D3DCapsStruct.m_NowDisplayMode)) ){ MessageBox(NULL,"ディスプレイモードの取得に失敗しました。[なにゆえ?]","致命的なエラー", MB_OK | MB_ICONSTOP); RELEASE_3D(pD3D); return FALSE; } D3DCapsStruct.m_ttCaps.m_R8G8B8 = IsTextureFormatOk( D3DFMT_R8G8B8, D3DCapsStruct.m_NowDisplayMode.Format); D3DCapsStruct.m_ttCaps.m_X8R8G8B8 = IsTextureFormatOk( D3DFMT_X8R8G8B8, D3DCapsStruct.m_NowDisplayMode.Format); D3DCapsStruct.m_ttCaps.m_A8R8G8B8 = IsTextureFormatOk( D3DFMT_A8R8G8B8, D3DCapsStruct.m_NowDisplayMode.Format); D3DCapsStruct.m_ttCaps.m_R5G6B5 = IsTextureFormatOk( D3DFMT_R5G6B5, D3DCapsStruct.m_NowDisplayMode.Format); D3DCapsStruct.m_ttCaps.m_X1R5G5B5 = IsTextureFormatOk( D3DFMT_X1R5G5B5, D3DCapsStruct.m_NowDisplayMode.Format); D3DCapsStruct.m_ttCaps.m_A1R5G5B5 = IsTextureFormatOk( D3DFMT_A1R5G5B5, D3DCapsStruct.m_NowDisplayMode.Format); D3DCapsStruct.m_ttCaps.m_X4R4G4B4 = IsTextureFormatOk( D3DFMT_X4R4G4B4, D3DCapsStruct.m_NowDisplayMode.Format); D3DCapsStruct.m_ttCaps.m_A4R4G4B4 = IsTextureFormatOk( D3DFMT_A4R4G4B4, D3DCapsStruct.m_NowDisplayMode.Format); D3DCapsStruct.m_ttCaps.m_A8P8 = IsTextureFormatOk( D3DFMT_A8P8, D3DCapsStruct.m_NowDisplayMode.Format); D3DCapsStruct.m_ttCaps.m_P8 = IsTextureFormatOk( D3DFMT_P8, D3DCapsStruct.m_NowDisplayMode.Format); D3DCapsStruct.m_ttCaps.m_A8 = IsTextureFormatOk( D3DFMT_A8, D3DCapsStruct.m_NowDisplayMode.Format); D3DD_SetBackBuffer( WinWidth, WinHeight ); pD3DDevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_ARGB(0,0,0,0),1.0,0); if(0){ char buf2[512]; wsprintf( buf, "実行ディスプレイモード[%s]\n", TxFmtMode[ LIM(d3dppApp.BackBufferFormat,0,D3DFMT_D3DD_MAX-1) ] ); MBS_CPY(buf2,buf); MBS_CAT(buf2,"使用可能テクスチャ列挙\n"); for(i=1;i<D3DFMT_D3DD_MAX-1;i++){ if( TxFmtMode[i] ){ j = IsTextureFormatOk( (D3DFORMAT)i, D3DCapsStruct.m_NowDisplayMode.Format); if(j){ wsprintf(buf,"%-15s[%s]\n", TxFmtMode[i], (j==2)?"OK":"OK(NotRenderTarget)" ); MBS_CAT(buf2,buf); }else{ wsprintf(buf,"%-15s[%s]\n", TxFmtMode[i], "--Not--" ); MBS_CAT(buf2,buf); } } } DebugBox(NULL,buf2); } D3DD_CreateTable(); return TRUE; }
//******* // 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; }
ZED_UINT32 XboxRenderer::Create( GraphicsAdapter *p_Adapter, const CanvasDescription &p_Canvas ) { ZED_UINT32 ReturnStatus = ZED_FAIL; if( NULL ==( m_pD3D = Direct3DCreate8( D3D_SDK_VERSION ) ) ) { return ZED_FAIL; } m_Canvas = p_Canvas; m_PresentParams.BackBufferWidth = m_Canvas.GetWidth( ); m_PresentParams.BackBufferHeight = m_Canvas.GetHeight( ); m_PresentParams.BackBufferCount = m_Canvas.GetBackBufferCount( ); m_PresentParams.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // Get the colour switch( m_Canvas.GetBPP( ) ) { case ZED_FORMAT_ARGB8: { m_PresentParams.BackBufferFormat = D3DFMT_A8R8G8B8; ReturnStatus = ZED_OK; break; } default: { zedTrace( "Failed to set the back buffer format" ); return ZED_FAIL; } } // Get the Depth/Stencil switch( m_Canvas.GetDepthStencil( ) ) { case ZED_FORMAT_D24S8: { m_PresentParams.EnableAutoDepthStencil = ZED_TRUE; m_PresentParams.AutoDepthStencilFormat = D3DFMT_D24S8; ReturnStatus = ZED_OK; break; } default: { zedTrace( "Failed to set the depth/stencil format" ); return ZED_FAIL; } } // This needs to be exposed, but how? m_PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD; if( FAILED( m_pD3D->CreateDevice( 0, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &m_PresentParams, &m_pDevice ) ) ) { zedTrace( "Failed to create device" ); return ZED_FAIL; } #ifdef ZED_BUILD_DEBUG ZED_UINT32 ModeCount = m_pD3D->GetAdapterModeCount( D3DADAPTER_DEFAULT ); D3DDISPLAYMODE *pModes = new D3DDISPLAYMODE[ ModeCount ]; for( ZED_MEMSIZE i = 0; i < ModeCount; i++ ) { if( FAILED( m_pD3D->EnumAdapterModes( D3DADAPTER_DEFAULT, i, &pModes[ i ] ) ) ) { delete pModes; return ZED_FAIL; } ZED_MEMSIZE Len = strlen( FlagsToString( pModes[ i ].Flags ) ); char *pFlags; if( Len > 0 ) { pFlags = new char[ Len ]; strncpy( pFlags, FlagsToString( pModes[ i ].Flags ), Len-1 ); pFlags[ Len-1 ] = '\0'; } if( Len == 0 ) { // Add one for null-termination Len = strlen( "NO FLAGS" )+1; pFlags = new char[ Len ]; strncpy( pFlags, "NO FLAGS", Len ); } // Print out the adapter's capabilities zedTrace( "Mode %d:\n" "\tWidth: %d | Height: %d | Refresh Rate: %d | Flags: %s \n", i, pModes[ i ].Width, pModes[ i ].Height, pModes[ i ].RefreshRate, pFlags ); delete pFlags; } #endif return ReturnStatus; }
void CRenderCriticalSection::Reaction( long in_SrcSectionID, const CRenderCriticalSection_Get3DEnvironmentInfo& in_rGetInfo ) { CLog::Print("CRenderCriticalSection::Reaction( const CRenderCriticalSection_Get3DEnvironmentInfo& in_rGetInfo )\n"); assert(m_HWnd!=NULL); CRenderCriticalSection_3DEnvironmentInfo Collected3DInfo; Collected3DInfo.m_bError = true; // will be set to false after successfull 3d info query bool Have16bitModes = false; bool Have32bitModes = false; do { IDirect3D8* pD3D8 = (m_pD3D8!=NULL) ? m_pD3D8 : Direct3DCreate8( D3D_SDK_VERSION ); CLocalD3D8Holder LocalD3D8Holder( (m_pD3D8!=NULL) ? NULL : pD3D8 ); if(NULL==pD3D8) { break; } HRESULT res; // debug name D3DADAPTER_IDENTIFIER8 Ident; res = pD3D8->GetAdapterIdentifier( D3DADAPTER_DEFAULT, D3DENUM_NO_WHQL_LEVEL, &Ident ); if(res!=D3D_OK) { break; } CLog::Print(" Primary display adapter name:\n"); CLog::Print(" '%s'\n",Ident.Description); // fill in m_DisplayModes UINT NModes = pD3D8->GetAdapterModeCount( D3DADAPTER_DEFAULT ); CLog::Print(" Primary display adapter has %u modes.\n", NModes); Collected3DInfo.m_DisplayModes.reserve(NModes); D3DDISPLAYMODE DisplayMode; for( UINT i=0; i<NModes; ++i ) { HRESULT res = pD3D8->EnumAdapterModes(D3DADAPTER_DEFAULT,i,&DisplayMode); assert( D3D_OK == res ); char Buffer[1024]; sprintf(Buffer, " %ux%u, %u hertz, ", DisplayMode.Width, DisplayMode.Height, DisplayMode.RefreshRate); strcat(Buffer,DisplayFormatToString(DisplayMode.Format)); CLog::Print("%s\n",Buffer); // RENDER_DISPLAY_MODE_FORMAT RDMFormat = DisplayFormatToRDMF(DisplayMode.Format); if( RDMFormat!=RDMF_UNKNOWN ) { Have16bitModes |= (RDMFormat==RDMF_R5G6B5); Have32bitModes |= (RDMFormat==RDMF_X8R8G8B8); Collected3DInfo.m_DisplayModes.push_back( CRenderDisplayMode( DisplayMode.Width, DisplayMode.Height, DisplayMode.RefreshRate, RDMFormat ) ); } } // fill in m_CanRenderWindowed and m_CurrentDisplayMode D3DCAPS8 Caps8; res = pD3D8->GetDeviceCaps(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,&Caps8); assert( D3D_OK == res ); CLog::Print(" D3DDEVCAPS_TLVERTEXSYSTEMMEMORY = %s\n",0!=(Caps8.DevCaps&D3DDEVCAPS_TLVERTEXSYSTEMMEMORY)?"YES":"no"); CLog::Print(" D3DDEVCAPS_TLVERTEXVIDEOMEMORY = %s\n",0!=(Caps8.DevCaps&D3DDEVCAPS_TLVERTEXVIDEOMEMORY)?"YES":"no"); CLog::Print(" MaxVertexIndex = %08x\n",Caps8.MaxVertexIndex); Collected3DInfo.m_CanRenderWindowed = 0!=(Caps8.Caps2&D3DCAPS2_CANRENDERWINDOWED); CLog::Print(" Primary display adapter %s render windowed.\n", Collected3DInfo.m_CanRenderWindowed?"CAN":"CANNOT"); CLog::Print(" MaxTextureBlendStages = %lu\n", Caps8.MaxTextureBlendStages); CLog::Print(" MaxSimultaneousTextures = %lu\n", Caps8.MaxSimultaneousTextures); CLog::Print(" MaxVertexBlendMatrices = %lu\n", Caps8.MaxVertexBlendMatrices); CLog::Print(" MaxVertexBlendMatrixIndex = %lu\n", Caps8.MaxVertexBlendMatrixIndex); long VSHi = (Caps8.VertexShaderVersion>>8) & 0xff; long VSLo = (Caps8.VertexShaderVersion ) & 0xff; CLog::Print(" VertexShaderVersion = %d.%d\n", VSHi, VSLo); CLog::Print(" MaxVertexShaderConst = %lu\n", Caps8.MaxVertexShaderConst); long PSHi = (Caps8.PixelShaderVersion>>8) & 0xff; long PSLo = (Caps8.PixelShaderVersion ) & 0xff; CLog::Print(" PixelShaderVersion = %d.%d\n", PSHi, PSLo); CLog::Print(" MaxPixelShaderValue = %f\n", Caps8.MaxPixelShaderValue); res = pD3D8->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&DisplayMode); RENDER_DISPLAY_MODE_FORMAT RDMFormat = DisplayFormatToRDMF(DisplayMode.Format); assert( RDMFormat != RDMF_UNKNOWN ); char Buffer[1024]; sprintf(Buffer, "%ux%u, %u hertz, ", DisplayMode.Width, DisplayMode.Height, DisplayMode.RefreshRate); strcat(Buffer,DisplayFormatToString(DisplayMode.Format)); CLog::Print(" Current display mode: %s\n",Buffer); Collected3DInfo.m_CurrentDisplayMode = CRenderDisplayMode( DisplayMode.Width, DisplayMode.Height, DisplayMode.RefreshRate, RDMFormat ); if(RDMFormat==RDMF_R5G6B5) { assert(Have16bitModes); } else // RDMFormat==RDMF_X8R8G8B8 { assert(Have32bitModes); } // fill in depth buffer flags if(Have16bitModes) { CLog::Print(" 16bit:\n"); Collected3DInfo.m_16Depth = ( D3D_OK == pD3D8->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_R5G6B5, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D16) ); CLog::Print(" Depth = %s\n",Collected3DInfo.m_16Depth?"YES":"no"); Collected3DInfo.m_16DepthStencil = false; // 16bit modes support only 1bit stencil, which is crap. CLog::Print(" DepthStencil = %s\n",Collected3DInfo.m_16DepthStencil?"YES":"no"); } if(Have32bitModes) { CLog::Print(" 32bit:\n"); Collected3DInfo.m_32Depth = ( D3D_OK==pD3D8->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D32) ) || ( D3D_OK==pD3D8->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X8) ); CLog::Print(" Depth = %s\n",Collected3DInfo.m_32Depth?"YES":"no"); Collected3DInfo.m_32DepthStencil = ( D3D_OK==pD3D8->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24S8) ) || ( D3D_OK==pD3D8->CheckDeviceFormat( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24X4S4) ); CLog::Print(" DepthStencil = %s\n",Collected3DInfo.m_32DepthStencil?"YES":"no"); } pD3D8->Release(); Collected3DInfo.m_bError = false; } while(false); CTCommandSender<CRenderCriticalSection_3DEnvironmentInfo>::SendCommand( in_SrcSectionID, Collected3DInfo ); CLog::Print("CRenderCriticalSection::Reaction( const CRenderCriticalSection_Get3DEnvironmentInfo& in_rGetInfo ) end\n"); }
void CRenderCriticalSection::Reaction( long in_SrcSectionID, const CRenderSection_InitRender& in_rInit ) { CLog::Print("CRenderCriticalSection::Reaction( const CRenderSection_InitRender& in_rInit )\n"); CLog::Print(" width = %lu\n",in_rInit.m_DX); CLog::Print(" height = %lu\n",in_rInit.m_DY); CLog::Print(" windowed = %s\n",in_rInit.m_bWindowed?"yes":"no"); CLog::Print(" depth = %s\n",in_rInit.m_bDepthBufferRequired?"yes":"no"); CLog::Print(" stencil = %s\n",in_rInit.m_bStencilBufferRequired?"yes":"no"); CLog::Print(" refresh = %lu\n",in_rInit.m_FullscreenRefreshRate); CLog::Print(" vsync = %s\n",in_rInit.m_bVSync?"yes":"no"); assert(m_pD3D8==NULL); assert(m_HWnd!=NULL); assert(in_rInit.m_bWindowed); // TODO: fullscreen initialization D3DFORMAT BackBufferFormat; bool Ok = false; RENDER_VERTEX_PROCESS_TYPE VertexProcessingType = RVP_UNKNOWN; do { m_pD3D8 = Direct3DCreate8( D3D_SDK_VERSION ); assert(m_pD3D8!=NULL); if(in_rInit.m_bWindowed) { D3DDISPLAYMODE Mode; HRESULT Res = m_pD3D8->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &Mode ); assert(Res==D3D_OK); BackBufferFormat = Mode.Format; } else { assert(2==5); // TODO } if( TryToCreateDevice( in_rInit, BackBufferFormat, RVP_HARDWARE ) ) VertexProcessingType = RVP_HARDWARE; else { if( TryToCreateDevice( in_rInit, BackBufferFormat, RVP_SOFTWARE ) ) VertexProcessingType = RVP_SOFTWARE; else { assert(false); } } Ok = true; } while(false); if(!Ok) { ReleaseRenderObjects(); } CTCommandSender<CRenderCriticalSection_InitRenderResult>::SendCommand( in_SrcSectionID, CRenderCriticalSection_InitRenderResult( Ok ? IRR_OK : IRR_FAIL, Ok ? m_pD3D8 : NULL, Ok ? m_pD3D8Device : NULL, Ok ? VertexProcessingType : RVP_UNKNOWN, Ok ? BackBufferFormat : D3DFMT_UNKNOWN ) ); }
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); pD3D->Release(); return 1; } char HomeDir[MAX_PATH]; GetCurrentDirectory(MAX_PATH, HomeDir); XPRFile.OutputBuf = (char*)VirtualAlloc(0, 64 * 1024 * 1024, MEM_RESERVE, PAGE_NOACCESS); if (!XPRFile.OutputBuf) { printf("Memory allocation failure: %08x\n", GetLastError()); pD3DDevice->Release(); pD3D->Release(); return 1; } Bundler.StartBundle(); // Scan the input directory (or current dir if false) for media files ConvertDirectory(InputDir, NULL, MaxMSE); VirtualFree(XPRFile.OutputBuf, 0, MEM_RELEASE); pD3DDevice->Release(); pD3D->Release(); SetCurrentDirectory(HomeDir); DWORD attr = GetFileAttributes(OutputFilename); if (attr != -1 && (attr & FILE_ATTRIBUTE_DIRECTORY)) { SetCurrentDirectory(OutputFilename); OutputFilename = "Textures.xpr"; } printf("\nWriting bundle: %s", OutputFilename); int BundleSize = Bundler.WriteBundle(OutputFilename, NoProtect); if (BundleSize == -1) { printf("\nERROR: %08x\n", GetLastError()); return 1; } printf("\nUncompressed texture size: %6dkB\nCompressed texture size: %8dkB\nBundle size: %8dkB\n\nWasted Pixels: %u/%u (%5.2f%%)\n", (UncompressedSize + 1023) / 1024, (((CompressedSize + 1023) / 1024) + 3) & ~3, (BundleSize + 1023) / 1024, TotalDstPixels - TotalSrcPixels, TotalDstPixels, 100.f * (float)(TotalDstPixels - TotalSrcPixels) / (float)TotalDstPixels); return 0; }