使用框架中的OpenGL上下文编写简单的wxWidgets应用程序

时间:2014-05-29 14:39:01

标签: c++ opengl wxwidgets codeblocks windows-7-x64

我想知道如何将OpenGL与wxWidgets应用程序一起使用。为此,我尝试使用" OpenGL Cube"中的代码。来自wxWidgets库示例的示例(wxWidgets / trunk / samples / opengl - cube)。我在Windows 7 x64计算机上使用CodeBlocks 13.12。

在CodeBlocks中创建一个新的wxWidgets 3.0应用程序项目后,复制教程中的代码并添加" GL"带有标题的文件夹,我收到很多构建错误(主要是未定义的引用)。在此之前,我一直在编写简单的wxWidgets应用程序并使用OpenGL(单独)而没有重大问题。

对于初学者,我希望看到一个简单的应用程序,它可以在wxWidgets框架内创建GL上下文,比如说,为了简单起见,只绘制一个正方形。我认为这比解决我遇到的构建问题要花费更少的努力,所以如果有人能够提供一个简单的示例代码,我会很高兴。

编辑:

以下是在CodeBlocks中构建失败后的构建消息:

||=== Build: Debug in cubePrimercek (compiler: GNU GCC Compiler) ===|
cube.cpp|37|warning: "wxUSE_GLCANVAS" redefined [enabled by default]|
O:\SourceCode\Libraries\wxWidgets3.0\include\wx\setup.h|1318|note: this is the location of the previous definition|    obj\Debug\cube.o||In function `ZN13TestGLContextC2EP10wxGLCanvas':|
cube.cpp|146|undefined reference to `wxGLContext::wxGLContext(wxGLCanvas*, wxGLContext const*)'|
cube.cpp|148|undefined reference to `wxGLContext::SetCurrent(wxGLCanvas const&) const'|
cube.cpp|146|undefined reference to `wxGLContext::~wxGLContext()'|obj\Debug\cube.o||In function `ZN12TestGLCanvasC2EP8wxWindowPi':|
cube.cpp|338|undefined reference to `wxGLCanvas::wxGLCanvas(wxWindow*, int, int const*, wxPoint const&, wxSize const&, long, wxString const&, wxPalette const&)'|
cube.cpp|338|undefined reference to `wxGLCanvas::~wxGLCanvas()'|obj\Debug\cube.o||In function `ZN7MyFrameC2Eb':|
cube.cpp|500|undefined reference to `wxGLCanvasBase::IsDisplaySupported(int const*)'|obj\Debug\cube.o:cube.cpp:(.rdata+0x248)||undefined reference to `wxGLCanvas::sm_eventTable'|obj\Debug\cube.o:cube.cpp:(.rdata$_ZTV12TestGLCanvas[__ZTV12TestGLCanvas]+0x8)||undefined reference to `wxGLCanvas::GetClassInfo() const'|obj\Debug\cube.o:cube.cpp:(.rdata$_ZTV12TestGLCanvas[__ZTV12TestGLCanvas]+0x368)||undefined reference to `wxGLCanvas::SwapBuffers()'|obj\Debug\cube.o:cube.cpp:(.rdata$_ZTV12TestGLCanvas[__ZTV12TestGLCanvas]+0x370)||undefined reference to `wxGLCanvas::CreateDefaultPalette()'|obj\Debug\cube.o||In function `ZN12TestGLCanvasD1Ev':|
cube.h|66|undefined reference to `wxGLCanvas::~wxGLCanvas()'|
cube.h|66|undefined reference to `wxGLCanvas::~wxGLCanvas()'|obj\Debug\cube.o:cube.cpp:(.rdata$_ZTV13TestGLContext[__ZTV13TestGLContext]+0x8)||undefined reference to `wxGLContext::GetClassInfo() const'|obj\Debug\cube.o:cube.cpp:(.rdata$_ZTV13TestGLContext[__ZTV13TestGLContext]+0x1c)||undefined reference to `wxGLContext::SetCurrent(wxGLCanvas const&) const'|obj\Debug\cube.o||In function `ZN13TestGLContextD1Ev':|    
cube.h|18|undefined reference to `wxGLContext::~wxGLContext()'|
||=== Build failed: 15 error(s), 1 warning(s) (0 minute(s), 9 second(s)) ===|

我添加了一行(重新)将wxUSE_GLCANVAS定义为1.

3 个答案:

答案 0 :(得分:3)

您需要明确链接wxmsw30u[d]_gl.lib,确保它列在项目链接器选项中。

答案 1 :(得分:3)

在这个问题中不确定CodeBlocks元素,但是如果你的link命令使用wx-config来检索编译器参数列表,那么你需要做的就是添加--gl-libs,如:

g++ `wx-config --libs --gl-libs` -lGL -lGLU mycode.o -o myprogram

至少在UNIX中对我有用的东西,肯定应该有一种在Windows中执行此操作的方法。

答案 2 :(得分:1)

我认为问题是为wxWidgets构建的默认二进制文件不会在包含opengL支持的情况下编译。

您可能需要使用--with-opengl标志重建wxWidgets。

相关问题