【发布时间】: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