Jump to content
  • Advertisement
Sign in to follow this  
EvilWeebl

Render DirectX in c# form picturebox?

This topic is 3259 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

Hi all, So this might be an entirely noob question but I am actually just starting out with the whole c# and visual thing as opposed to c++ console stuff. Im trying to make an application tool with a GUI that arranges sprites from sprite sheets, anyway im getting totally off topic as im stuck at the beginning. so I create a new visual c# project and read some stuff about the basics of setting up managed directx device. In my program im going to want the created sprite to animate in a picturebox or something on the form. How?! This is all I have so far.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;

namespace Assignment
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

namespace Assignment
{
    public partial class Form1 : Form
    {
        private Device m_device;
        public Form1()
        {
            InitializeComponent();
            InitializeGraphics();
        }

        //initialise DirectX graphics
        public bool InitializeGraphics()
        {
            PresentParameters pp = new PresentParameters();
            pp.SwapEffect = SwapEffect.Discard;
            pp.Windowed = true;
            pp.DeviceWindowHandle = pictureBox1.Handle;
            try
            {
                m_device = new Device(0, DeviceType.Hardware, pictureBox1.Handle, CreateFlags.SoftwareVertexProcessing, pp);
                return true;
            }
            catch (DirectXException)
            {
                return false;
            }
        }

        //
        private void Render()
        {
            m_device.Clear(ClearFlags.Target, Color.Navy, 1.0f, 0);
            m_device.BeginScene();

            // Render frame here

            m_device.EndScene();
            m_device.Present();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }


        private void pictureBox1_paint(object sender, EventArgs e)
        {
            Render();
        }

    }
}

I know the Render function doesn't actually do anything right now but I figure if it clears the picture box to blue its working right? Any and all very detailed help as im new to this would be much appreciated

Share this post


Link to post
Share on other sites
Advertisement
You might want to check this out.

http://www.codeproject.com/KB/game/XNA_and_WinForms.aspx?msg=3004569

You can use the managed windows forms as a gui and use unmanaged DirectX but it's a bit of a pain.

WBK

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!