static void test_create_line(IDirect3DDevice9* device) { HRESULT hr; LPD3DXLINE line = NULL; LPDIRECT3DDEVICE9 return_device; D3DXMATRIX world, identity, result; FLOAT r11, r12, r13, r14; ULONG ref; /* Arbitrary values for matrix tests. */ r11 = 0.1421; r12 = 0.2114; r13 = 0.8027; r14 = 0.4587; hr = D3DXCreateLine(NULL, &line); ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL); hr = D3DXCreateLine(device, NULL); ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL); hr = D3DXCreateLine(device, &line); ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr); if (FAILED(hr)) { return; } hr = ID3DXLine_GetDevice(line, NULL); ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL); hr = ID3DXLine_GetDevice(line, &return_device); ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK); ok(return_device == device, "Expected line device %p, got %p\n", device, return_device); D3DXMatrixIdentity(&world); D3DXMatrixIdentity(&identity); S(U(world))._11 = r11; S(U(world))._12 = r12; S(U(world))._13 = r13; S(U(world))._14 = r14; hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, &world); ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK); hr = ID3DXLine_Begin(line); ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK); hr = IDirect3DDevice9_GetTransform(device, D3DTS_WORLD, &result); ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK); expect_mat(&identity, &result); hr = ID3DXLine_End(line); ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK); hr = IDirect3DDevice9_GetTransform(device, D3DTS_WORLD, &result); ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK); expect_mat(&world, &result); ref = IDirect3DDevice9_Release(return_device); ok(ref == 2, "Got %x references to device %p, expected 2\n", ref, return_device); ref = ID3DXLine_Release(line); ok(ref == 0, "Got %x references to line %p, expected 0\n", ref, line); }
ZeroLine::ZeroLine() { D3DXCreateLine(ZeroApp->GetDevice(), &line); D3DXCreateLine(ZeroApp->GetDevice(), &utilLine); line->SetAntialias(true); line->SetPatternScale(1.0f); utilLine->SetAntialias(true); utilLine->SetPatternScale(1.0f); lineWidth = -1; lineHeight = -1; }
void Drawer::Load() { m_vertices = new D3DXVECTOR2[(RenderDeviceManager::ResolutionWidth / TILESIZE + 2) * 2 + (RenderDeviceManager::ResolutionHeight / TILESIZE + 2) * 2]; PrepareGridVertices(); HRESULT hRes; hRes = D3DXCreateSprite(RenderDeviceManager::RenderDevice, &m_sprite); hRes = D3DXCreateLine(RenderDeviceManager::RenderDevice, &m_line); tilesOnScreenX = RenderDeviceManager::ResolutionWidth / TILESIZE; tilesOnScreenY = RenderDeviceManager::ResolutionHeight / TILESIZE; m_camPosXMin = 0; m_camPosYMin = -TILESIZE; m_camPosXMax = m_camPosXMin + WWIDTH * TILESIZE - RenderDeviceManager::ResolutionWidth; m_camPosYMax = m_camPosYMin + WHEIGHT * TILESIZE - RenderDeviceManager::ResolutionHeight + TILESIZE * 4; SetCamPosCenter(WWIDTH * TILESIZE / 2, WHEIGHT * TILESIZE / 2); // Font D3DXCreateFont(RenderDeviceManager::RenderDevice, 20, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Verdana", &m_font); UpdateMiniMap(); PrepareMinimapFrame(); }
void ZeroLine::ReloadResource() { line->Release(); utilLine->Release(); D3DXCreateLine(ZeroApp->GetDevice(), &line); D3DXCreateLine(ZeroApp->GetDevice(), &utilLine); line->SetAntialias(true); line->SetPatternScale(1.0f); utilLine->SetAntialias(true); utilLine->SetPatternScale(1.0f); if (lineWidth != -1) SetLineWidth(lineWidth); if (lineHeight != -1) SetLinePattern(lineHeight); }
/// <summary>Manages the creation of all resources required by this /// class to draw text.</summary> /// <params name="pDevice">LPDIRECT3DDEVICE9 to create data with. Must be /// the same device later used to render.</params> /// <returns>true if successful, false if failed.</returns> bool D3DDisplayManager::_CreateFont(LPDIRECT3DDEVICE9 pDevice){ // TODO: scale font size with resolution? if (!pFont) { // Create a font if we haven't already HRESULT hr = D3DXCreateFont(pDevice, 18, 0, FW_NORMAL, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), &pFont); if (FAILED(hr)) return false; } if (!pTitleFont) { HRESULT hr = D3DXCreateFont(pDevice, 20, 0, FW_BOLD, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), &pTitleFont); if (FAILED(hr)) return false; } if (!pFontSprite) { HRESULT hr = D3DXCreateSprite(pDevice, &pFontSprite); if (FAILED(hr)) return false; } if (!pLine) { HRESULT hr = D3DXCreateLine(pDevice, &pLine); if (FAILED(hr)) return false; pLine->SetAntialias(false); pLine->SetGLLines(true); } return true; }
void DirectxFunctions::DirectXInit(HWND hwnd) { if (FAILED(Direct3DCreate9Ex(D3D_SDK_VERSION, &DirectX.Object))) exit(1); ZeroMemory(&DirectX.Param, sizeof(DirectX.Param)); DirectX.Param.Windowed = true; DirectX.Param.BackBufferFormat = D3DFMT_A8R8G8B8; DirectX.Param.BackBufferHeight = Overlay.Height; DirectX.Param.BackBufferWidth = Overlay.Width; DirectX.Param.EnableAutoDepthStencil = true; DirectX.Param.AutoDepthStencilFormat = D3DFMT_D16; DirectX.Param.MultiSampleQuality = D3DMULTISAMPLE_NONE; DirectX.Param.SwapEffect = D3DSWAPEFFECT_DISCARD; if (FAILED(DirectX.Object->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &DirectX.Param, 0, &DirectX.Device))) exit(1); D3DXCreateFont(DirectX.Device, 16, 0, 0, 0, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Arial", &DirectX.Font); if (!DirectX.Line) D3DXCreateLine(DirectX.Device, &DirectX.Line); }
GameDebugDraw::GameDebugDraw(LPD3DXSPRITE spriteHandler) { mSpriteHandler = spriteHandler; mSpriteHandler->GetDevice(&mddv); D3DXCreateLine(mddv, &LineDraw); LineDraw->SetWidth(10); mColor = D3DCOLOR_XRGB(71, 85, 119); }
void CRenderManager::Initialize(HWND const _hWnd, int const _nScreenWidth, int const _nScreenHeight, bool const _bWindowed, bool const _bVSync) { if(!_hWnd) { MessageBox(0, "Handle to the window is invalid.", "Initialize", MB_OK); return; } if(m_pD3D9) { MessageBox(0, "CRenderManager has already been initialized.", "Initialize", MB_OK); return; } m_hWnd = _hWnd; m_nScreenWidth = _nScreenWidth; m_nScreenHeight = _nScreenHeight; m_bIsWindowed = _bWindowed; // Create the d3d object if(NULL == (m_pD3D9 = Direct3DCreate9(D3D_SDK_VERSION))) { MessageBox(0, "Failed to create the D3D Object.", "Initialize", MB_OK); return; } // Present Parameters m_PresentParameters.hDeviceWindow = m_hWnd; m_PresentParameters.BackBufferWidth = m_nScreenWidth; m_PresentParameters.BackBufferHeight = m_nScreenHeight; m_PresentParameters.Windowed = m_bIsWindowed; m_PresentParameters.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; m_PresentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD; // Create the Device if(FAILED(m_pD3D9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &m_PresentParameters, &m_pDevice))) { MessageBox(0, "Failed to create the Device.", "Initialize", MB_OK); return; } // Create the Sprite if(FAILED(D3DXCreateSprite(m_pDevice, &m_pSpriteManager))) { MessageBox(0, "Failed to create the Sprite Manager.", "Initialize", MB_OK); return; } // Create the line if(FAILED(D3DXCreateLine(m_pDevice, &m_pLine))) MessageBox(0, "Failed to create Line.", "Initialize", MB_OK); }
void DrawLine(float Bx, float By, float Ex, float Ey, int A, int R, int G, int B) { LPD3DXLINE line; D3DXCreateLine(d3ddev, &line); D3DXVECTOR2 lines[] = { D3DXVECTOR2(Bx, By), D3DXVECTOR2(Ex, Ey) }; line->Draw(lines, 2, D3DCOLOR_ARGB(A, R, G, B)); line->Release(); }
bool CLine::LoadResource(IDirect3DDevice9 *pDevice) { if(m_Line) { m_Line->Release(); m_Line = NULL; } D3DXCreateLine(pDevice,&m_Line); return m_Line != NULL; }
void CP3DDraw2D::Line_Draw(P3DVector2D *points, DWORD numPoints, unsigned long color) { if (!m_pLine) D3DXCreateLine(g_pD3DDevice, &m_pLine); if (m_bNeedSetWidth) { Line_End(); m_pLine->SetWidth((float)m_fLineWidth); Line_Begin(); m_bNeedSetWidth = false; } m_pLine->Draw((D3DXVECTOR2*)points, numPoints, color); // vykresli èáru }
bool DirectXT::SetupDirectX(HWND Handle, int Width, int Height) { Debug->Log(L"Setting up DirectX..."); Direct3DCreate9Ex(D3D_SDK_VERSION, &DX); if (DX) { ZeroMemory(&DXParams, sizeof(DXParams)); DXParams.Windowed = TRUE; DXParams.SwapEffect = D3DSWAPEFFECT_DISCARD; DXParams.hDeviceWindow = Handle; DXParams.MultiSampleQuality = D3DMULTISAMPLE_NONE; DXParams.BackBufferFormat = D3DFMT_A8R8G8B8; DXParams.BackBufferWidth = Width; DXParams.BackBufferHeight = Height; DXParams.EnableAutoDepthStencil = TRUE; DXParams.AutoDepthStencilFormat = D3DFMT_D16; DX->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Handle, D3DCREATE_HARDWARE_VERTEXPROCESSING, &DXParams, 0, &DXDevice); if (DXDevice) { D3DXCreateLine(DXDevice, &DXLine); if (DXLine) { D3DXCreateFont(DXDevice, 16, NULL, FW_SEMIBOLD, NULL, false, DEFAULT_CHARSET, OUT_TT_ONLY_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH, L"Arial", &DXFont); if (DXFont) { Debug->Log(L"DirectX setup was successful."); return true; } else { MessageBoxW(NULL, L"D3DXCreateFont Failed!", L"Fatal Error", MB_OK); return false; } } else { MessageBoxW(NULL, L"D3DXCreateLine Failed!", L"Fatal Error", MB_OK); return false; } } else { MessageBoxW(NULL, L"CreateDeviceEx Failed!", L"Fatal Error", MB_OK); return false; } } else { MessageBoxW(NULL, L"Direct3DCreate9Ex Failed!", L"Fatal Error", MB_OK); return false; } }
CBox2D::CBox2D(LPDIRECT3DDEVICE9 device, vector2d pos, vector2d size, vector2d velocity) { HRESULT hr = D3DXCreateLine(device, &m_line); if (FALSE(hr)) return; m_Position = pos; m_Size.x = size.x + deltaBoundingBox.x * 2; m_Size.y = size.y + deltaBoundingBox.y * 2; m_Velocity = velocity; }
CBox2D::CBox2D(LPDIRECT3DDEVICE9 device, RECT rectangle, vector2d velocity) { HRESULT hr = D3DXCreateLine(device, &m_line); if (FALSE(hr)) return; m_Position.x = rectangle.left; m_Position.y = rectangle.top; m_Size.x = rectangle.right - rectangle.left + deltaBoundingBox.x*2; m_Size.y = rectangle.top - rectangle.bottom + deltaBoundingBox.y*2; m_Velocity = velocity; }
void CDebug::InitLine() { D3DXCreateLine(m_pDevice, &m_Line); m_Line->SetWidth(1.5f); //두개(시작,끝)의 벡터를 갖는 라인 배열 //m_vList = new D3DXVECTOR3*[LOG_COUNT]; //m_ColorList = new D3DXCOLOR[LOG_COUNT]; //memset(&m_ColorList, 0, sizeof(m_ColorList[0]) * LOG_COUNT ); ////memset(&m_vList, 0, sizeof(m_vList[0])* LOG_COUNT ); //for( int i = 0; i < LOG_COUNT; ++i) //{ // m_vList[i] = new D3DXVECTOR3[2]; // // //memset(&m_vList, 0, sizeof(m_vList[0]) * LOG_COUNT * 2 ); //} }
BOOL CRender::Init(LPIDirect3DDevice9 pDevice) { // Init line CLog::Log(eLogType::HIGH, "> Creating D3D9X line handler"); if (D3DXCreateLine(pDevice, &pD3DLine) != S_OK) { CLog::Log(eLogType::HIGH, " > FAILED"); return E_FAIL; } pD3DLine->SetPattern(0xFFFFFFFF); pD3DLine->SetAntialias(TRUE); CLog::Log(eLogType::HIGH, " > SUCCESS [0x%p]", pD3DLine); // Init font if (SetFont(pDevice, "Arial", 16) != S_OK) return FALSE; return TRUE; }
InitDX9App::InitDX9App(HINSTANCE hInstance, std::wstring winCaption, D3DDEVTYPE devType, DWORD requestedVP) : D3DApp(hInstance, winCaption, devType, requestedVP) { srand(time_t(0)); D3DXFONT_DESC fontDesc; fontDesc.Height = 80; fontDesc.Width = 40; fontDesc.Weight = FW_BOLD; fontDesc.MipLevels = 0; fontDesc.Italic = true; fontDesc.CharSet = DEFAULT_CHARSET; fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS; fontDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; wcscpy_s(fontDesc.FaceName, LF_FACESIZE, L"Times New Roman"); HR(D3DXCreateFontIndirect(gd3dDevice, &fontDesc, &mFont)); HR(D3DXCreateLine(gd3dDevice, &mLine)); }
void CP3DDraw2D::Line_Begin() { if (!m_pLine) D3DXCreateLine(g_pD3DDevice, &m_pLine); m_pLine->Begin(); }
void LoadMapObjectResources(IDirect3DDevice9* Device) { D3DXCreateLine(Device, &line); }
bool nGraphics::InitGraphics() { // Create our base direct3d object m_pDirect3D = Direct3DCreate9(D3D_SDK_VERSION); if(!m_pDirect3D) { nMainFrame::LastError("Failed to create direct3d 9, directx 9 not installed?"); return TraceRet(__FUNCTION__" Failed to create direct3d 9, directx 9 not installed?\n",false); } // Check if the device support's the caps we will use if(!ValidateDevice()) return false; // Get the desktop's display mode D3DDISPLAYMODE displayMode; if(FAILED(m_pDirect3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displayMode))) { nMainFrame::LastError("Failed to get current display adapter mode."); return TraceRet(__FUNCTION__" Failed to get current display adapter mode.\n",false); } // The struct that describes our direct3d device ZeroMemory(&m_PresentParameters,sizeof(m_PresentParameters)); m_Fullscreen = !nGetInstance()->GetCommandLineVar("-windowed",SETTINGS_WINDOWED).asBool(); m_PresentParameters.Windowed = !m_Fullscreen; m_PresentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD; m_PresentParameters.BackBufferFormat = D3DFMT_X8R8G8B8; m_PresentParameters.EnableAutoDepthStencil = TRUE; m_PresentParameters.AutoDepthStencilFormat = D3DFMT_D24S8; // Check if we should use fsaa if(nGetInstance()->GetCommandLineVar("-fsaa",SETTINGS_FSAA).asBool()) { unsigned long samples = 0; // Check if multisampling is supported and enable it if it is if(SUCCEEDED(m_pDirect3D->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,m_PresentParameters.BackBufferFormat,!m_Fullscreen,D3DMULTISAMPLE_NONMASKABLE,&samples))) { m_PresentParameters.MultiSampleQuality = samples-1; m_PresentParameters.MultiSampleType = D3DMULTISAMPLE_NONMASKABLE; Trace(__FUNCTION__" Using %dx multisampling.\n",samples-1); } } // Check if we should display in fullscreen if(m_Fullscreen) { m_PresentParameters.BackBufferWidth = displayMode.Width; m_PresentParameters.BackBufferHeight = displayMode.Height; } else { nRect rect; GetClientRect(nGetInstance()->GetWindowHandle(),(LPRECT)&rect); m_PresentParameters.BackBufferWidth = rect.GetWidth(); m_PresentParameters.BackBufferHeight = rect.GetHeight(); } // Check if we shouldn't use vsync if(!nGetInstance()->GetCommandLineVar("-vsync",SETTINGS_VSYNC).asBool()) m_PresentParameters.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; Trace(__FUNCTION__" Display mode %dx%d.\n",m_PresentParameters.BackBufferWidth,m_PresentParameters.BackBufferHeight); // Now create our direct3d device from the base direct3d object HRESULT hr = m_pDirect3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,nGetInstance()->GetWindowHandle(),D3DCREATE_SOFTWARE_VERTEXPROCESSING,&m_PresentParameters,&m_pDevice); if(FAILED(hr)) return TraceRet(__FUNCTION__" Failed to create the device.\n",false); // Turn on color dithering hr = m_pDevice->SetRenderState(D3DRS_DITHERENABLE,TRUE); if(FAILED(hr)) Trace(__FUNCTION__" Display adapter doesn't support color dithering, using default.\n"); // Turn off culling m_pDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_NONE); // Enable anisotropic filtering if fsaa is enabled //if(flags & RECFLAG_FSAA) // EnableAnisotropic(m_p3DDevice); // Create our line drawing object hr = D3DXCreateLine(m_pDevice, &m_pLine); if(FAILED(hr)) { nMainFrame::LastError("Failed to create line drawing object."); return TraceRet(__FUNCTION__" Failed to create line drawing object.\n",false); } // Don't use gl lines m_pLine->SetGLLines(false); // Init our font hr = D3DXCreateFont(m_pDevice,SETTINGS_FONTHEIGHT,0,FW_BOLD,0,FALSE,DEFAULT_CHARSET,OUT_TT_PRECIS,6/*CLEARTYPE_QUALITY*/,DEFAULT_PITCH,SETTINGS_FONTNAME,&m_pFontBold); if(FAILED(hr)) { nMainFrame::LastError("Failed to create font. Font not found?"); return TraceRet(__FUNCTION__" Failed to create font. Font not found?",false); } // Init our thin font hr = D3DXCreateFont(m_pDevice,SETTINGS_FONTHEIGHT,0,FW_NORMAL,0,FALSE,DEFAULT_CHARSET,OUT_TT_PRECIS,6/*CLEARTYPE_QUALITY*/,DEFAULT_PITCH,SETTINGS_FONTNAME,&m_pFontNormal); if(FAILED(hr)) { nMainFrame::LastError("Failed to create bold font. Font not found?"); return TraceRet(__FUNCTION__" Failed to create bold font. Font not found?",false); } // Get the font sizes nRect fontSize; GetTextRect(GetBoldFont(),"str",&fontSize,NULL); m_BoldFontHeight = fontSize.GetHeight(); GetTextRect(GetNormalFont(),"str",&fontSize,NULL); m_NormalFontHeight = fontSize.GetHeight(); // Create our sprite drawing object hr = D3DXCreateSprite(m_pDevice, &m_pSprite); if(FAILED(hr)) { nMainFrame::LastError("Failed to create sprite."); return TraceRet(__FUNCTION__" Failed to create sprite.\n",false); } // Turn on texture filtering m_pDevice->SetSamplerState(0,D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); m_pDevice->SetSamplerState(0,D3DSAMP_MINFILTER, D3DTEXF_LINEAR); m_pDevice->SetSamplerState(1,D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); m_pDevice->SetSamplerState(1,D3DSAMP_MINFILTER, D3DTEXF_LINEAR); m_pDevice->SetSamplerState(2,D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); m_pDevice->SetSamplerState(2,D3DSAMP_MINFILTER, D3DTEXF_LINEAR); return true; }
void Init() { D3DXCreateLine(Engine()->GetDevice(), &m_pLine); Engine()->AddObject(m_pLine); }
HRESULT APPLICATION::Init(HINSTANCE hInstance, int width, int height, bool windowed) { debug.Print("Application initiated"); //Create Window Class WNDCLASS wc; memset(&wc, 0, sizeof(WNDCLASS)); wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC)::DefWindowProc; wc.hInstance = hInstance; wc.lpszClassName = "D3DWND"; //Register Class and Create new Window RegisterClass(&wc); m_mainWindow = CreateWindow("D3DWND", "Example 5.6: Frustum Culling", WS_EX_TOPMOST, 0, 0, width, height, 0, 0, hInstance, 0); SetCursor(NULL); ShowWindow(m_mainWindow, SW_SHOW); UpdateWindow(m_mainWindow); //Create IDirect3D9 Interface IDirect3D9* d3d9 = Direct3DCreate9(D3D_SDK_VERSION); if(d3d9 == NULL) { debug.Print("Direct3DCreate9() - FAILED"); return E_FAIL; } //Check that the Device supports what we need from it D3DCAPS9 caps; d3d9->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps); //Hardware Vertex Processing or not? int vp = 0; if(caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) vp = D3DCREATE_HARDWARE_VERTEXPROCESSING; else vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING; //Check vertex & pixelshader versions if(caps.VertexShaderVersion < D3DVS_VERSION(2, 0) || caps.PixelShaderVersion < D3DPS_VERSION(2, 0)) { debug.Print("Warning - Your graphic card does not support vertex and pixelshaders version 2.0"); } //Set D3DPRESENT_PARAMETERS D3DPRESENT_PARAMETERS d3dpp; d3dpp.BackBufferWidth = width; d3dpp.BackBufferHeight = height; d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8; d3dpp.BackBufferCount = 1; d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; d3dpp.MultiSampleQuality = 0; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = m_mainWindow; d3dpp.Windowed = windowed; d3dpp.EnableAutoDepthStencil = true; d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; d3dpp.Flags = 0; d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; //Create the IDirect3DDevice9 if(FAILED(d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_mainWindow, vp, &d3dpp, &m_pDevice))) { debug.Print("Failed to create IDirect3DDevice9"); return E_FAIL; } //Release IDirect3D9 interface d3d9->Release(); D3DXCreateFont(m_pDevice, 18, 0, 0, 1, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Arial", &m_pFont); //Create m_light ::ZeroMemory(&m_light, sizeof(m_light)); m_light.Type = D3DLIGHT_DIRECTIONAL; m_light.Ambient = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); m_light.Diffuse = D3DXCOLOR(0.9f, 0.9f, 0.9f, 1.0f); m_light.Specular = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f); m_light.Direction = D3DXVECTOR3(0.0f, -1.0f, 0.0f); m_pDevice->SetLight(0, &m_light); m_pDevice->LightEnable(0, true); //Set sampler state for(int i=0;i<4;i++) { m_pDevice->SetSamplerState(i, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); m_pDevice->SetSamplerState(i, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); m_pDevice->SetSamplerState(i, D3DSAMP_MIPFILTER, D3DTEXF_POINT); } //Init camera m_camera.Init(m_pDevice); //Load objects LoadObjectResources(m_pDevice); //Create 2D Line D3DXCreateLine(m_pDevice, &m_pLine); //Create city m_city.Init(INTPOINT(25, 25)); m_camera.m_focus = m_city.GetCenter(); //Init mouse m_mouse.InitMouse(m_pDevice, m_mainWindow); return S_OK; }
void DXFrame::init(HWND& hWnd, HINSTANCE& hInst,bool bWindowed) { m_hWnd = hWnd; m_bFullScreen = bWindowed; //create d3d object m_pD3DObject = Direct3DCreate9(D3D_SDK_VERSION); //find height and width of window RECT rect; GetWindowRect(hWnd, &rect); w_width = rect.right - rect.left; w_height = rect.bottom - rect.top; // Set D3D Device presentation parameters before creating the device D3DPRESENT_PARAMETERS D3Dpp; ZeroMemory(&D3Dpp, sizeof(D3Dpp)); // NULL the structure's memory D3Dpp.hDeviceWindow = hWnd; // Handle to the focus window D3Dpp.Windowed = bWindowed; // Windowed or Full-screen boolean D3Dpp.AutoDepthStencilFormat = D3DFMT_D24S8; // Format of depth/stencil buffer, 24 bit depth, 8 bit stencil D3Dpp.EnableAutoDepthStencil = TRUE; // Enables Z-Buffer (Depth Buffer) D3Dpp.BackBufferCount = 1; // Change if need of > 1 is required at a later date D3Dpp.BackBufferFormat = D3DFMT_X8R8G8B8; // Back-buffer format, 8 bits for each pixel D3Dpp.BackBufferHeight = w_height; // Make sure resolution is supported, use adapter modes D3Dpp.BackBufferWidth = w_width; // (Same as above) D3Dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; // Discard back-buffer, must stay discard to support multi-sample D3Dpp.PresentationInterval = m_bVsync ? D3DPRESENT_INTERVAL_DEFAULT : D3DPRESENT_INTERVAL_IMMEDIATE; // Present back-buffer immediately, unless V-Sync is on D3Dpp.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL; // This flag should improve performance, if not set to NULL. D3Dpp.FullScreen_RefreshRateInHz = bWindowed ? 0 : D3DPRESENT_RATE_DEFAULT; // Full-screen refresh rate, use adapter modes or default D3Dpp.MultiSampleQuality = 0; // MSAA currently off, check documentation for support. D3Dpp.MultiSampleType = D3DMULTISAMPLE_NONE; // MSAA currently off, check documentation for support. // Check device capabilities DWORD deviceBehaviorFlags = 0; m_pD3DObject->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &m_D3DCaps); // Determine vertex processing mode if(m_D3DCaps.DevCaps & D3DCREATE_HARDWARE_VERTEXPROCESSING) { // Hardware vertex processing supported? (Video Card) deviceBehaviorFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING; } else { // If not, use software (CPU) deviceBehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING; } // If hardware vertex processing is on, check pure device support if(m_D3DCaps.DevCaps & D3DDEVCAPS_PUREDEVICE && deviceBehaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING) { deviceBehaviorFlags |= D3DCREATE_PUREDEVICE; } // Create the D3D Device with the present parameters and device flags above if(m_pD3DObject->CreateDevice( D3DADAPTER_DEFAULT, // which adapter to use, set to primary D3DDEVTYPE_HAL, // device type to use, set to hardware rasterization hWnd, // handle to the focus window deviceBehaviorFlags, // behavior flags &D3Dpp, // presentation parameters &m_pD3DDevice)==D3D_OK) { // returned device pointer // Create a Font Object D3DXCreateFont(m_pD3DDevice,30,0,FW_BOLD,0,false,DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY,DEFAULT_PITCH | FF_DONTCARE, TEXT("Times New Roman"),&m_pD3DFont); // Create Sprite Object and Textures D3DXCreateSprite(m_pD3DDevice, &m_pD3DSprite); //create line object D3DXCreateLine(m_pD3DDevice, &m_pD3DLine); m_pD3DDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE ); m_pD3DDevice->SetRenderState( D3DRS_SPECULARENABLE, TRUE); m_pD3DDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(60, 60, 60)); m_pD3DDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true); m_pD3DDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true); m_pD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); m_pD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); m_pD3DDevice->GetViewport(&defaultView); m_bLost = false; //m_bSplitScreen = false; //viewPorts[0].viewPort = defaultView; } else m_bLost = true; }