How do I get the D3D Device from the demos?

How do I get the D3D Device from the demos?

Ritratto di Kevin

Hi,

I am using the CEGUI into the Havok demos. As the demos are rendered by DirectX, and CEGUI supplies DirectX as well.

But when creating an instance of the renderer in CEGUI, the d3d device is required.

CEGUI::Direct3D9Renderer& myRenderer = CEGUI::Direct3D9Renderer::bootstrapSystem( myD3D9Device );

Could anyone tell me how can I get the d3d device from the demos?

There is only 1 month left for my final year project, please help me T.T

6 post / 0 new
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione
Ritratto di Kevin

Please....

Ritratto di HavokTim

Hi Kevin--

Given a pointer to a demo - for example, hkDefaultPhysicsDemo* demo, first get the hkgWindow associated with the demo. Next, cast the hkgWindow to an hkgWindowDX9S and call its member function getDevice(). The code should look something like:

((hkgWindowDX9S*)m_env->m_window)->getDevice();

There's also a very light-weight GUI solution included in the demos. If this seems like a viable option for you, search the demos for ImGui. Please let me know whether that works for you - thanks.

--Tim

Ritratto di Kevin

Hi Tim,

Thank you for the help. I've read the ImGui demo but I think CEGUI is a better choice for my project. I followed ur instructions and it compiled well. But when running it, the program stopped at in this function in CEGUIDirect3D9Renderer.cpp

Size Direct3D9Renderer::getViewportSize() {     

D3DVIEWPORT9 vp;    

 if (FAILED(d_device->GetViewport(&vp)))         

CEGUI_THROW(RendererException( "Direct3D9Renderer::getViewportSize - Unable to access required view port information from Direct3DDevice9."));   

  else         

return Size(static_cast<float>(vp.Width), static_cast<float>(vp.Height)); }

So I assume that it needs to get the viewport as well, then I wrote the following in my code

//function to create the GUI

void MyPhysicsLab::createGUI(){

LPDIRECT3DDEVICE9 m_device;

m_device = ((hkgWindowDX9S*)m_env->m_window)->getDevice();

m_device->SetViewport((hkgViewportDX9S*)m_env->m_window->getViewport(0));

new MyGUI(m_device); }

However, the compiler is not happy about this and told me that I cannot cast the “hkgViewportDX9S *” type to the “const D3DVIEWPORT9 *” type.

How can I fix it?

Kevin.

Ritratto di Kevin

Sorry I didnot use the pointer to the demo in the previous post, I put the code in my constructor now, but the programm stops on the last line:

HK_DECLARE_DEMO(MyPhysicsLab,HK_DEMO_TYPE_PHYSICS,"My Physics Lab", helpString);

And the error messge is that the following variable has not got a proper value:

((*(hkArrayBase<hkgViewport *>*)(&(*(hkArray<hkgViewport *,extContainerAllocator>*)(&(*((*(env)).m_window)).m_viewports))))).m_size

Ritratto di HavokTim

Hi Kevin--

The class hkgViewportDX9S is not derived from the D3D9 struct D3DVIEWPORT9, so attempting to cast between them will fail. I suggest checking the HRESULT returned by GetViewport(). Based on the information you provided, this doesn't sound like a Havok issue, so you may find more luck speaking with experts in CEGUI.

--Tim

Accedere per lasciare un commento.