【问题标题】:Writing simple wxWidgets application with an OpenGL context in a frame在框架中使用 OpenGL 上下文编写简单的 wxWidgets 应用程序
【发布时间】:2014-07-19 02:47:49
【问题描述】:

我想知道如何在 wxWidgets 应用程序中使用 OpenGL。为此,我尝试使用 wxWidgets 库示例(wxWidgets/trunk/samples/opengl - cube)中的“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。

【问题讨论】:

  • wxWidgets 中有一个 Open GL Cube 示例.... :) 说真的,您的问题很可能是构建环境。告诉我们构建错误可能会更有帮助。
  • @gbjbaanb - 作为对问题的编辑,我添加了来自 CodeBlocks 的构建消息。

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


【解决方案1】:

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

【讨论】:

  • 感谢您的回答。你确定我应该使用 .lib,因为我使用 CodeBlocks 吗?我已将“libwxmsw30u_gl.a”和“libwxmsw30ud_gl.a”添加到项目-> 构建选项-> 链接器设置-> 链接库。以及 CodeBlocks -> MinGW -> lib 文件夹。我仍然收到 15 个错误。
  • 您不应该将库放在任何文件夹中,而是将项目配置为从正确的位置使用它们。如果你这样做,你不应该再有任何关于wxGLContextwxGLCanvas 符号的错误。
  • 我已将 "lib" 和 "lib64" 中的 "libwxmsw30u_gl.a" 和 "libwxmsw30ud_gl.a" 添加到链接器设置 -> CodeBlocks 项目中的链接库。我也将这些库的文件夹添加到项目 -> 搜索目录 -> 链接器中。以及搜索目录中的全局 CodeBlocks 编译器设置 -> 链接器。我仍然得到 15 个错误。我的想法已经不多了,因为我是初学者,到目前为止我所做的项目都很简单。
  • 抱歉,我不是 CB 用户,所以我不知道发生了什么,但很明显您的更改没有被考虑在内,这仅仅是因为您在使用 64 位库时应该会出错在 32 位版本中。如果您看到正在使用的实际链接器命令行,它可能仍然不包含这些库。
  • 好的,我明白了,很抱歉问你太具体的 CB 问题。也许我会尝试 CB 论坛。但实际上我可以在构建日志中看到命令行,它显示了这些库链接。这真的让我很困惑。
【解决方案2】:

不确定此问题中的 CodeBlocks 元素,但如果您的链接命令使用 wx-config 检索编译器参数列表,那么您只需添加 --gl-libs,如下所示:

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

至少这在 UNIX 中对我有用,当然在 Windows 中应该有等效的方法。

【讨论】:

  • 减轻了我在 ubuntu 机器上数小时的挫败感。
  • 这解决了我在 ubuntu 上的链接 gl 问题,谢谢。我只需要在 Project -> Build Options ... -> top of tree -> Linker Settings -> Other linker options (Code Blocks v13.12) 中将“wx-config --libs”更改为读取“wx-config --libs --gl-libs
【解决方案3】:

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

您可能必须使用 --with-opengl 标志重建 wxWidgets。

【讨论】:

  • 我拥有的 wxWidgets 是从 wxPack 中提取的。老实说,作为初学者,我不知道它们是如何在那里编译的,也不知道它们是否包含 OpenGL 支持。
  • 那么我会推荐一个不同的系统,也许是 Qt,或者在 wxWidgets 网站上阅读有关构建库的说明。
  • 我可以尝试了解更多关于 wxWidgets 的信息。我不会更改系统,因为 Widgets 比 Qt 和其他更适合我的目的,而且我之前已经在其中编码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-31
  • 2011-01-17
  • 1970-01-01
  • 2015-05-18
  • 2012-05-27
  • 2013-04-14
相关资源
最近更新 更多