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

Author Topic: [SOLVED] RenderWindow as Control with own Render loop  (Read 3468 times)

0 Members and 1 Guest are viewing this topic.

Wafthrudnir

  • Newbie
  • *
  • Posts: 26
    • View Profile
[SOLVED] RenderWindow as Control with own Render loop
« on: July 15, 2015, 10:49:40 pm »
Hi,

I am using a WinForms UserControl with a private RenderWindow property referencing the UserControl handle.
I am struggleing with the update of my UC. I tried a thread and inside OnPaint (stupid me ;D).

Can anyone think of a good way to get it to work?! :/

Here's my Code:
    using System.Windows.Forms;
    using SFML.Graphics;
    using SFML.System;

    internal class Viewport : UserControl
    {
        private RenderWindow _renderwindow;

        public Viewport()
        {
            _renderwindow = new SFML.Graphics.RenderWindow(this.Handle);
        }

        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            //base.OnPaint(e);
        }

        protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
        {
            //base.OnPaintBackground(pevent);
        }
    }
 
« Last Edit: July 16, 2015, 07:25:00 pm by Wafthrudnir »
Black Metal + Coding = Win!

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: RenderWindow as Control with own Render loop
« Reply #1 on: July 16, 2015, 03:19:26 am »
Run the application loop yourself. The following should get you going.

http://en.sfml-dev.org/forums/index.php?topic=12466.msg87073#msg87073
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Wafthrudnir

  • Newbie
  • *
  • Posts: 26
    • View Profile
Re: RenderWindow as Control with own Render loop
« Reply #2 on: July 16, 2015, 07:04:19 pm »
Run the application loop yourself. The following should get you going.

http://en.sfml-dev.org/forums/index.php?topic=12466.msg87073#msg87073

Thanks zsbzsb for the answer,

but this is not quite what i am looking for. I managed to get it working based on this OpenTK Tutorial:
http://www.opentk.com/doc/chapter/2/glcontrol

The only thing I had to change is the call of Invalidate() to RaisePaintEvent(). So all the SFML stuff get's processed inside the OnPaint-Event of my c# UserControl now.

This way I am able to instantiate more than one SFML-Context/View (Both white rects are SFML-Controls each with it's own context, therefore the different zoom levels etc):


The only annoying thin is that Visual Studio gets an Exception in Design Mode :/ "Can't find module csfml-graphics2" ...
Edit: Never instantiate properties inside the class body ^^
« Last Edit: July 16, 2015, 07:25:34 pm by Wafthrudnir »
Black Metal + Coding = Win!