[solved] C# Form + Mogre = Problems?
I've embedded some Mogre stuff into a C# form using the last of the tutorials in the Mogre tutorials section. Everything works good until I decide to add another control to the form.. then the Mogre window never shows up.. I am going to build a tool and need a Mogre window as well as C# controls, such as listboxes and buttons.
Okey, solved it.. seems like the Mogre part of the form does not repaint itself any longer. If I minimize the app and then restore it, the scene shows. How can I fix this?
Added some controls (button/textbox) to the tutorial form and had no problems.
Have you manualy added your controls (not via IDE)?
Personaly i would create separate forms for controls.
In my project I have the scene rendered in a PictureBox not in the Form, and i have many controls, A Office 2007 like bar, and other controls.
I use the RenderOneFrame() function that works, but sometimes it renders and the picturebox got white, Is how if it renders but next the picturebox update it self again and clear the picturebox, this happens with some portions of my code, I will have to find a solution.
I also use StartRendering() in other parts of my code and the picturebox renders correctly all time.
I've added them via the Form Editor in MSVC due to the fact it needs to look slick.
I use the tutorial as it is, except from the new controls I added...
Shit.. just realized I said I used the last Mogre tutorial from the wiki...
What I meant to say is that I used the Demo.MogreForm sample from the Dagon SDK... sorry about my confusion. I just tried modifying that sample to rotate the ogre head:
public void Paint()
SceneNode node = root.GetSceneManager("SceneMgr").GetSceneNode("ogreNode");
But I need to constantly minimize and restore the window to be able to see that the head is rotating because the Ogre window is static...
You need to understand the way Windows redraws its windows. To avoid constantly redrawing everything, it simply redraws the windows that are "invalid".
The reason why the head doesnt spin is because windows thinks nothing has changed and the control doesnt need to be drawn. As a proof, drag another window over the image and it will start to rotate.
What you need to do is to call the Invalidate() on the panel whenever you want the head to be redrawn (im assuming you dont want to use StartRendering).
But doing this might create a lot of flickers. You might need to make your Ogre control inherit from Control and tweak it a little (double buffering, etc.). There are some examples of that in MSDN.
But again, this has nothing to do win Mogre. Have fun!
I am Calling RenderOneFrame outside the Paint.
Paint Just redraws the form when it needs, when the form is minimized, or another forms is on top of your form.
Call RenderOneFrame from another part of your code when you need to redraw the scene.
Calling RenderOneFrame will not trigger Paint().
I am not using Paint().
Aha, I understand. But.. how do I get a loop going in my form? How would I have to modify Demo.MogreForm to get this working?
You can create Timer, that will call Refresh() method every x milliseconds, depending on desired fps.
Windows Forms Timer are not very good for high latency.
But if this is not problem for you then you can use it.
.NET has 3 Timers, Windows.Forms, Threading and another that I donÂ´t remember.