Jump to content
  • Advertisement
Sign in to follow this  
tokenone

MDX render to a panel in a windows form

This topic is 4325 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been searching the hole day for a solution to this, but it looks like my google skills won't help me with this one. I'd like to make a form for a litle server application that will host a game and should show the current gam ein a little window while displaying log messages and other things . So I tried to make a panel and render the device content to it , but this one doesn't work out , because the form components don't get updated and redrawn. It will either update the device content or the components but not both at the same time. Here's the simplified code :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace App_test {
    public partial class Form1 : Form {

        private float angle = 0.0f;

        private Device panelDevice;
        private PresentParameters pp;
        private Mesh mesh;

        public Form1() {
            InitializeComponent();
   
            this.Setstyle(Controlstyles.AllPaintingInWmPaint |         Controlstyles.Opaque, true);
        }

        public bool InitializeGraphics() {
            pp = new PresentParameters();

            pp.Windowed = true;
            pp.SwapEffect = SwapEffect.Discard;

            panelDevice = new Device(0, DeviceType.Hardware, scenePanel1, CreateFlags.SoftwareVertexProcessing, pp);

            mesh = Mesh.Teapot(panelDevice);

            return true;
        }

        protected override void OnPaint(PaintEventArgs e) {
            angle += 0.01f;

            int i = 0;
            if ((i = new Random().Next(100)) < 10)
                textBox1.Text += "Zahl : " + i + "\r\n";

            panelDevice.Transform.World = Matrix.RotationY(angle);
            panelDevice.Transform.View = Matrix.LookAtLH(new Vector3(0, 0, -5f), new Vector3(0, 0, 1), new Vector3(0, 1, 0));
            panelDevice.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)scenePanel1.Width / (float)scenePanel1.Height, 1.0f, 1000.0f);

            panelDevice.Clear(ClearFlags.Target , Color.CornflowerBlue, 1.0f, 0);

            panelDevice.BeginScene();

            mesh.DrawSubset(0);

            panelDevice.EndScene();

            panelDevice.Present();

            this.Invalidate();
        }
    }

    public class ScenePanel : Panel {
        public ScenePanel() {
            
            this.Setstyle(Controlstyles.AllPaintingInWmPaint | Controlstyles.Opaque, true);
     
        }
    }
}


Thanks for any suggestions . Oh and btw. how can i make a code box in a post? [Edited by - tokenone on September 15, 2006 11:47:53 AM]

Share this post


Link to post
Share on other sites
Advertisement

panelDevice = new Device(0, DeviceType.Hardware, scenePanel1.Handle, CreateFlags.SoftwareVertexProcessing, pp);




I don't know if it helps but you can try this. scenePanel1.Handle insteed of scenePanel1.

http://www.gamedev.net/community/forums/faq.asp#tags <-- add source code ;)

Share this post


Link to post
Share on other sites
thx , for the codebox help.

But the handle thing is only for mdx 2.0 i think . I'm using 1.1 here . Sorry forgot to mention that.

Share this post


Link to post
Share on other sites
hmmz, i did the same thing a long time ago. But i can't remember what i did. I shall try to code something and post it on this topic.

have a little patience... ;)

Share this post


Link to post
Share on other sites
What i did is i took the onpaint method of the panel and not from the form. It's not nessesary to change the style of the panel of form. cheers


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace WindowsApplication2
{
public partial class Form1 : Form
{
private float angle = 0.0f;

private Device panelDevice;
private PresentParameters pp;
private Mesh mesh;


public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
pp = new PresentParameters();

pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;

panelDevice = new Device(0, DeviceType.Hardware, scenePanel1, CreateFlags.SoftwareVertexProcessing, pp);

mesh = Mesh.Teapot(panelDevice);

}

private void Form1_Paint(object sender, PaintEventArgs e)
{
angle += 0.01f;

int i = 0;
if ((i = new Random().Next(100)) < 10)
textBox1.Text += "Zahl : " + i + "\r\n";

panelDevice.Transform.World = Matrix.RotationY(angle);
panelDevice.Transform.View = Matrix.LookAtLH(new Vector3(0, 0, -5f), new Vector3(0, 0, 1), new Vector3(0, 1, 0));
panelDevice.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4.0f, (float)scenePanel1.Width / (float)scenePanel1.Height, 1.0f, 1000.0f);

panelDevice.Clear(ClearFlags.Target, Color.CornflowerBlue, 1.0f, 0);

panelDevice.BeginScene();

mesh.DrawSubset(0);

panelDevice.EndScene();

panelDevice.Present();

this.Invalidate();
}
}
}



Share this post


Link to post
Share on other sites
Well, I tried both , an override of the Panel OnPaint method , and attaching a Render method to the Panel.Paint . Still doesn't paint it right. Maybe I missunderstood what you have written.

Share this post


Link to post
Share on other sites
Great ! Okay , now i have a solid ground to work on . Thanx a lot ! Maybe it's a problem with a device lost state that wasn't taken care of in my code . Because I did nearly the same as in your code except the this.Load . And also my Paint attach was in the constructor.

Again thanks

Share this post


Link to post
Share on other sites
You need to invalidate the the scenePanel not the parent form.

in your render function you need this..

this.scenePanel.Invalidate();

Also I tend to not overrwrite the OnPaint, but simply set the Paint handler for the renderTarget panel in this case its your scenePanel1

this.scenePanel.Paint += PaintEventHandler(Render);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!