16 #if MRPT_HAS_WXWIDGETS && MRPT_HAS_OPENGL_GLUT 18 #if MRPT_HAS_OPENGL_GLUT 25 #include <GLUT/glut.h> 26 #include <OpenGL/gl.h> 27 #include <OpenGL/glu.h> 32 #ifdef HAVE_FREEGLUT_EXT_H 33 #include <GL/freeglut_ext.h> 40 #error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild wxWidgets" 52 void CWxGLCanvasBase::OnWindowCreation(wxWindowCreateEvent& ev)
54 if (!m_gl_context) m_gl_context = std::make_unique<wxGLContext>(
this);
57 void CWxGLCanvasBase::swapBuffers()
61 SetCurrent(*m_gl_context);
65 void CWxGLCanvasBase::preRender() { OnPreRender(); }
66 void CWxGLCanvasBase::postRender() { OnPostRender(); }
67 void CWxGLCanvasBase::renderError(
const string& err_msg)
69 OnRenderError(err_msg.c_str());
72 void CWxGLCanvasBase::OnMouseDown(wxMouseEvent& event)
74 setMousePos(event.GetX(),
event.GetY());
75 setMouseClicked(
true);
77 void CWxGLCanvasBase::OnMouseUp(wxMouseEvent& )
79 setMouseClicked(
false);
82 void CWxGLCanvasBase::OnMouseMove(wxMouseEvent& event)
84 bool leftIsDown =
event.LeftIsDown();
90 if (leftIsDown || event.RightIsDown())
93 CamaraParams
params = cameraParams();
97 if (event.ShiftDown())
100 else if (event.ControlDown())
101 updateRotate(
params, X, Y);
104 updateOrbitCamera(
params, X, Y);
112 #if wxCHECK_VERSION(2, 9, 5) 113 wxTheApp->SafeYieldFor(
nullptr, wxEVT_CATEGORY_TIMER);
124 void CWxGLCanvasBase::OnMouseWheel(wxMouseEvent& event)
126 CamaraParams
params = cameraParams();
127 updateZoom(
params, event.GetWheelRotation());
136 static int WX_GL_ATTR_LIST[] = {
137 WX_GL_DOUBLEBUFFER, WX_GL_RGBA,
138 WX_GL_DEPTH_SIZE, 24,
139 #if wxCHECK_VERSION(3, 0, 3) 140 WX_GL_MAJOR_VERSION, 3,
141 WX_GL_MINOR_VERSION, 1,
148 CWxGLCanvasBase::CWxGLCanvasBase(
149 wxWindow* parent, wxWindowID
id,
const wxPoint& pos,
const wxSize&
size,
150 long style,
const wxString& name)
153 parent, id, WX_GL_ATTR_LIST, pos,
size,
154 style | wxFULL_REPAINT_ON_RESIZE, name)
156 this->Bind(wxEVT_LEFT_DOWN, &CWxGLCanvasBase::OnMouseDown,
this);
157 this->Bind(wxEVT_RIGHT_DOWN, &CWxGLCanvasBase::OnMouseDown,
this);
158 this->Bind(wxEVT_LEFT_UP, &CWxGLCanvasBase::OnMouseUp,
this);
159 this->Bind(wxEVT_RIGHT_UP, &CWxGLCanvasBase::OnMouseUp,
this);
160 this->Bind(wxEVT_MOTION, &CWxGLCanvasBase::OnMouseMove,
this);
161 this->Bind(wxEVT_MOUSEWHEEL, &CWxGLCanvasBase::OnMouseWheel,
this);
162 this->Bind(wxEVT_CHAR, &CWxGLCanvasBase::OnChar,
this);
163 this->Bind(wxEVT_CHAR_HOOK, &CWxGLCanvasBase::OnChar,
this);
164 this->Bind(wxEVT_CREATE, &CWxGLCanvasBase::OnWindowCreation,
this);
166 this->Bind(wxEVT_SIZE, &CWxGLCanvasBase::OnSize,
this);
167 this->Bind(wxEVT_PAINT, &CWxGLCanvasBase::OnPaint,
this);
169 wxEVT_ERASE_BACKGROUND, &CWxGLCanvasBase::OnEraseBackground,
this);
170 this->Bind(wxEVT_ENTER_WINDOW, &CWxGLCanvasBase::OnEnterWindow,
this);
175 wxWindowCreateEvent dum;
176 OnWindowCreation(dum);
180 void CWxGLCanvasBase::OnChar(wxKeyEvent& event) { OnCharCustom(event); }
181 void CWxGLCanvasBase::Render()
190 SetCurrent(*m_gl_context);
200 GetClientSize(&width, &height);
201 double At = renderCanvas(width, height);
203 OnPostRenderSwapBuffers(At, dc);
206 void CWxGLCanvasBase::OnEnterWindow(wxMouseEvent& WXUNUSED(event))
211 void CWxGLCanvasBase::OnPaint(wxPaintEvent& WXUNUSED(event)) { Render(); }
212 void CWxGLCanvasBase::OnSize(wxSizeEvent& event)
214 if (!m_parent->IsShown())
return;
218 GetClientSize(&w, &h);
220 if (this->IsShownOnScreen())
227 SetCurrent(*m_gl_context);
229 resizeViewport(w, h);
233 void CWxGLCanvasBase::OnEraseBackground(wxEraseEvent& WXUNUSED(event))
238 void CWxGLCanvasBase::InitGL()
245 SetCurrent(*m_gl_context);
247 static bool GLUT_INIT_DONE =
false;
251 GLUT_INIT_DONE =
true;
254 char*
argv[1] = {
nullptr};
264 #endif // MRPT_HAS_WXWIDGETS #define THROW_EXCEPTION(msg)
size_t size(const MATRIXLIKE &m, const int dim)
mrpt::vision::TStereoCalibParams params
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
The namespace for 3D scene representation and rendering.
Classes for creating GUI windows for 2D and 3D visualization.
This base class implements a working with opengl::Camera and a OpenGL canvas, and it's used in gui::C...