【问题标题】:Why can't wxwidgets and sfml play nice?为什么 wxwidgets 和 sfml 不能很好玩?
【发布时间】:2014-10-27 02:39:31
【问题描述】:

我想将 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

【问题讨论】:

  • 那是因为您试图将其作为链接发布。将错误和代码直接放在您的帖子中。
  • @user1953923 请检查此markup help section,并在询问之前检查take the tour

标签: c++ gtk wxwidgets sfml


【解决方案1】:

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

仅供参考 m_wxwindow 是一个 GtkFixed 本身是一个 GtkContainer 这是一个 GtkWidget,所以如果你能找到如何使用 SFML 和原生 GtkContainerGtkWidget,你应该能够将它与 wxGTK 一起使用也不会出现太多问题。

祝你好运!

【讨论】:

    猜你喜欢
    • 2014-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-01
    • 1970-01-01
    • 2017-06-16
    • 1970-01-01
    相关资源
    最近更新 更多