Reputation: 919
I would like to know how to use OpenGL with wxWidgets applications. For that purpose I have tried to use the code from the "OpenGL Cube" example from the wxWidgets library samples ( wxWidgets/trunk/samples/opengl - cube ). I am using CodeBlocks 13.12 on a Windows 7 x64 machine.
After creating a new wxWidgets 3.0 application project in CodeBlocks, copying the code from tutorial and adding "GL" folder with headers, I get many build errors ( undefined references mostly ). Before that, I have been writing simple wxWidgets applications and using OpenGL ( separately ) without major issues.
For starters, I would like to see a simple application that would create GL context inside a wxWidgets frame and, say, just draw a square, for simplicity. I think that would take much less effort than solving the build problems I have encountered, so I would be really glad if someone will be nice enough to provide a simple example code.
EDIT :
Here are the build messages, after unsuccessful build in 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)) ===|
I have added a line which (re)defines wxUSE_GLCANVAS to 1.
Upvotes: 0
Views: 4347
Reputation: 360
Not sure about the CodeBlocks element in this question, but if your link command uses wx-config to retrieve the list of compiler arguments then all you need to do is add --gl-libs
, as in:
g++ `wx-config --libs --gl-libs` -lGL -lGLU mycode.o -o myprogram
At least that's what works for me in UNIX, surely there should be an equivalent way to do this in Windows.
Upvotes: 3
Reputation: 22753
You need to explicitly link with wxmsw30u[d]_gl.lib
, ensure that it is listed in your project linker options.
Upvotes: 3
Reputation: 52689
I think the problem is that the default binaries built for wxWidgets are not compiled iwth opengL support included.
You might have to rebuild wxWidgets with the --with-opengl
flag.
Upvotes: 1