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

Author Topic: SFML.Net GTK# Integration Questions  (Read 6781 times)

0 Members and 1 Guest are viewing this topic.

josh123

  • Newbie
  • *
  • Posts: 17
    • View Profile
SFML.Net GTK# Integration Questions
« on: November 13, 2014, 05:26:40 pm »
In a simulator I am developing, I have used solely OpenGL for GUI, but my needs got a bit more complicated (File Chooser Dialog) and I think it is better that I bring in a GUI library. I am having trouble understanding how GTK integrates with SFML. Do GTK widgets embed themselves into a SFML window? Or does a SFML window embed itself into a GTK window? If so, can event handling still be done with SFML? It seems normally GTK apps take up the main thread with the Application.Run() call, does integrating mean I have to go multi-threaded?

I'm new to GTK so I am not sure if it provides the SFML functionality I am using (OpenGL rendering, Keyboard access), but would anyone suggest that perhaps my use of SFML is superfluous and using just GTK is better? I already have the simulator coded using SFML, so I would rather not switch completely unless I am not putting SFML to good use.

Thanks for any input.

dabbertorres

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
    • website/blog
Re: SFML.Net GTK# Integration Questions
« Reply #1 on: November 13, 2014, 06:23:48 pm »
a quick google search came up with this: https://lalaland.github.io/gtkGuide.html

josh123

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: SFML.Net GTK# Integration Questions
« Reply #2 on: November 13, 2014, 08:58:29 pm »
I saw that method, but I didn't know it could use X11/Quartz too. That's interesting. However I would rather use a single piece of platform independent code (rather then using all of those compiler directives) to integrate SFML and GTK if possible. Something along the lines of this https://github.com/SFML/SFML/wiki/Source:-GTK-integeration tutorial may allow for that, but I am not sure if event handling would still be possible with SFML API calls rather than GTK API calls.

Regardless I will consider the window handle method, but what I don't like is that it requires me to know all of the platforms the program might run on during coding it. This is reasonable, but coding an application that can run on more than just the programmer's expectations is always preferred.

josh123

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: SFML.Net GTK# Integration Questions
« Reply #3 on: November 14, 2014, 12:26:20 am »
On another note, since the application is already coded using SFML, I designed it to update every frame. Since GTK takes over the main loop, the application would not be able to update every frame unless something like this is used (from the tutorial I mentioned).

/// <summary>
/// Timer handler. Since GTK controlls the main loop we need this to poll SFML events.
/// </summary>
private void OnTimerElapsed()
{
    Gtk.Application.Invoke(
    delegate
    {
        DispatchEvents();
        Redraw();
        Display();
    });
 }
 

But I do not understand why the author calls the update code from the OnTimerElapsed() method. Maybe it happens every frame?

I have also been looking into a GUI library called TGUI.Net. It might be better in this situation because:
- It doesn't take over the main thread.
- It's widgets embed into a SFML window.
- Event handling can still be done through SFML without calling an update function from OnTimerElasped().

josh123

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: SFML.Net GTK# Integration Questions
« Reply #4 on: November 16, 2014, 02:01:31 am »
It appears the method of integration in the tutorial I linked just displays a borderless window over a gtk window. This is not good as gtk elements cannot be rendered ontop of the borderless window.

I've tried the window handle method as well. I retrieved the the window handle from the gtk window by using gdk_x11_display_get_xdisplay imported from libgtk-x11-2.0.so (running on GNU/Linux). However this resulted in an X Bad Window error. I also tried gdk_x11_drawable_get_xid and got a similar error. The tutorial by dabbertorres also says that the sf::Event system cannot be used, but I'm not sure why.

Regardless I decided to use another library. Either the currently in development SharpCEGui or the dead TGUI.Net project. They seem to be the only viable SFML/OpenGL based GUI toolkits available as most are dead and do not provide enough functionality.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: SFML.Net GTK# Integration Questions
« Reply #5 on: November 16, 2014, 11:07:14 am »
Quote
They seem to be the only viable SFML/OpenGL based GUI toolkits available as most are dead and do not provide enough functionality.

Out of curiosity, have you tried SFGUI and if so what functionality is it missing?

Ztormi

  • Jr. Member
  • **
  • Posts: 71
  • Web developer by day. Game developer by night.
    • View Profile
Re: SFML.Net GTK# Integration Questions
« Reply #6 on: November 16, 2014, 11:44:57 am »
SFGUI is C++

I think Gwen.NET is pretty good and simple to use.
« Last Edit: November 16, 2014, 11:47:16 am by Ztormi »

josh123

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: SFML.Net GTK# Integration Questions
« Reply #7 on: November 16, 2014, 08:29:21 pm »
SFGUI would be my first choice, but the project I am working on has to be in C#.

I saw GWEN.Net before, but I thought the project was dead because the one wiki page was written in 2011. I just checked the latest commit which was done in March 2014. Still probably dead, but better than TGUI.Net if it works. TGUI.Net seems to cause an SFML font warning when instantiating the label class. I'll consider GWEN.Net too, if I can get it to work.

Thanks for the suggestions.

josh123

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: SFML.Net GTK# Integration Questions
« Reply #8 on: November 17, 2014, 03:00:28 am »
Ztormi, were you ever able to get the GWEN.Net samples to work? In the SFML renderer version the sample throws a null reference exception upon allocating a UnitTest. Even when commenting it out, upon closing the application, I get a segmentation fault from SFML. The only sample that worked was the OpenTK renderer, but it rendered everything with a shade of red.

Ztormi

  • Jr. Member
  • **
  • Posts: 71
  • Web developer by day. Game developer by night.
    • View Profile
Re: SFML.Net GTK# Integration Questions
« Reply #9 on: November 17, 2014, 09:27:29 am »
Yes I did get them to work. I'll check when I get back home.
« Last Edit: November 17, 2014, 09:39:25 am by Ztormi »

Ztormi

  • Jr. Member
  • **
  • Posts: 71
  • Web developer by day. Game developer by night.
    • View Profile
Re: SFML.Net GTK# Integration Questions
« Reply #10 on: November 17, 2014, 04:19:38 pm »
So I redownloaded Gwen.NET from repository and redid it again.

- Postbuild events were borked so I just removed them and copied the files from media directory into bin. CSFML-dlls were also missing so you might want to copy all sfml dlls while you are at it.
- Changed target platform to x86.
- UnitTest-project threw an exception because it couldn't find 2 font files which were not included in sources so I just replaced them from code ("Motorwerk" and "French Script MT").

josh123

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: SFML.Net GTK# Integration Questions
« Reply #11 on: November 17, 2014, 11:59:24 pm »
I tried your suggestions but I still get a NullReferenceException at:
Point extents = new Point(0, sfFont.GetLineSpacing((uint)font.RealSize));
In SFML.cs which is in Gwen.Renderer.SFML. For some reason when sfFont is set to font.RendererData, font.RendererData is null.

However when switching to x86, MonoDevelop simply shows the disassembly. By looking at the stack trace I can tell it is the same issue.

I am not so sure this was designed to work with Mono on GNU/Linux.
« Last Edit: November 18, 2014, 12:09:24 am by josh123 »