Changing

smernesto

22-07-2007 03:32:21

Hi.

I am rendering in a picturebox that is inside a panel and it is inside of a Form, because my application is windowed and is like a level editor, I have buttons and other controls in my Form.

I want to change the size of the picturebox and dynamically change the the rendering resolution. The picture box hasn´t a 4:3 relation, is an arbitrary resolution and relation.

I don´t know why, I tried to change the resolution in many ways but nothing works.

Thanks

Ernesto

bleubleu

22-07-2007 21:16:00

Hi!

I probably can help you. I am working on a editor with Mogre and so far it works like a charm. I have a my "ViewControl" which is basically just a UserControl that renders with Mogre. It has a RenderWindow, a Viewport and a Camera.

In the OnResize method, I notify the RenderSystem that the window is resized and then I repaint it.


protected override void OnResize(EventArgs e)
{
if (m_window != null)
{
m_window.WindowMovedOrResized();

// Update your cameras here...
m_camera.AspectRatio = (float)m_viewport.ActualWidth /
(float)m_viewport.ActualHeight;

if (this.Visible)
{
// Render a frame.
Root.Singleton.RenderOneFrame();
}
}

base.OnResize(e);
}


If you need more help, let me know, I can post more code or give more explanation.

Mat

PS : Dont expect the resizes to be efficients. Direct3D is very sensitive to resizes with the device lost and stuff. So expect some flickering and/or slowdowns during resize. Use with care.

smernesto

23-07-2007 04:29:27

Well I tried very much.

What I am doing now is destroy the RenderWindow, create it again and create the viewport again, and it works now I have the resolution of the Control.

If I only change the aspect ratio the RenderWindow doesnt´t change the resolution.

I don´t know if you get the same?, when you resize your control, the viewport.ActualHeight and Width also changes? In my application if I resize the control the image resizes also but the viewport maintains its actualheight and actualwidth.

When my control resizes I call this:


public class MogreAdmon
{
...
RenderWindow renderWindow;
Root root;
...
InitializeMogre()
{
root = new Root();
...
CreateWindow(control, null)
}

public void CreateWindow(System.Windows.Forms.Control control, Mogre.Camera camera)
{
if (renderWindow != null)
{
root.DetachRenderTarget(renderWindow);
renderWindow.Destroy();
}

NameValuePairList misc = new NameValuePairList();
misc["externalWindowHandle"] = control.Handle.ToString();
renderWindow = root.CreateRenderWindow("Window name", (uint)control.Width, (uint)control.Height, false, misc); //Actually it seems the Width and Height in this function doesn´t matter if it has externalWindowHandle in misc

//Recreate the viewport
if(camera != null)
viewport = renderWindow.AddViewport(camara);
}
}

...
Class Control : Some Control or PictureBox
{
Camera actualCamera
..

OnControlResize()
{
mogreAdmon.CreateWindow(this, actualCamera);
actualCamera.AspectRatio = (float)viewport.ActualWidth / (float)viewport.ActualHeight;

}
}



With this now I get a clear image not a redimensioned image.

Try this in your code, change the control size to (160,120) immediately before you create the renderWindow, now use your control in a bigger size like 640,480. If I do this without recreate the renderWindow the actual resolution is 160x120 but it is scaled to 640x480 then I change the control size.

bleubleu

26-07-2007 00:17:23

You are right, by default, the control will resize but the rendering size will remain the same. Which mean you image will merely be streched to fit the control. This is no good.

But, I dont think you looked carefully at my code. At some point I call the method WindowMovedOrResized() on the window. This is the trick!

This method will trigger the resize in Direct3D. Try it! If it doesnt work, Let me know, I can simply post all my code in here!

Mat

smernesto

26-07-2007 03:48:08

Hey bleubleu hehehe, I thinked WindowMovedOrResized was a method implemented by you hahahaha , ouch, I solved the problem in another way but hahaha WindowMovedOrResized is less code, well well I will try,

Thanks.

Ernesto

EDIT:
I tried and it work well, with WindowMovedOrResized, thanks .