Hello,
I'm trying to upgrade from SFML 2.1 to SFML 2.3, and I encouter some problems doing so.
I'm mixing GTK and SFML because I want to get touch events from GTK, and SFML does not provide touches yet.
My code was working fine with my previous SFML version, but updating it to 2.3 made my window displaying only white on a computer (not even my window.clear color), or displaying the background at start time on another computer.
It could be related to :
renderWindow.create(GDK_WINDOW_XID(gtk_widget_get_window(area)));
since it is where SFML and gtk are linked. But I don't really know what could be the problem since it build correctly.
So I've made a little project using the less code possible to show the behavior:
#include <SFML/Graphics/RenderWindow.hpp>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
gboolean onDraw(GtkWidget *widget, GdkEvent *event, gpointer user);
class LinuxWindow
{
public:
void create( sf::Vector2f size )
{
// Create the main window with a drawing area
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
area = gtk_drawing_area_new();
gtk_container_add(GTK_CONTAINER(window), area);
// Enable events for the drawing area
GdkEventMask mask;
mask = GDK_ALL_EVENTS_MASK;
gtk_widget_add_events(area,mask);
//Request a starting size(Otherwise you have no size, ie 0)
gtk_widget_set_size_request(area, size.x, size.y);
//Make the window real(usually delayed to show_all, but we need it sooner)
gtk_widget_realize(area);
//It is double buffered in itself, does not need gtk's help
gtk_widget_set_double_buffered(area, false);
// Create the SFML RenderWindow, using the native window handler
renderWindow.create(GDK_WINDOW_XID(gtk_widget_get_window(area)));
renderWindow.setVerticalSyncEnabled(true);
// Connect signal
g_signal_connect(area, "draw", G_CALLBACK(onDraw), NULL);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show_all(window);
}
sf::RenderWindow renderWindow;
private:
GtkWidget* window;
GtkWidget *area;
};
LinuxWindow linuxWindow;
//Gtk Render callback method
gboolean onDraw(GtkWidget *widget, GdkEvent *event, gpointer user)
{
linuxWindow.renderWindow.clear( sf::Color(157,210,237,255) );
linuxWindow.renderWindow.display();
gtk_widget_queue_draw(widget);
return true;
}
int main(int argc, char** argv)
{
gtk_init(&argc, &argv);
linuxWindow.create(sf::Vector2f(800, 600));
gtk_main();
return 0;
}
This code works fine with SFML 2.1 but not with SFML 2.3.
Has anybody any idea/suggestion ?