SFML community forums
Bindings - other languages => DotNet => Topic started by: michax on April 12, 2010, 03:09:36 am
-
Hi,
I tried to include sfml RenderView in Gtk.Window, but i get in Console:
Failed to get device context of window -- cannot create OpenGL
Some details:
App launched without any exceptions. GTK window appeard but without
black screen of RenderWindow.
Is it possible to put SFML in Window or Custom Widget ? I tried both with
the same "bad" result. I tried to include RenderWindow in Window Form and it work flawless.
Code of Class extended by Gtk.Window
using System;
using Gtk;
using SFML.Graphics;
using SFML.Window;
public partial class MainWindow : Gtk.Window
{
public MainWindow () : base(Gtk.WindowType.Toplevel)
{
Build ();
RenderWindow render = new RenderWindow(this.Handle);
render.Clear();
render.Display();
}
protected void OnDeleteEvent (object sender, DeleteEventArgs a)
{
Application.Quit ();
a.RetVal = true;
}
}
-
If you, or someone else, is still interested in this i have found a way to use SFML with a GTK-Sharp widget.
First you need to disable DoubleBuffering (widget.DoubleBuffered = false), otherwise everything you draw will be overwritten with the widgets background color.
Then you need the gdk handle/xid. Currently the only way is to call a function from a shared library.
For windows this is (tested): "IntPtr gdk_win32_drawable_get_handle(IntPtr window)" in "libgdk-win32-2.0-0.dll"
[DllImport("libgdk-win32-2.0-0.dll")]
static extern IntPtr gdk_win32_drawable_get_handle(IntPtr window);
For linux this is (Tested): "IntPtr gdk_x11_drawable_get_xid(IntPtr window)" in "gdk-x11-2.0"
[DllImport("gdk-x11-2.0")]
static extern IntPtr gdk_x11_drawable_get_xid(IntPtr window);
You have to call that function using widget.GdkWindow.Handle and pass the returned value to the RenderWindow constructor.
Example:
IntPtr tmpHandle = gdk_win32_drawable_get_handle(widget.GdkWindow.Handle);
SFMLApp = new RenderWindow(tmpHandle);
I have tested this with DrawingArea, but it should work on any other widgets too.
[edit]
Tested with Linux: Works
Events work when calling RenderWindow.Dispatch()
[/edit]
-
Thanks a lot man ! I will test it and post result. Thanks a lot again for help !