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

Author Topic: how to work without renderwindow?  (Read 7706 times)

0 Members and 1 Guest are viewing this topic.

felipehenrique

  • Newbie
  • *
  • Posts: 8
    • View Profile
how to work without renderwindow?
« on: September 02, 2009, 10:14:04 pm »
Hello.
I am beginner in the SFML and have a question.
       
How to integrate SFML with windows forms?
The part of the window will use the windows forms and the part of the game will use the SFML.
Thanks.
(sorry for the bad english, I am brazilian)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
how to work without renderwindow?
« Reply #1 on: September 02, 2009, 10:59:09 pm »
You can create a RenderWindow from the handle of an existing Form.
Laurent Gomila - SFML developer

felipehenrique

  • Newbie
  • *
  • Posts: 8
    • View Profile
how to work without renderwindow?
« Reply #2 on: September 03, 2009, 02:23:06 am »
But how do this?
Could you give an example?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
how to work without renderwindow?
« Reply #3 on: September 03, 2009, 07:49:31 am »
Code: [Select]
RenderWindow window = new RenderWindow(form.Handle);
Laurent Gomila - SFML developer

felipehenrique

  • Newbie
  • *
  • Posts: 8
    • View Profile
how to work without renderwindow?
« Reply #4 on: September 03, 2009, 08:41:57 pm »
Thanks for your help.
But the application crashes as soon as it starts, do not know what is wrong.
Here is the project in visual studio if you can analyze what is wrong, I will be eternally grateful.
And sorry for my ignorance, it is because I am a little beginner.
http://www.4shared.com/file/129959446/cc2af22/WindowsFormsApplication2.html

CodeCriminal

  • Newbie
  • *
  • Posts: 18
    • View Profile
    • Email
how to work without renderwindow?
« Reply #5 on: October 06, 2009, 12:38:53 am »
Its not crashing, its just that the main loop is blocking the windows form from monitoring events sent to it.. i have this same problem.

If someone knew of a way to force a winform to monitor events from within a loop that would should solve the problem... kinda

[EDIT!]
Ok so i figured out how to get it setup properly, and working with winforms also its better to start with an empty project when you do this instead of starting a winforms project.

heres the code i have:
Code: [Select]
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;

namespace SFML_Application
{
class Window : Form
{
public Window()
{
InitializeComponent();
}

private void InitializeComponent()
{
this.SuspendLayout();
//
// Window
//
this.ClientSize = new System.Drawing.Size(784, 562);
this.Name = "Window";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "SFML Application";
this.ResumeLayout(false);

}
}

class SFMLApp
{
static void Main(string[] args)
{
Window Wnd = new Window();
SFML.Graphics.RenderWindow Scene = new SFML.Graphics.RenderWindow(Wnd.Handle);
SFML.Graphics.Shape Rect = SFML.Graphics.Shape.Rectangle(new SFML.Graphics.Vector2(0, 0),
new SFML.Graphics.Vector2(200, 100),
new SFML.Graphics.Color(255, 40, 40));


Wnd.Show();

while (Wnd.Created)
{
Application.DoEvents();
Scene.Clear();
Scene.Draw(Rect);
Scene.Display();
}
}
}
}


If you want to edit your winform, right click on the class that inherits from Form (Window i think) and select view designer.

There.

PS: it was Application.DoEvents( ) that allowed me to monitor events inside a loop.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
how to work without renderwindow?
« Reply #6 on: October 06, 2009, 08:50:19 am »
If you work with WinForms then you should let it control the main execution flow, and insert your SFML stuff at the proper locations.

This topic gives a good solution:
http://www.sfml-dev.org/forum/viewtopic.php?p=10720#10720
Laurent Gomila - SFML developer