LiangliangNan / Easy3D

A lightweight, easy-to-use, and efficient C++ library for processing and rendering 3D data
GNU General Public License v3.0
1.35k stars 243 forks source link

Failed to use ModelPicker in QT_Viewer #152

Closed deepdarkbone closed 1 year ago

deepdarkbone commented 1 year ago

Hello! Thank you for your work. Based on Tutorial_204_Viewer_Qt I have built and run the qt_viewer successfully. I am trying to follow Tutorial_401_ModelPicker and use ModelPicker in overrided mousePressEvent in the qtviewer,but an error occurred

I see the following error messages while picking a model

E 31/01/2023 19:33:41.662 vertex_array_object.cpp:81] GL error:
       file: D:\MTRG_Software4.0\3rd_party\Easy3D-2.5.2\easy3d\renderer\vertex_array_object.cpp
       line: 81
       function: easy3d::VertexArrayObject::bind
       info: Invalid operation (The specified operation is not allowed in the current state)
E 31/01/2023 19:33:41.663 drawable.cpp:240] GL error:
        file: D:\MTRG_Software4.0\3rd_party\Easy3D-2.5.2\easy3d\renderer\drawable.cpp
        line: 240
        function: easy3d::Drawable::gl_draw
        info: Invalid operation (The specified operation is not allowed in the current state)

My code is as following, MyViewer Inherits form Viewer in Tutorial_204_Viewer

virtual void MyViewer::mousePressEvent(QMouseEvent* e) override;
void MyViewer::mousePressEvent(QMouseEvent* e) {
      int x = e->pos().x();
      int y = e->pos().y();
      ModelPicker picker(camera());
      auto model = picker.pick(models(), x, y);     //error occurred
      if (model)
          mark(model);

      QOpenGLWidget::mousePressEvent(e);
          update();
}

I find the error occurs in drawable_points when i debug, and I notice that some have reported the bug in drawable used in qtviewer. drawable->draw(camera()) I wonder how to solve the problem and use ModelPicker in qtviewer successfully.

Development/Running environment:

LiangliangNan commented 1 year ago

add makeCurrent(); before auto model = picker.pick(models(), x, y); and add doneCurrent(); after it.

deepdarkbone commented 1 year ago

I changed my code according your suggestion The function mark(model) can be called this time ,but there are new error messages

E 31/01/2023 21:04:56.895 framebuffer_object.cpp:761] GL error:
        file: D:\MTRG_Software4.0\3rd_party\Easy3D-2.5.2\easy3d\renderer\framebuffer_object.cpp
        line: 761
        function: easy3d::FramebufferObject::is_bound
        info: Invalid operation (The specified operation is not allowed in the current state)
E 31/01/2023 21:04:56.895 framebuffer_object.cpp:114] GL error:
        file: D:\MTRG_Software4.0\3rd_party\Easy3D-2.5.2\easy3d\renderer\framebuffer_object.cpp
        line: 114
        function: easy3d::FramebufferObject::clear
        info: Invalid operation (The specified operation is not allowed in the current state)
E 31/01/2023 21:04:56.895 framebuffer_object.cpp:118] GL error:
        file: D:\MTRG_Software4.0\3rd_party\Easy3D-2.5.2\easy3d\renderer\framebuffer_object.cpp
        line: 118
        function: easy3d::FramebufferObject::clear
        info: Invalid operation (The specified operation is not allowed in the current state)
E 31/01/2023 21:04:56.895 framebuffer_object.cpp:128] GL error:
        file: D:\MTRG_Software4.0\3rd_party\Easy3D-2.5.2\easy3d\renderer\framebuffer_object.cpp
        line: 128
        function: easy3d::FramebufferObject::clear
        info: Invalid operation (The specified operation is not allowed in the current state)
E 31/01/2023 21:04:56.895 framebuffer_object.cpp:133] GL error:
        file: D:\MTRG_Software4.0\3rd_party\Easy3D-2.5.2\easy3d\renderer\framebuffer_object.cpp
        line: 133
        function: easy3d::FramebufferObject::clear
        info: Invalid operation (The specified operation is not allowed in the current state)
E 31/01/2023 21:04:56.895 framebuffer_object.cpp:137] GL error:
        file: D:\MTRG_Software4.0\3rd_party\Easy3D-2.5.2\easy3d\renderer\framebuffer_object.cpp
        line: 137
        function: easy3d::FramebufferObject::clear
        info: Invalid operation (The specified operation is not allowed in the current state)
deepdarkbone commented 1 year ago

The picker works as followed, but error exists as i have mentioned before,

2023-01-31 214025 I have no idea whether it will affect other parts.

LiangliangNan commented 1 year ago

The reason is that an OpenGL function is called (in the destructor of the ModelPicker) when the OpenGL context is not made current. Here is the solution: make ModelPicker a member variable (by something like m_picker = new ModelPicker(camera())), and delete the picker in the destructor of the viewer.

deepdarkbone commented 1 year ago

The picker is working correctly now, thanks a lot for your help! Easy3d is really helpful for my work.

deepdarkbone commented 1 year ago

Meanwhile I have another question. In Tutorial_401_ModelPicker, mouse_press_event is overrided, but it seems that the former mouse_press_event is still working. When I override the mouse_press_event in qtviewer like Tutorial, the former event stops working, and I can't drag the model to rotate it.

deepdarkbone commented 1 year ago

Oh sorry, I find when i add pressed_button_ = e->button(); The problem is solved.

LiangliangNan commented 1 year ago

Glad to hear that. Good luck with your research!