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 =
new wxGLContext(
this);
57 void CWxGLCanvasBase::swapBuffers() { SwapBuffers(); }
58 void CWxGLCanvasBase::preRender() { OnPreRender(); }
59 void CWxGLCanvasBase::postRender() { OnPostRender(); }
60 void CWxGLCanvasBase::renderError(
const string& err_msg)
62 OnRenderError(err_msg.c_str());
65 void CWxGLCanvasBase::OnMouseDown(wxMouseEvent& event)
67 setMousePos(event.GetX(),
event.GetY());
68 setMouseClicked(
true);
70 void CWxGLCanvasBase::OnMouseUp(wxMouseEvent& )
72 setMouseClicked(
false);
75 void CWxGLCanvasBase::OnMouseMove(wxMouseEvent& event)
77 bool leftIsDown =
event.LeftIsDown();
79 if (leftIsDown || event.RightIsDown())
86 CamaraParams
params = cameraParams();
90 if (event.ShiftDown())
93 else if (event.ControlDown())
94 updateRotate(
params, X, Y);
97 updateOrbitCamera(
params, X, Y);
105 #if wxCHECK_VERSION(2, 9, 5) 106 wxTheApp->SafeYieldFor(
nullptr, wxEVT_CATEGORY_TIMER);
115 void CWxGLCanvasBase::OnMouseWheel(wxMouseEvent& event)
117 CamaraParams
params = cameraParams();
118 updateZoom(
params, event.GetWheelRotation());
126 static int WX_GL_ATTR_LIST[] = {WX_GL_DOUBLEBUFFER, WX_GL_RGBA,
127 WX_GL_DEPTH_SIZE, 24, 0};
129 CWxGLCanvasBase::CWxGLCanvasBase(
130 wxWindow* parent, wxWindowID
id,
const wxPoint& pos,
const wxSize&
size,
131 long style,
const wxString&
name)
134 parent,
id, WX_GL_ATTR_LIST, pos,
size,
135 style | wxFULL_REPAINT_ON_RESIZE,
name)
137 this->Bind(wxEVT_LEFT_DOWN, &CWxGLCanvasBase::OnMouseDown,
this);
138 this->Bind(wxEVT_RIGHT_DOWN, &CWxGLCanvasBase::OnMouseDown,
this);
139 this->Bind(wxEVT_LEFT_UP, &CWxGLCanvasBase::OnMouseUp,
this);
140 this->Bind(wxEVT_RIGHT_UP, &CWxGLCanvasBase::OnMouseUp,
this);
141 this->Bind(wxEVT_MOTION, &CWxGLCanvasBase::OnMouseMove,
this);
142 this->Bind(wxEVT_MOUSEWHEEL, &CWxGLCanvasBase::OnMouseWheel,
this);
143 this->Bind(wxEVT_CHAR, &CWxGLCanvasBase::OnChar,
this);
144 this->Bind(wxEVT_CHAR_HOOK, &CWxGLCanvasBase::OnChar,
this);
145 this->Bind(wxEVT_CREATE, &CWxGLCanvasBase::OnWindowCreation,
this);
147 this->Bind(wxEVT_SIZE, &CWxGLCanvasBase::OnSize,
this);
148 this->Bind(wxEVT_PAINT, &CWxGLCanvasBase::OnPaint,
this);
150 wxEVT_ERASE_BACKGROUND, &CWxGLCanvasBase::OnEraseBackground,
this);
151 this->Bind(wxEVT_ENTER_WINDOW, &CWxGLCanvasBase::OnEnterWindow,
this);
156 wxWindowCreateEvent dum;
157 OnWindowCreation(dum);
161 CWxGLCanvasBase::~CWxGLCanvasBase()
163 if (m_gl_context)
delete m_gl_context;
165 void CWxGLCanvasBase::OnChar(wxKeyEvent& event) { OnCharCustom(event); }
166 void CWxGLCanvasBase::Render()
175 SetCurrent(*m_gl_context);
188 OnPostRenderSwapBuffers(At, dc);
191 void CWxGLCanvasBase::OnEnterWindow(wxMouseEvent& WXUNUSED(event))
196 void CWxGLCanvasBase::OnPaint(wxPaintEvent& WXUNUSED(event)) { Render(); }
197 void CWxGLCanvasBase::OnSize(wxSizeEvent& event)
199 if (!m_parent->IsShown())
return;
203 GetClientSize(&
w, &h);
205 if (this->IsShownOnScreen())
212 SetCurrent(*m_gl_context);
214 resizeViewport(
w, h);
218 void CWxGLCanvasBase::OnEraseBackground(wxEraseEvent& WXUNUSED(event))
223 void CWxGLCanvasBase::InitGL()
230 SetCurrent(*m_gl_context);
232 static bool GLUT_INIT_DONE =
false;
236 GLUT_INIT_DONE =
true;
239 char* argv[1] = {
nullptr};
240 glutInit(&argc, argv);
249 #endif // MRPT_HAS_WXWIDGETS #define THROW_EXCEPTION(msg)
GLubyte GLubyte GLubyte GLubyte w
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.
GLuint const GLchar * name
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...
GLenum GLsizei GLsizei height
GLenum const GLfloat * params