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

Author Topic: GTKSharp for SFML  (Read 4084 times)

0 Members and 1 Guest are viewing this topic.

michax

  • Newbie
  • *
  • Posts: 2
    • View Profile
GTKSharp for SFML
« on: April 12, 2010, 03:09:36 am »
Hi,

I tried to include sfml RenderView in Gtk.Window, but i get in Console:

Code: [Select]
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

Code: [Select]

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;
}

}

Beliar

  • Newbie
  • *
  • Posts: 27
    • View Profile
GTKSharp for SFML
« Reply #1 on: September 09, 2010, 08:13:01 pm »
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"
Code: [Select]
[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"
Code: [Select]
[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:
Code: [Select]

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]
Debuggers don't remove bugs. They only show them in slow motion.

michax

  • Newbie
  • *
  • Posts: 2
    • View Profile
GTKSharp for SFML
« Reply #2 on: October 07, 2010, 06:32:36 pm »
Thanks a lot man ! I will test it and post result. Thanks a lot again for help !