SFML community forums

Help => General => Topic started by: delio on April 01, 2014, 04:40:51 pm

Title: Get SFML renderwindow on label problem
Post by: delio on April 01, 2014, 04:40:51 pm
I want to get SFML renderwindow on label in WinForm.
But when I compiled, It gave me an error like this.
(http://upic.me/i/qg/error.png)

This is my code

Programing.cs
Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using SFML;
using SFML.Audio;
using SFML.Window;
using SFML.Graphics;

namespace _01_AddingRibbonSupport
{
    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());
        }
    }
}

Form1.cs
Code: [Select]
using System;
using System.Windows.Forms;
using RibbonLib;
using RibbonLib.Interop;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SFML;
using SFML.Audio;
using SFML.Window;
using SFML.Graphics;

namespace _01_AddingRibbonSupport
{
    public partial class Form1 : Form, IRibbonForm
    {
        public class DrawingSurface : System.Windows.Forms.Control
        {
            protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
            {
                // don't call base.OnPaint(e) to prevent forground painting
                // base.OnPaint(e);
            }
            protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
            {
                // don't call base.OnPaintBackground(e) to prevent background painting
                //base.OnPaintBackground(pevent);
            }
        }
        private Ribbon _ribbon = new Ribbon();

        public Form1()
        {
            InitializeComponent();

            DrawingSurface rendersurface = new DrawingSurface(); // our control for SFML to draw on
            rendersurface.Size = new System.Drawing.Size(400, 400); // set our SFML surface control size to be 500 width & 500 height
            lblPlaceHolderDescription.Controls.Add(rendersurface); // add the SFML surface control to our form
            rendersurface.Location = new System.Drawing.Point(100, 100); // center our control on the form

            // initialize sfml
            SFML.Graphics.RenderWindow renderwindow = new SFML.Graphics.RenderWindow(rendersurface.Handle); // creates our SFML RenderWindow on our surface control

            // drawing loop
            while (lblPlaceHolderDescription.Visible) // loop while the window is open
            {
                System.Windows.Forms.Application.DoEvents(); // handle form events
                renderwindow.DispatchEvents(); // handle SFML events - NOTE this is still required when SFML is hosted in another window
                renderwindow.Clear(SFML.Graphics.Color.Yellow); // clear our SFML RenderWindow
                renderwindow.Display(); // display what SFML has drawn to the screen
            }
        }
       
        #region IRibbonForm Members

        public IntPtr WindowHandle
        {
            get
            {
                return this.Handle;
            }
        }

        public void RibbonHeightUpdated(int newHeight)
        {
            this.splitContainer1.SplitterDistance = newHeight;
        }

        #endregion

        private void Form1_Load(object sender, EventArgs e)
        {
            _ribbon.InitFramework(this);
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            _ribbon.DestroyFramework();
        }
    }
}
Title: Re: get SFML renderwindow on label problem
Post by: Laurent on April 01, 2014, 04:44:01 pm
This problem has nothing to do with your code. The error is pretty clear: the sfmlnet-graphics-2.dll (or its dependency csfml-graphics-2.dll) has an incorrect format. I guess this can happen when you mix 32 and 64 bits DLLs, for example.
Title: Re: Get SFML renderwindow on label problem
Post by: delio on April 01, 2014, 04:58:33 pm
I'm using window 64-bit.
So I've change all SFML's dll from 32-bit to 64-bit.
It gave new error.

I wonder that handling in label is the right way to show in WinForm?

(http://upic.me/i/6r/error1.png)

Title: Re: Get SFML renderwindow on label problem
Post by: Laurent on April 01, 2014, 05:04:05 pm
Quote
I'm using window 64-bit.
So I've change all SFML's dll from 32-bit to 64-bit.
SFML.Net and CSFML DLLs must match the architecture of your project, not your OS. We don't care about the OS, it can handle both architectures fine.

Quote
I wonder that handling in label is the right way to show in WinForm?
I guess you can do it in any kind of control. I've seen people using a Picture control as well. But again, this problem has nothing to do with your code. Any other SFML code would fail with the same error.
Title: Re: Get SFML renderwindow on label problem
Post by: delio on April 01, 2014, 05:25:14 pm
Thanks  :D, I've change architecture from "Any CPU" to "x64"

And I have another problem.
Code from my upper post, can build successfully.
I've call
renderwindow.Clear(SFML.Graphics.Color.Yellow);
but In label won't be yellow. It display white.

(http://upic.me/i/9u/eerror.png)


I've follow zsbzsb's code
http://en.sfml-dev.org/forums/index.php?topic=9141.msg61848#msg61848
------------------------------------------------------------------
PS.Sorry for posting wrong thread(I just saw it).
Title: Re: Get SFML renderwindow on label problem
Post by: zsbzsb on April 01, 2014, 06:43:27 pm
I posted a complete example of how to do this here (http://en.sfml-dev.org/forums/index.php?topic=12466.msg87073#msg87073).
Title: Re: Get SFML renderwindow on label problem
Post by: delio on April 01, 2014, 07:02:22 pm
but I want to display in a Panel. not making new form.

Programing.cs
Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using SFML;
using SFML.Audio;
using SFML.Window;
using SFML.Graphics;

namespace _01_AddingRibbonSupport
{
    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());
        }
    }
}

Form1.cs
Code: [Select]
using System;
using System.Windows.Forms;
using RibbonLib;
using RibbonLib.Interop;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SFML;
using SFML.Audio;
using SFML.Window;
using SFML.Graphics;

namespace _01_AddingRibbonSupport
{
    public partial class Form1 : Form, IRibbonForm
    {
        public class DrawingSurface : System.Windows.Forms.Control
        {
            protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
            {
                // don't call base.OnPaint(e) to prevent forground painting
                // base.OnPaint(e);
            }
            protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
            {
                // don't call base.OnPaintBackground(e) to prevent background painting
                //base.OnPaintBackground(pevent);
            }
        }
        private Ribbon _ribbon = new Ribbon();

        public Form1()
        {
            InitializeComponent();

            DrawingSurface rendersurface = new DrawingSurface(); // our control for SFML to draw on
            rendersurface.Size = new System.Drawing.Size(400, 400); // set our SFML surface control size to be 500 width & 500 height
            lblPlaceHolderDescription.Controls.Add(rendersurface); // add the SFML surface control to our form
            rendersurface.Location = new System.Drawing.Point(100, 100); // center our control on the form

            // initialize sfml
            SFML.Graphics.RenderWindow renderwindow = new SFML.Graphics.RenderWindow(rendersurface.Handle); // creates our SFML RenderWindow on our surface control

            // drawing loop
            while (lblPlaceHolderDescription.Visible) // loop while the window is open
            {
                System.Windows.Forms.Application.DoEvents(); // handle form events
                renderwindow.DispatchEvents(); // handle SFML events - NOTE this is still required when SFML is hosted in another window
                renderwindow.Clear(SFML.Graphics.Color.Yellow); // clear our SFML RenderWindow
                renderwindow.Display(); // display what SFML has drawn to the screen
            }
        }
       
        #region IRibbonForm Members

        public IntPtr WindowHandle
        {
            get
            {
                return this.Handle;
            }
        }

        public void RibbonHeightUpdated(int newHeight)
        {
            this.splitContainer1.SplitterDistance = newHeight;
        }

        #endregion

        private void Form1_Load(object sender, EventArgs e)
        {
            _ribbon.InitFramework(this);
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            _ribbon.DestroyFramework();
        }
    }
}

Thanks