mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-11-02 20:51:23 -07:00 
			
		
		
		
	Fix opencsg example on Win32
This commit is contained in:
		
							parent
							
								
									17de6ff51a
								
							
						
					
					
						commit
						558529146c
					
				
					 4 changed files with 51 additions and 33 deletions
				
			
		| 
						 | 
				
			
			@ -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
 | 
			
		||||
    )
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,11 +5,11 @@
 | 
			
		|||
 | 
			
		||||
#include <GL/glew.h>
 | 
			
		||||
 | 
			
		||||
#ifdef __APPLE__
 | 
			
		||||
#include <GLUT/glut.h>
 | 
			
		||||
#else
 | 
			
		||||
#include <GL/glut.h>
 | 
			
		||||
#endif
 | 
			
		||||
//#ifdef __APPLE__
 | 
			
		||||
//#include <GLUT/glut.h>
 | 
			
		||||
//#else
 | 
			
		||||
//#include <GL/glut.h>
 | 
			
		||||
//#endif
 | 
			
		||||
 | 
			
		||||
#include <boost/log/trivial.hpp>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -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; i<s.size(); ++i) {
 | 
			
		||||
        glutBitmapCharacter(GLUT_BITMAP_8_BY_13, s[i]);
 | 
			
		||||
    }
 | 
			
		||||
//    for (unsigned int i=0; i<s.size(); ++i) {
 | 
			
		||||
//        glutBitmapCharacter(GLUT_BITMAP_8_BY_13, s[i]);
 | 
			
		||||
//    }
 | 
			
		||||
    glEnable(GL_LIGHTING);
 | 
			
		||||
    glPopMatrix();
 | 
			
		||||
    glMatrixMode(GL_MODELVIEW);
 | 
			
		||||
| 
						 | 
				
			
			@ -347,21 +347,24 @@ void Display::clear_screen()
 | 
			
		|||
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Display::~Display()
 | 
			
		||||
{
 | 
			
		||||
    OpenCSG::freeResources();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Display::set_active(long width, long height)
 | 
			
		||||
{
 | 
			
		||||
    static int argc = 0;
 | 
			
		||||
    
 | 
			
		||||
    if (!m_initialized) {
 | 
			
		||||
        glewInit();
 | 
			
		||||
        glutInit(&argc, nullptr);
 | 
			
		||||
//        glutInit(&argc, nullptr);
 | 
			
		||||
        m_initialized = true;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    m_size = {width, height};
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    // gray background
 | 
			
		||||
    glClearColor(0.9f, 0.9f, 0.9f, 1.0f);
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    // Enable two OpenGL lights
 | 
			
		||||
    GLfloat light_diffuse[]   = { 1.0f,  1.0f,  0.0f,  1.0f};  // White diffuse light
 | 
			
		||||
    GLfloat light_position0[] = {-1.0f, -1.0f, -1.0f,  0.0f};  // Infinite light location
 | 
			
		||||
| 
						 | 
				
			
			@ -380,7 +383,7 @@ void Display::set_active(long width, long height)
 | 
			
		|||
    glEnable(GL_DEPTH_TEST);
 | 
			
		||||
    glEnable(GL_STENCIL_TEST);
 | 
			
		||||
    
 | 
			
		||||
    m_camera->set_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()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -303,6 +303,8 @@ public:
 | 
			
		|||
        : m_camera(camera ? camera : std::make_shared<PerspectiveCamera>())
 | 
			
		||||
    {}
 | 
			
		||||
    
 | 
			
		||||
    ~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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -8,7 +8,7 @@
 | 
			
		|||
// For compilers that support precompilation, includes "wx/wx.h".
 | 
			
		||||
#include <wx/wxprec.h>
 | 
			
		||||
#ifndef WX_PRECOMP
 | 
			
		||||
    #include <wx/wx.h>
 | 
			
		||||
#include <wx/wx.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include <wx/slider.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -31,7 +31,7 @@ using namespace Slic3r::GL;
 | 
			
		|||
 | 
			
		||||
class Canvas: public wxGLCanvas, public Slic3r::GL::Display
 | 
			
		||||
{
 | 
			
		||||
    std::unique_ptr<wxGLContext> m_context;
 | 
			
		||||
    shptr<wxGLContext> 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() {}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue