我想用wxwidgets使用sfml。我試圖按照一個相當過時的教程,因爲沒有更近的教程。爲什麼wxwidgets和sfml不能很好玩?
教程這裏: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。至於顯示()錯誤,我不知道有什麼問題...無論如何,使一切發揮不錯?
這裏是我的代碼:
#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
}
下面是錯誤:
[[email protected] 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
這是因爲您試圖將其作爲鏈接發佈。把錯誤和你的代碼直接放在你的帖子中。 – 2014-09-02 18:43:51
@ user1953923在詢問之前,請檢查此[標記幫助部分](http://stackoverflow.com/editing-help#code),還請[參觀](http://stackoverflow.com/tour)! – 2014-09-02 18:49:50