Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Get SFML renderwindow on label problem  (Read 2875 times)

0 Members and 1 Guest are viewing this topic.

delio

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
Get SFML renderwindow on label problem
« 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.


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();
        }
    }
}
« Last Edit: April 01, 2014, 04:43:22 pm by delio »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: get SFML renderwindow on label problem
« Reply #1 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.
Laurent Gomila - SFML developer

delio

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
Re: Get SFML renderwindow on label problem
« Reply #2 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?




Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Get SFML renderwindow on label problem
« Reply #3 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.
Laurent Gomila - SFML developer

delio

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
Re: Get SFML renderwindow on label problem
« Reply #4 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.




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).
« Last Edit: April 01, 2014, 05:48:15 pm by delio »

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Get SFML renderwindow on label problem
« Reply #5 on: April 01, 2014, 06:43:27 pm »
I posted a complete example of how to do this here.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

delio

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
Re: Get SFML renderwindow on label problem
« Reply #6 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
« Last Edit: April 02, 2014, 01:41:33 pm by delio »

 

anything