From 558529146cae7b031bedb97cc389fdab8b9cef3d Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 17 Dec 2019 16:27:28 +0100 Subject: [PATCH] Fix opencsg example on Win32 --- sandboxes/opencsg/CMakeLists.txt | 12 ++++++++--- sandboxes/opencsg/GLScene.cpp | 35 ++++++++++++++++---------------- sandboxes/opencsg/GLScene.hpp | 3 +++ sandboxes/opencsg/main.cpp | 34 +++++++++++++++++++------------ 4 files changed, 51 insertions(+), 33 deletions(-) diff --git a/sandboxes/opencsg/CMakeLists.txt b/sandboxes/opencsg/CMakeLists.txt index 651fbe82f7..cf66867a56 100644 --- a/sandboxes/opencsg/CMakeLists.txt +++ b/sandboxes/opencsg/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0) project(OpenCSG-example) -add_executable(opencsg_example main.cpp GLScene.hpp GLScene.cpp +add_executable(opencsg_example WIN32 main.cpp GLScene.hpp GLScene.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../src/slic3r/GUI/ProgressStatusBar.cpp ${CMAKE_CURRENT_SOURCE_DIR}/../../src/slic3r/GUI/I18N.hpp ${CMAKE_CURRENT_SOURCE_DIR}/../../src/slic3r/GUI/I18N.cpp) @@ -11,11 +11,17 @@ find_package(wxWidgets 3.1 REQUIRED COMPONENTS core base gl html) find_package(OpenGL REQUIRED) find_package(GLEW REQUIRED) find_package(OpenCSG REQUIRED) -find_package(GLUT REQUIRED) +# find_package(GLUT REQUIRED) include(${wxWidgets_USE_FILE}) target_link_libraries(opencsg_example libslic3r) target_include_directories(opencsg_example PRIVATE ${wxWidgets_INCLUDE_DIRS}) target_compile_definitions(opencsg_example PRIVATE ${wxWidgets_DEFINITIONS}) -target_link_libraries(opencsg_example ${wxWidgets_LIBRARIES} GLEW::GLEW OpenCSG::opencsg GLUT::GLUT OpenGL::OpenGL -lXrandr -lXext -lX11) + +target_link_libraries(opencsg_example ${wxWidgets_LIBRARIES} + OpenCSG::opencsg + GLEW::GLEW + OpenGL::GL + #-lXrandr -lXext -lX11 + ) diff --git a/sandboxes/opencsg/GLScene.cpp b/sandboxes/opencsg/GLScene.cpp index 1cfccb3b19..2c3d1ffcd1 100644 --- a/sandboxes/opencsg/GLScene.cpp +++ b/sandboxes/opencsg/GLScene.cpp @@ -5,11 +5,11 @@ #include -#ifdef __APPLE__ -#include -#else -#include -#endif +//#ifdef __APPLE__ +//#include +//#else +//#include +//#endif #include @@ -63,7 +63,7 @@ void renderfps () { static int msec = 0; last = msec; - msec = glutGet(GLUT_ELAPSED_TIME); +// msec = glutGet(GLUT_ELAPSED_TIME); if (last / 1000 != msec / 1000) { float correctedFps = fps * 1000.0f / float(msec - ancient); @@ -82,9 +82,9 @@ void renderfps () { glRasterPos2f(-1.0f, -1.0f); glDisable(GL_LIGHTING); std::string s = fpsStream.str(); - for (unsigned int i=0; iset_screen(width, height); + set_screen_size(width, height); } void Display::set_screen_size(long width, long height) @@ -389,8 +392,6 @@ void Display::set_screen_size(long width, long height) m_camera->set_screen(width, height); m_size = {width, height}; - - repaint(); } void Display::repaint() diff --git a/sandboxes/opencsg/GLScene.hpp b/sandboxes/opencsg/GLScene.hpp index 68cc59b01c..62863dc0b2 100644 --- a/sandboxes/opencsg/GLScene.hpp +++ b/sandboxes/opencsg/GLScene.hpp @@ -303,6 +303,8 @@ public: : m_camera(camera ? camera : std::make_shared()) {} + ~Display() override; + Camera * camera() { return m_camera.get(); } virtual void swap_buffers() = 0; @@ -370,5 +372,6 @@ public: void move_clip_plane(double z) { call_cameras(&Camera::set_clip_z, z); } }; + }} // namespace Slic3r::GL #endif // GLSCENE_HPP diff --git a/sandboxes/opencsg/main.cpp b/sandboxes/opencsg/main.cpp index c2f8a74aa1..3f764fe626 100644 --- a/sandboxes/opencsg/main.cpp +++ b/sandboxes/opencsg/main.cpp @@ -8,7 +8,7 @@ // For compilers that support precompilation, includes "wx/wx.h". #include #ifndef WX_PRECOMP - #include +#include #endif #include @@ -31,7 +31,7 @@ using namespace Slic3r::GL; class Canvas: public wxGLCanvas, public Slic3r::GL::Display { - std::unique_ptr m_context; + shptr m_context; public: void set_active(long w, long h) override @@ -54,6 +54,12 @@ public: m_context.reset(ctx); } + + ~Canvas() override + { + m_scene_cache.clear(); + m_context.reset(); + } }; class MyFrame: public wxFrame @@ -95,11 +101,11 @@ private: void bind_canvas_events_to_controller(); - void OnExit(wxCommandEvent& /*event*/) + void OnClose(wxCloseEvent& /*event*/) { RemoveChild(m_canvas.get()); - m_canvas->Destroy(); - Close( true ); + m_canvas.reset(); + Destroy(); } void OnOpen(wxCommandEvent &/*evt*/) @@ -117,10 +123,7 @@ private: void OnShown(wxShowEvent&) { const wxSize ClientSize = GetClientSize(); - m_canvas->set_active(ClientSize.x, ClientSize.y); - - m_canvas->set_screen_size(ClientSize.x, ClientSize.y); - m_canvas->repaint(); + m_canvas->set_active(ClientSize.x, ClientSize.y); // Do the repaint continuously Bind(wxEVT_IDLE, [this](wxIdleEvent &evt) { @@ -179,8 +182,9 @@ MyFrame::MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size): wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS | wxFULL_REPAINT_ON_RESIZE); m_ctl->add_display(m_canvas); - + wxPanel *control_panel = new wxPanel(this); + auto controlsizer = new wxBoxSizer(wxHORIZONTAL); auto slider_sizer = new wxBoxSizer(wxVERTICAL); auto console_sizer = new wxBoxSizer(wxVERTICAL); @@ -247,7 +251,9 @@ MyFrame::MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size): SetSizer(sizer); Bind(wxEVT_MENU, &MyFrame::OnOpen, this, wxID_OPEN); - Bind(wxEVT_MENU, &MyFrame::OnExit, this, wxID_EXIT); + Bind(wxEVT_CLOSE_WINDOW, &MyFrame::OnClose, this); + Bind(wxEVT_MENU, [this](wxCommandEvent &) { Close(true); }, wxID_EXIT); + Bind(wxEVT_SHOW, &MyFrame::OnShown, this, GetId()); Bind(wxEVT_SLIDER, [this, slider](wxCommandEvent &) { @@ -334,7 +340,7 @@ void MyFrame::bind_canvas_events_to_controller() m_canvas->Bind(wxEVT_PAINT, [this](wxPaintEvent &) { // This is required even though dc is not used otherwise. - wxPaintDC dc(this); + wxPaintDC dc(m_canvas.get()); // Set the OpenGL viewport according to the client size of this // canvas. This is done here rather than in a wxSizeEvent handler @@ -347,7 +353,7 @@ void MyFrame::bind_canvas_events_to_controller() m_canvas->set_screen_size(ClientSize.x, ClientSize.y); m_canvas->repaint(); - }); + }, m_canvas->GetId()); } void MyFrame::SLAJob::process() @@ -370,3 +376,5 @@ void MyFrame::SLAJob::process() m_print->process(); } + +//int main() {}