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

Author Topic: SFML 2.0 with gtkmm-2.4  (Read 2118 times)

0 Members and 1 Guest are viewing this topic.

Hazematman

  • Newbie
  • *
  • Posts: 3
    • View Profile
SFML 2.0 with gtkmm-2.4
« on: June 17, 2012, 04:12:58 am »
Hey! I've been trying to get SFML to work with gtkmm-2.4. I've managed to get SFML to work with GTK+ following this, but I would much rather use gtkmm. I was looking at this for creating an SFML widget with gtkmm but I couldn't get it to compile. (I did change the outdated SFML code to SFML 2.0 code)

It would be very helpful if anyone could show me anything about setting up SFML 2.0 with gtkmm 2.4.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: SFML 2.0 with gtkmm-2.4
« Reply #1 on: June 17, 2012, 01:11:25 pm »
Unless someone is also interested in getting SFML 2 running with gtkmm or has already done it, no one will dig into it.

You should provide what you've already done so far and at what point you failed then maybe people will know the next step rather then creating everything from the bottom up. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML 2.0 with gtkmm-2.4
« Reply #2 on: June 17, 2012, 02:24:54 pm »
It would be much simpler to just fix the compile errors that you now have with SFML 2.0.
Laurent Gomila - SFML developer

Hazematman

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: SFML 2.0 with gtkmm-2.4
« Reply #3 on: June 17, 2012, 06:51:10 pm »
After lots and lots of trial and error :/ I finally managed to get it work. I just ended up integrating the GTK+ alongside the GTKmm code, so I'm able to draw the whole user interface using Gtkmm but the SFML window is written for GTK+, I guess this will have to do :P

#include <SFML/Graphics.hpp>
#include <gtkmm.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
using namespace std;

sf::RenderWindow prog;

gboolean on_exposed(GtkWidget *widget,GdkEvent *event, gpointer user) {
        prog.clear(sf::Color(255,255,255));
        prog.display();
        gtk_widget_queue_draw(widget);
        return true;
}

class HelloWorld : public Gtk::Window {
        public:
                HelloWorld();
        protected:
                virtual bool on_expose();
                Gtk::Widget *area;
};

HelloWorld::HelloWorld(){
        set_title("SFML!");
        GtkWidget* carea;
        carea = gtk_drawing_area_new();
        area = Glib::wrap(carea);

        add(*area);

        GdkEventMask mask;
        mask = GDK_ALL_EVENTS_MASK;

        gtk_widget_add_events(area->gobj(),mask);
        gtk_widget_set_can_focus(area->gobj(),true);
        gtk_widget_set_size_request(area->gobj(),640,480);
        gtk_widget_realize(area->gobj());
        gtk_widget_set_double_buffered(area->gobj(),false);
#ifdef WINDOWS
        prog.create(GDK_WINDOW_HWND(area->gobj()->window));
#else
        prog.create(GDK_WINDOW_XID(area->gobj()->window));
#endif

        g_signal_connect(area->gobj(),"expose-event",G_CALLBACK(on_exposed),NULL);


        show_all_children();
}

bool HelloWorld::on_expose() {
        prog.clear(sf::Color(255,255,255));
        prog.display();
        area->queue_draw();
        return true;

}

int main(int argc,char *argv[]) {
        Gtk::Main kit(argc,argv);

        HelloWorld helloworld;

        Gtk::Main::run(helloworld);
}

 

anything