decai
Topic Author
Posts: 31
Joined: 06 Jul 2016, 18:19

About integerate NoesisGUI with OGRE 2.1

25 Sep 2016, 07:09

Hi guys,

I have some problem with integerate NoesisGUI with Ogre 2.1.

1. As we use OGRE 2.1 we use directX 11, I found an OgreBindings project at github but it's use directX 9. I chaned some code and use the D3D11 Render from 1.3 sdk to support directX11. Because I never use Dirext api before, the Tutorial05 in the sdk said that "Restore state. This must be done per frame because NoesisGUI modifies the GPU state" and the code shown as below
g_pImmediateContext->OMSetRenderTargets(1, &g_pRenderTargetView, g_pDepthStencilView);
g_pImmediateContext->IASetInputLayout(g_pVertexLayout);
UINT stride = sizeof(SimpleVertex);
UINT offset = 0;
g_pImmediateContext->IASetVertexBuffers(0, 1, &g_pVertexBuffer, &stride, &offset);
g_pImmediateContext->IASetIndexBuffer(g_pIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
g_pImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

g_pImmediateContext->OMSetDepthStencilState(0, 0);
g_pImmediateContext->RSSetState(0);
g_pImmediateContext->OMSetBlendState(0, 0, 0xffffffff);

D3D11_VIEWPORT vp = { 0.0f, 0.0f, (FLOAT)g_Width, (FLOAT)g_Height, 0.0f, 1.0f};
g_pImmediateContext->RSSetViewports(1, &vp);
I'm wonder which code are store the GPU state and which are restore the GPU state. I'm sorry to ask you so basic issus.
In my project I call renderer->RenderOffscreen() when Ogre framestarted and call renderer->Render() when Ogre frameRenderingQueued as the OgreBindings sample at github.

2. In our project we support some keyboard shutcuts such as W-A-S-D to control walk. When showing a gui view with an input in the 3D scence, I want the input box to lost focus when the mouse clicked out of the gui view. I found a method UIElement::Focus but there no method called such as ReleaseFocus, how can I implement this function. I want when I press 'W' the word will not show in the input box after I clicked the mouse out of the view but walking.

3. How do I determine if an event(keyboard event, mouse event or touch event) has been handled by NoesisGUI or not? Just now I found UIElement::IsMouseOver method, is that correct?

Thanks.
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: About integerate NoesisGUI with OGRE 2.1

26 Sep 2016, 21:23

1. I'm wonder which code are store the GPU state and which are restore the GPU state. I'm sorry to ask you so basic issus.
In my project I call renderer->RenderOffscreen() when Ogre framestarted and call renderer->Render() when Ogre frameRenderingQueued as the OgreBindings sample at github.
Don't worry about asking basic issues. In fact, this is not a basic issue. Whenever you call Render() or RenderOffscreen() we modify the GPU state and it must be restored at your side. The easiest and more efficient way is by setting all the changed states again in your engine.That is what is being done in the integration sample. Another alternative, easier to implement but more inefficient would be doing Gets before calling Noesis and doing Sets after that to restore the state. In D3D11 this is very easy, this is the list of states we are chaning:
mContext->IASetIndexBuffer(mIndices.buffer, DXGI_FORMAT_R16_UINT, 0);
mContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
mContext->VSSetConstantBuffers(0, 1, &mConstants);
mContext->PSSetConstantBuffers(0, 1, &mConstants);
mContext->HSSetShader(0, 0, 0);
mContext->DSSetShader(0, 0, 0);
mContext->GSSetShader(0, 0, 0);
mContext->CSSetShader(0, 0, 0);
mContext->SetPredication(0, 0);
mContext->IASetInputLayout(layout);
mContext->VSSetShader(shader, 0, 0);
mContext->PSSetShader(shader, 0, 0);
mContext->RSSetState(state);
mContext->OMSetBlendState(state, 0, 0xffffffff);
mContext->OMSetDepthStencilState(state, stencilRef);
mContext->PSSetShaderResources(0-3, 1, &texture);
mContext->PSSetSamplers(0-3, 1, &sampler);
So basically you should do Get of all those states and Set them again after rendering with Noesis.

I will improve the integration sample with all this to avoid confusion.
2. In our project we support some keyboard shutcuts such as W-A-S-D to control walk. When showing a gui view with an input in the 3D scence, I want the input box to lost focus when the mouse clicked out of the gui view. I found a method UIElement::Focus but there no method called such as ReleaseFocus, how can I implement this function. I want when I press 'W' the word will not show in the input box after I clicked the mouse out of the view but walking.
I recommend using VisualTreeHelper::HitTest to detect if the mouse position is over a NoesisGUI element or not. Our D3D9 integration sample does it. Note that sample is using NoesisGUI 1.2.
3. How do I determine if an event(keyboard event, mouse event or touch event) has been handled by NoesisGUI or not? Just now I found UIElement::IsMouseOver method, is that correct?
Using HitTest as commented above you can easily implement a keyboard focus manager between your application and NoesisGUI. Please, let me know if you need more details about it.
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: About integerate NoesisGUI with OGRE 2.1

26 Sep 2016, 23:35

If you want to manually remove the focus of an element, you can do it via the Mouse class, by calling:
Mouse* mouse = element->GetMouse();
mouse->Capture(0);
You can execute that code when the user clicks outside any element of the UI, and you know it by using VisualTreeHelper::HitTest() as jsantos previously indicated.
 
decai
Topic Author
Posts: 31
Joined: 06 Jul 2016, 18:19

Re: About integerate NoesisGUI with OGRE 2.1

27 Sep 2016, 16:43

I tried you guys described above, it's works fine for me. Thank you.

Who is online

Users browsing this forum: No registered users and 1 guest