繁体   English   中英

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

[英]Writing simple wxWidgets application with an OpenGL context in a frame

我想知道如何在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。

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

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

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

至少这是在UNIX中对我有效的方法,当然在Windows中应该有等效的方法可以做到这一点。

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM