16 #if MRPT_HAS_WXWIDGETS && MRPT_HAS_OPENGL_GLUT 24 #if MRPT_HAS_OPENGL_GLUT 25 #ifdef MRPT_OS_WINDOWS 31 #include <OpenGL/gl.h> 32 #include <OpenGL/glu.h> 33 #include <GLUT/glut.h> 38 #ifdef HAVE_FREEGLUT_EXT_H 39 #include <GL/freeglut_ext.h> 46 #error "OpenGL required: set wxUSE_GLCANVAS to 1 and rebuild wxWidgets" 53 void CWxGLCanvasBase::OnWindowCreation(wxWindowCreateEvent& ev)
55 if (!m_gl_context) m_gl_context =
new wxGLContext(
this);
58 void CWxGLCanvasBase::swapBuffers() { SwapBuffers(); }
59 void CWxGLCanvasBase::preRender() { OnPreRender(); }
60 void CWxGLCanvasBase::postRender() { OnPostRender(); }
61 void CWxGLCanvasBase::renderError(
const string& err_msg)
63 OnRenderError(
_U(err_msg.c_str()));
66 void CWxGLCanvasBase::OnMouseDown(wxMouseEvent& event)
68 setMousePos(event.GetX(),
event.GetY());
69 setMouseClicked(
true);
71 void CWxGLCanvasBase::OnMouseUp(wxMouseEvent& )
73 setMouseClicked(
false);
76 void CWxGLCanvasBase::OnMouseMove(wxMouseEvent& event)
78 bool leftIsDown =
event.LeftIsDown();
80 if (leftIsDown || event.RightIsDown())
87 CamaraParams
params = cameraParams();
91 if (event.ShiftDown())
94 else if (event.ControlDown())
95 updateRotate(
params, X, Y);
98 updateOrbitCamera(
params, X, Y);
106 #if wxCHECK_VERSION(2, 9, 5) 107 wxTheApp->SafeYieldFor(
nullptr, wxEVT_CATEGORY_TIMER);
116 void CWxGLCanvasBase::OnMouseWheel(wxMouseEvent& event)
118 CamaraParams
params = cameraParams();
119 updateZoom(
params, event.GetWheelRotation());
127 static int WX_GL_ATTR_LIST[] = {WX_GL_DOUBLEBUFFER, WX_GL_RGBA,
128 WX_GL_DEPTH_SIZE, 24, 0};
130 CWxGLCanvasBase::CWxGLCanvasBase(
131 wxWindow* parent, wxWindowID
id,
const wxPoint& pos,
const wxSize&
size,
132 long style,
const wxString&
name)
135 parent,
id, WX_GL_ATTR_LIST, pos,
size,
136 style | wxFULL_REPAINT_ON_RESIZE,
name)
138 this->Bind(wxEVT_LEFT_DOWN, &CWxGLCanvasBase::OnMouseDown,
this);
139 this->Bind(wxEVT_RIGHT_DOWN, &CWxGLCanvasBase::OnMouseDown,
this);
140 this->Bind(wxEVT_LEFT_UP, &CWxGLCanvasBase::OnMouseUp,
this);
141 this->Bind(wxEVT_RIGHT_UP, &CWxGLCanvasBase::OnMouseUp,
this);
142 this->Bind(wxEVT_MOTION, &CWxGLCanvasBase::OnMouseMove,
this);
143 this->Bind(wxEVT_MOUSEWHEEL, &CWxGLCanvasBase::OnMouseWheel,
this);
144 this->Bind(wxEVT_CHAR, &CWxGLCanvasBase::OnChar,
this);
145 this->Bind(wxEVT_CHAR_HOOK, &CWxGLCanvasBase::OnChar,
this);
146 this->Bind(wxEVT_CREATE, &CWxGLCanvasBase::OnWindowCreation,
this);
148 this->Bind(wxEVT_SIZE, &CWxGLCanvasBase::OnSize,
this);
149 this->Bind(wxEVT_PAINT, &CWxGLCanvasBase::OnPaint,
this);
151 wxEVT_ERASE_BACKGROUND, &CWxGLCanvasBase::OnEraseBackground,
this);
152 this->Bind(wxEVT_ENTER_WINDOW, &CWxGLCanvasBase::OnEnterWindow,
this);
157 wxWindowCreateEvent dum;
158 OnWindowCreation(dum);
162 CWxGLCanvasBase::~CWxGLCanvasBase() {
delete_safe(m_gl_context); }
163 void CWxGLCanvasBase::OnChar(wxKeyEvent& event) { OnCharCustom(event); }
164 void CWxGLCanvasBase::Render()
173 SetCurrent(*m_gl_context);
186 OnPostRenderSwapBuffers(At, dc);
189 void CWxGLCanvasBase::OnEnterWindow(wxMouseEvent& WXUNUSED(event))
194 void CWxGLCanvasBase::OnPaint(wxPaintEvent& WXUNUSED(event)) { Render(); }
195 void CWxGLCanvasBase::OnSize(wxSizeEvent& event)
197 if (!m_parent->IsShown())
return;
201 GetClientSize(&
w, &h);
203 if (this->IsShownOnScreen())
210 SetCurrent(*m_gl_context);
212 resizeViewport(
w, h);
216 void CWxGLCanvasBase::OnEraseBackground(wxEraseEvent& WXUNUSED(event))
221 void CWxGLCanvasBase::InitGL()
228 SetCurrent(*m_gl_context);
230 static bool GLUT_INIT_DONE =
false;
234 GLUT_INIT_DONE =
true;
237 char* argv[1] = {
nullptr};
238 glutInit(&argc, argv);
247 #endif // MRPT_HAS_WXWIDGETS Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
#define THROW_EXCEPTION(msg)
GLubyte GLubyte GLubyte GLubyte w
void delete_safe(T *&ptr)
Calls "delete" to free an object only if the pointer is not nullptr, then set the pointer to NULL...
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