void D3DOverdrawWindow:: SetupProjection(void) { int w = GetWidth(), h = GetHeight(); if (w < h) D3DXMatrixOrthoOffCenterRH(&m_mProjection, -0.5f, 0.5f, -0.5f * h / w, 0.5f * h / w, 0, 2); else D3DXMatrixOrthoOffCenterRH(&m_mProjection, -0.5f * w / h, 0.5f * w / h, -0.5f, 0.5f, 0, 2); }
void WKCACFLayerRenderer::createRenderer() { if (m_triedToCreateD3DRenderer) return; m_triedToCreateD3DRenderer = true; D3DPRESENT_PARAMETERS parameters = initialPresentationParameters(); if (!d3d() || !::IsWindow(m_hostWindow)) return; // D3D doesn't like to make back buffers for 0 size windows. We skirt this problem if we make the // passed backbuffer width and height non-zero. The window will necessarily get set to a non-zero // size eventually, and then the backbuffer size will get reset. RECT rect; GetClientRect(m_hostWindow, &rect); if (rect.left-rect.right == 0 || rect.bottom-rect.top == 0) { parameters.BackBufferWidth = 1; parameters.BackBufferHeight = 1; } if (FAILED(d3d()->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hostWindow, D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, ¶meters, &m_d3dDevice))) return; D3DXMATRIXA16 projection; D3DXMatrixOrthoOffCenterRH(&projection, rect.left, rect.right, rect.top, rect.bottom, -1.0f, 1.0f); m_d3dDevice->SetTransform(D3DTS_PROJECTION, &projection); m_context.adoptCF(CACFContextCreate(0)); windowsForContexts().set(m_context.get(), this); m_renderContext = static_cast<CARenderContext*>(CACFContextGetRenderContext(m_context.get())); m_renderer = CARenderOGLNew(wkqcCARenderOGLCallbacks(wkqckCARenderDX9Callbacks), m_d3dDevice.get(), 0); // Create the root hierarchy m_rootLayer = WKCACFLayer::create(WKCACFLayer::Layer); m_rootLayer->setName("WKCACFLayerRenderer rootLayer"); m_scrollLayer = WKCACFLayer::create(WKCACFLayer::Layer); m_scrollLayer->setName("WKCACFLayerRenderer scrollLayer"); m_rootLayer->addSublayer(m_scrollLayer); m_scrollLayer->setMasksToBounds(true); m_scrollLayer->setAnchorPoint(CGPointMake(0, 1)); #ifndef NDEBUG CGColorRef debugColor = createCGColor(Color(255, 0, 0, 204)); m_rootLayer->setBackgroundColor(debugColor); CGColorRelease(debugColor); #endif if (IsWindow(m_hostWindow)) m_rootLayer->setFrame(bounds()); if (m_context) m_rootLayer->becomeRootLayerForContext(m_context.get()); }
void LegacyCACFLayerTreeHost::initD3DGeometry() { ASSERT(m_d3dDevice); CGRect bounds = this->bounds(); float x0 = bounds.origin.x; float y0 = bounds.origin.y; float x1 = x0 + bounds.size.width; float y1 = y0 + bounds.size.height; D3DXMATRIXA16 projection; D3DXMatrixOrthoOffCenterRH(&projection, x0, x1, y0, y1, -1.0f, 1.0f); m_d3dDevice->SetTransform(D3DTS_PROJECTION, &projection); }
void Graphics::onResetDevice() { mFX->OnResetDevice(); for(auto iter = mFontList.begin(); iter != mFontList.end(); iter++) (*iter).second->OnResetDevice(); // Ortho projection when not using shader pipeline. D3DXMATRIX m; D3DXMatrixIdentity(&m); gd3dDevice->SetTransform(D3DTS_WORLD, &m); gd3dDevice->SetTransform(D3DTS_VIEW, &m); D3DXMatrixOrthoOffCenterRH(&m, 0, 1200, 800, 0, 0, 1); gd3dDevice->SetTransform(D3DTS_PROJECTION, &m); }
d3d_vis::d3d_vis(HWND hwnd, LPDIRECT3DDEVICE9 pdevice) : hwnd_ (hwnd), pdevice_ (pdevice), color_ (D3DCOLOR_XRGB(255,255,0)), ofs_ (0.0f, 0.0f), scale_ (1.0f) { RECT myrect; GetClientRect (hwnd_, &myrect); HRESULT hr = D3DXCreateFont( pdevice_, 16, 0, FW_NORMAL, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Arial"), &pfont_ ); assert (SUCCEEDED(hr)); D3DXMATRIX proj; D3DXMatrixOrthoOffCenterRH (&proj, 0, (float)myrect.right, (float)myrect.bottom, 0, -1.0f, 1.0f); pdevice_->SetTransform (D3DTS_PROJECTION, &proj); D3DVERTEXELEMENT9 dwDeclSingle[] = { {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, {1, 0, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0} , D3DDECL_END() }; D3DVERTEXELEMENT9 dwDeclMulti[] = { {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, {0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0} , D3DDECL_END() }; pdevice_->CreateVertexDeclaration(dwDeclSingle, &pvdeclsingle_); pdevice_->CreateVertexDeclaration(dwDeclMulti, &pvdeclmulti_); pdevice_->CreateVertexBuffer(sizeof (DWORD), 0, 0, D3DPOOL_MANAGED, &psinglecolor_, NULL); pdevice_->CreateVertexBuffer(sizeof (b_vertex) * 5, 0, 0, D3DPOOL_MANAGED, &prect_, NULL); pdevice_->SetStreamSource(1, psinglecolor_, 0, 0); set_color (0xFFFFFFFF); in_screen(); }
Matrix Matrix::CreateOrthographicOffCenter(float minx, float maxx, float miny, float maxy, float zn, float zf) { D3DXMATRIX mat; D3DXMatrixOrthoOffCenterRH(&mat, minx, maxx, miny, maxy, zn, zf); return Matrix( (float*)&mat._11); }
void xForm::SetProjectionOrtho(float left, float top, float right, float bottom, float zNear, float zFar) { D3DXMATRIX mat; D3DXMatrixOrthoOffCenterRH(&mat, left, right, top, bottom, zNear, zFar); m_pd3dDevice->SetTransform(D3DTS_PROJECTION, &mat); }
bool WKCACFLayerRenderer::createRenderer() { if (m_d3dDevice || !m_mightBeAbleToCreateDeviceLater) return m_d3dDevice; m_mightBeAbleToCreateDeviceLater = false; D3DPRESENT_PARAMETERS parameters = initialPresentationParameters(); if (!d3d() || !::IsWindow(m_hostWindow)) return false; // D3D doesn't like to make back buffers for 0 size windows. We skirt this problem if we make the // passed backbuffer width and height non-zero. The window will necessarily get set to a non-zero // size eventually, and then the backbuffer size will get reset. RECT rect; GetClientRect(m_hostWindow, &rect); if (rect.left-rect.right == 0 || rect.bottom-rect.top == 0) { parameters.BackBufferWidth = 1; parameters.BackBufferHeight = 1; } D3DCAPS9 d3dCaps; if (FAILED(d3d()->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dCaps))) return false; DWORD behaviorFlags = D3DCREATE_FPU_PRESERVE; if ((d3dCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) && d3dCaps.VertexProcessingCaps) behaviorFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING; else behaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING; COMPtr<IDirect3DDevice9> device; if (FAILED(d3d()->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hostWindow, behaviorFlags, ¶meters, &device))) { // In certain situations (e.g., shortly after waking from sleep), Direct3DCreate9() will // return an IDirect3D9 for which IDirect3D9::CreateDevice will always fail. In case we // have one of these bad IDirect3D9s, get rid of it so we'll fetch a new one the next time // we want to call CreateDevice. s_d3d->Release(); s_d3d = 0; // Even if we don't have a bad IDirect3D9, in certain situations (e.g., shortly after // waking from sleep), CreateDevice will fail, but will later succeed if called again. m_mightBeAbleToCreateDeviceLater = true; return false; } // Now that we've created the IDirect3DDevice9 based on the capabilities we // got from the IDirect3D9 global object, we requery the device for its // actual capabilities. The capabilities returned by the device can // sometimes be more complete, for example when using software vertex // processing. D3DCAPS9 deviceCaps; if (FAILED(device->GetDeviceCaps(&deviceCaps))) return false; if (!hardwareCapabilitiesIndicateCoreAnimationSupport(deviceCaps)) return false; m_d3dDevice = device; D3DXMATRIXA16 projection; D3DXMatrixOrthoOffCenterRH(&projection, rect.left, rect.right, rect.top, rect.bottom, -1.0f, 1.0f); m_d3dDevice->SetTransform(D3DTS_PROJECTION, &projection); m_renderer = CARenderOGLNew(&kCARenderDX9Callbacks, m_d3dDevice.get(), 0); if (IsWindow(m_hostWindow)) m_rootLayer->setBounds(bounds()); return true; }