[solved] C# Form + Mogre = Problems?

Eldritch

14-04-2007 18:58:48

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.

Eldritch

14-04-2007 19:14:26

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?

Blackbeard

15-04-2007 03:19:10

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.

smernesto

15-04-2007 03:35:07

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.

Eldritch

15-04-2007 08:15:10

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...

Eldritch

15-04-2007 08:43:59

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");
node.Yaw(new Radian(rot++));
root.RenderOneFrame();
}


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...

bleubleu

15-04-2007 18:15:26

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!

Mat

smernesto

15-04-2007 19:35:52

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().

Eldritch

15-04-2007 21:11:19

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?

Dale_ee

27-04-2007 15:09:28

You can create Timer, that will call Refresh() method every x milliseconds, depending on desired fps.

smernesto

27-04-2007 19:38:27

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.