为什么wxwidgets和sfml不能很好玩?

时间:2014-09-02 18:35:38

标签: c++ gtk wxwidgets sfml

我想将sfml与wxwidgets一起使用。我试图遵循一个相当过时的教程,因为没有更新的教程。

这里的教程:http://sfml-dev.org/tutorials/1.6/graphics-wxwidgets.php

本教程适用于sfml1.6和wxwidgets 2.x但是我想将sfml2.1与wxwidgets 3一起使用,但代码不会编译。显然win_gtk.h现在是一个私有标题,在gtk3中无法访问?此标头包含gtk_pizza。至于display()错误,我不知道那里有什么问题......无论如何要让一切都好看吗?

这是我的代码:

#include <SFML/Graphics.hpp>

#include <wx/wx.h>

#ifdef __WXGTK__
    #include <gdk/gdkx.h>
    #include <gtk/gtk.h>
    // #include <wx/gtk/win_gtk.h> this doesn't exist in wxwidgets3?
#endif


class wxSFMLCanvas : public wxControl, public sf::RenderWindow
{
public :

    wxSFMLCanvas(wxWindow* Parent = NULL, wxWindowID Id = -1, const wxPoint& Position = wxDefaultPosition,
                 const wxSize& Size = wxDefaultSize, long Style = 0);

    virtual ~wxSFMLCanvas();

private :

    DECLARE_EVENT_TABLE()

    virtual void OnUpdate();

    void OnIdle(wxIdleEvent&);

    void OnPaint(wxPaintEvent&);

    void OnEraseBackground(wxEraseEvent&);
};

void wxSFMLCanvas::OnIdle(wxIdleEvent&)
{
    // Send a paint message when the control is idle, to ensure maximum framerate
    Refresh();
}

void wxSFMLCanvas::OnPaint(wxPaintEvent&)
{
    // Prepare the control to be repainted
    wxPaintDC Dc(this);

    // Let the derived class do its specific stuff
    OnUpdate();

    // Display on screen
    Display();
}


wxSFMLCanvas::wxSFMLCanvas(wxWindow* Parent, wxWindowID Id, const wxPoint& Position, const wxSize& Size, long Style) :
wxControl(Parent, Id, Position, Size, Style)
{
    #ifdef __WXGTK__

        // GTK implementation requires to go deeper to find the
        // low-level X11 identifier of the widget
        gtk_widget_realize(m_wxwindow);
        gtk_widget_set_double_buffered(m_wxwindow, false);
        GdkWindow* Win = GTK_PIZZA(m_wxwindow)->bin_window;
        XFlush(GDK_WINDOW_XDISPLAY(Win));
        //sf::RenderWindow::Create(GDK_WINDOW_XWINDOW(Win));

    #else

        // Tested under Windows XP only (should work with X11
        // and other Windows versions - no idea about MacOS)
        //sf::RenderWindow::Create(GetHandle());

    #endif
}

以下是错误:

[greg@greg-desktop polyedit]$ make
g++ -g -I. -I/usr/lib/wx/include/gtk2-unicode-3.0 -I/usr/include/wx-3.0 -D_FILE_OFFSET_BITS=64 -DWXUSINGDLL -D__WXGTK__ -pthread -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/libdrm -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/harfbuzz   -MMD -MP -c -o .eobjs/./main.o main.cpp
main.cpp: In member function 'void wxSFMLCanvas::OnPaint(wxPaintEvent&)':
main.cpp:49:13: error: invalid use of incomplete type 'Display {aka struct _XDisplay}'
     Display();
             ^
In file included from /usr/include/wx-3.0/wx/cursor.h:69:0,
                 from /usr/include/wx-3.0/wx/event.h:21,
                 from /usr/include/wx-3.0/wx/wx.h:24,
                 from main.cpp:3:
/usr/include/wx-3.0/wx/utils.h:778:15: error: forward declaration of 'Display {aka struct _XDisplay}'
 inline struct _XDisplay *wxGetX11Display()
               ^
main.cpp: In constructor 'wxSFMLCanvas::wxSFMLCanvas(wxWindow*, wxWindowID, const wxPoint&, const wxSize&, long int)':
main.cpp:62:46: error: 'GTK_PIZZA' was not declared in this scope
         GdkWindow* Win = GTK_PIZZA(m_wxwindow)->bin_window

1 个答案:

答案 0 :(得分:0)

本教程确实已过时,在任何情况下使用私有wxGTK标头和实现细节绝不是一个好主意。我对SFML一无所知,但您需要找出其文档中描述的本机WindowHandle究竟是什么,然后您应该能够从wxGTK获取它。

仅供参考m_wxwindow GtkFixed本身就是GtkContainer GtkWidget,因此您可以了解如何将SFML与原生GtkContainer一起使用}或GtkWidget,您应该能够将它与wxGTK一起使用,而不会出现太多问题。

祝你好运!