From 17e83d573d6a4e3f58267c14ab8c81b5bf7be6ea Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 8 Jan 2021 11:40:09 +0100 Subject: [PATCH] Fix demos --- AABB_tree/demo/AABB_tree/AABB_demo.cpp | 18 ++++-- AABB_tree/demo/AABB_tree/Scene.cpp | 34 ++++++----- AABB_tree/demo/AABB_tree/Scene.h | 2 +- .../demo/Alpha_shapes_3/Alpha_shape_3.cpp | 22 +++++-- Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.cpp | 28 ++++----- .../Circular_kernel_3/Circular_kernel_3.cpp | 18 ++++-- .../demo/Circular_kernel_3/Viewer.cpp | 30 +++++----- .../Linear_cell_complex_3_demo.cpp | 8 +-- .../Linear_cell_complex/basic_viewer.h | 57 ++++++++++--------- .../periodic_3_triangulation_3_demo.cpp | 6 ++ .../Periodic_Lloyd_3/Periodic_Lloyd_3.cpp | 15 +++-- .../Principal_component_analysis/PCA_demo.cpp | 10 ++++ .../demo/Triangulation_3/T3_demo.cpp | 14 +++-- 13 files changed, 163 insertions(+), 99 deletions(-) diff --git a/AABB_tree/demo/AABB_tree/AABB_demo.cpp b/AABB_tree/demo/AABB_tree/AABB_demo.cpp index c69f7aa1281..061036cd9cd 100644 --- a/AABB_tree/demo/AABB_tree/AABB_demo.cpp +++ b/AABB_tree/demo/AABB_tree/AABB_demo.cpp @@ -23,14 +23,24 @@ int main(int argc, char **argv) { + QSurfaceFormat fmt; +#ifdef Q_OS_MAC + fmt.setVersion(4, 1); +#else + fmt.setVersion(4, 3); +#endif + fmt.setRenderableType(QSurfaceFormat::OpenGL); + fmt.setProfile(QSurfaceFormat::CoreProfile); + fmt.setOption(QSurfaceFormat::DebugContext); + QSurfaceFormat::setDefaultFormat(fmt); + //for windows +#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)) + QApplication::setAttribute(Qt::AA_UseDesktopOpenGL); +#endif QApplication app(argc, argv); app.setOrganizationDomain("inria.fr"); app.setOrganizationName("INRIA"); app.setApplicationName("AABB tree demo"); - //for windows -#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)) - app.setAttribute(Qt::AA_UseDesktopOpenGL); -#endif // Import resources from libCGALQt (Qt5). CGAL_QT_INIT_RESOURCES; diff --git a/AABB_tree/demo/AABB_tree/Scene.cpp b/AABB_tree/demo/AABB_tree/Scene.cpp index 69ba683a21b..a48a517423a 100644 --- a/AABB_tree/demo/AABB_tree/Scene.cpp +++ b/AABB_tree/demo/AABB_tree/Scene.cpp @@ -91,8 +91,8 @@ void Scene::compile_shaders() //Vertex source code const char vertex_source[] = { - "#version 120 \n" - "attribute highp vec4 vertex;\n" + "#version 150 \n" + "in highp vec4 vertex;\n" "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 f_matrix;\n" "void main(void)\n" @@ -103,10 +103,11 @@ void Scene::compile_shaders() //Vertex source code const char fragment_source[] = { - "#version 120 \n" + "#version 150 \n" "uniform highp vec4 color; \n" + "out highp vec4 out_color; \n" "void main(void) { \n" - "gl_FragColor = color; \n" + "out_color = color; \n" "} \n" "\n" }; @@ -139,26 +140,27 @@ void Scene::compile_shaders() //Vertex source code const char tex_vertex_source[] = { - "#version 120 \n" - "attribute highp vec4 vertex;\n" - "attribute highp vec2 tex_coord; \n" + "#version 150 \n" + "in highp vec4 vertex;\n" + "in highp vec2 tex_coord; \n" "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 f_matrix;\n" - "varying highp vec2 texc;\n" + "out highp vec2 texc;\n" "void main(void)\n" "{\n" " gl_Position = mvp_matrix * f_matrix * vertex;\n" - " texc = tex_coord;\n" + " texc = tex_coord;\n" "}" }; //Vertex source code const char tex_fragment_source[] = { - "#version 120 \n" + "#version 150 \n" "uniform sampler2D texture;\n" - "varying highp vec2 texc;\n" + "in highp vec2 texc;\n" + "out highp vec4 out_color; \n" "void main(void) { \n" - "gl_FragColor = texture2D(texture, texc.st);\n" + "out_color = texture2D(texture, texc.st);\n" "} \n" "\n" }; @@ -1319,12 +1321,8 @@ void Scene::deactivate_cutting_plane() } void Scene::initGL() { - gl = new QOpenGLFunctions_2_1(); - if(!gl->initializeOpenGLFunctions()) - { - qFatal("ERROR : OpenGL Functions not initialized. Check your OpenGL Verison (should be >=3.3)"); - exit(1); - } + gl = new QOpenGLFunctions(); + gl->initializeOpenGLFunctions(); gl->glGenTextures(1, &textureId); compile_shaders(); diff --git a/AABB_tree/demo/AABB_tree/Scene.h b/AABB_tree/demo/AABB_tree/Scene.h index 95ea74cdc33..44d7b8239ce 100644 --- a/AABB_tree/demo/AABB_tree/Scene.h +++ b/AABB_tree/demo/AABB_tree/Scene.h @@ -86,7 +86,7 @@ public: private: // member data - QOpenGLFunctions_2_1 *gl; + QOpenGLFunctions *gl; Bbox m_bbox; Polyhedron *m_pPolyhedron; std::list m_points; diff --git a/Alpha_shapes_3/demo/Alpha_shapes_3/Alpha_shape_3.cpp b/Alpha_shapes_3/demo/Alpha_shapes_3/Alpha_shape_3.cpp index dbe053e9824..a83e4ae1683 100644 --- a/Alpha_shapes_3/demo/Alpha_shapes_3/Alpha_shape_3.cpp +++ b/Alpha_shapes_3/demo/Alpha_shapes_3/Alpha_shape_3.cpp @@ -8,15 +8,27 @@ int main(int argc, char** argv) { - QApplication application(argc,argv); + QSurfaceFormat fmt; +#ifdef Q_OS_MAC + fmt.setVersion(4, 1); +#else + fmt.setVersion(4, 3); +#endif + fmt.setRenderableType(QSurfaceFormat::OpenGL); + fmt.setProfile(QSurfaceFormat::CoreProfile); + fmt.setOption(QSurfaceFormat::DebugContext); + QSurfaceFormat::setDefaultFormat(fmt); + + //for Windows +#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)) + QApplication::setAttribute(Qt::AA_UseDesktopOpenGL); +#endif + + QApplication application(argc,argv); application.setOrganizationDomain("geometryfactory.com"); application.setOrganizationName("GeometryFactory"); application.setApplicationName("Alpha Shape Reconstruction"); - //for Windows -#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)) - application.setAttribute(Qt::AA_UseDesktopOpenGL); -#endif // Import resources from libCGALQt (Qt5). // See https://doc.qt.io/qt-5/qdir.html#Q_INIT_RESOURCE diff --git a/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.cpp b/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.cpp index a30e7a9a133..ad0e388412c 100644 --- a/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.cpp +++ b/Alpha_shapes_3/demo/Alpha_shapes_3/Viewer.cpp @@ -29,14 +29,14 @@ void Viewer::compile_shaders() //Vertex source code const char vertex_source[] = { - "#version 120 \n" - "attribute highp vec4 vertex;\n" - "attribute highp vec3 normal;\n" + "#version 150 \n" + "in highp vec4 vertex;\n" + "in highp vec3 normal;\n" "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 mv_matrix; \n" - "varying highp vec4 fP; \n" - "varying highp vec3 fN; \n" + "out highp vec4 fP; \n" + "out highp vec3 fN; \n" "void main(void)\n" "{\n" " fP = mv_matrix * vertex; \n" @@ -47,15 +47,16 @@ void Viewer::compile_shaders() //Fragment source code const char fragment_source[] = { - "#version 120 \n" - "varying highp vec4 fP; \n" - "varying highp vec3 fN; \n" + "#version 150 \n" + "in highp vec4 fP; \n" + "in highp vec3 fN; \n" "uniform highp vec4 color; \n" "uniform highp vec4 light_pos; \n" "uniform highp vec4 light_diff; \n" "uniform highp vec4 light_spec; \n" "uniform highp vec4 light_amb; \n" "uniform float spec_power ; \n" + "out highp vec4 out_color; \n" "void main(void) { \n" @@ -70,7 +71,7 @@ void Viewer::compile_shaders() " highp vec4 diffuse = abs(dot(N,L)) * light_diff * color; \n" " highp vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" - "gl_FragColor = light_amb*color + diffuse + specular ; \n" + "out_color = light_amb*color + diffuse + specular ; \n" "} \n" "\n" }; @@ -105,8 +106,8 @@ rendering_program.bind(); //Vertex source code const char vertex_source_points[] = { - "#version 120 \n" - "attribute highp vec4 vertex;\n" + "#version 150 \n" + "in highp vec4 vertex;\n" "uniform highp mat4 mvp_matrix;\n" "uniform highp float point_size;\n" @@ -119,11 +120,12 @@ const char vertex_source_points[] = //Vertex source code const char fragment_source_points[] = { - "#version 120 \n" + "#version 150 \n" "uniform highp vec4 color; \n" + "out highp vec4 out_color; \n" "void main(void) { \n" - "gl_FragColor = color; \n" + "out_color = color; \n" "} \n" "\n" }; diff --git a/Circular_kernel_3/demo/Circular_kernel_3/Circular_kernel_3.cpp b/Circular_kernel_3/demo/Circular_kernel_3/Circular_kernel_3.cpp index 513722fec61..72c7a0a4c09 100644 --- a/Circular_kernel_3/demo/Circular_kernel_3/Circular_kernel_3.cpp +++ b/Circular_kernel_3/demo/Circular_kernel_3/Circular_kernel_3.cpp @@ -3,15 +3,25 @@ int main(int argc, char** argv) { + QSurfaceFormat fmt; +#ifdef Q_OS_MAC + fmt.setVersion(4, 1); +#else + fmt.setVersion(4, 3); +#endif + fmt.setRenderableType(QSurfaceFormat::OpenGL); + fmt.setProfile(QSurfaceFormat::CoreProfile); + fmt.setOption(QSurfaceFormat::DebugContext); + QSurfaceFormat::setDefaultFormat(fmt); // Read command lines arguments. + //for Windows +#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)) + QApplication::setAttribute(Qt::AA_UseDesktopOpenGL); +#endif QApplication application(argc,argv); // Instantiate the viewer. Viewer viewer; - //for Windows -#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)) - application.setAttribute(Qt::AA_UseDesktopOpenGL); -#endif viewer.setWindowTitle("Intersection points of randomly generated circles."); // Make the viewer window visible on screen. diff --git a/Circular_kernel_3/demo/Circular_kernel_3/Viewer.cpp b/Circular_kernel_3/demo/Circular_kernel_3/Viewer.cpp index c026e1cce0b..69901dbbd1c 100644 --- a/Circular_kernel_3/demo/Circular_kernel_3/Viewer.cpp +++ b/Circular_kernel_3/demo/Circular_kernel_3/Viewer.cpp @@ -32,16 +32,16 @@ void Viewer::compile_shaders() //Vertex source code const char vertex_source[] = { - "#version 120 \n" - "attribute highp vec4 vertex;\n" - "attribute highp vec3 normal;\n" - "attribute highp vec4 center;\n" + "#version 150 \n" + "in highp vec4 vertex;\n" + "in highp vec3 normal;\n" + "in highp vec4 center;\n" "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 mv_matrix; \n" - "varying highp vec4 fP; \n" - "varying highp vec3 fN; \n" + "out highp vec4 fP; \n" + "out highp vec3 fN; \n" "void main(void)\n" "{\n" " fP = mv_matrix * vertex; \n" @@ -52,15 +52,16 @@ void Viewer::compile_shaders() //Vertex source code const char fragment_source[] = { - "#version 120 \n" - "varying highp vec4 fP; \n" - "varying highp vec3 fN; \n" + "#version 150 \n" + "in highp vec4 fP; \n" + "in highp vec3 fN; \n" "uniform highp vec4 color; \n" "uniform highp vec4 light_pos; \n" "uniform highp vec4 light_diff; \n" "uniform highp vec4 light_spec; \n" "uniform highp vec4 light_amb; \n" "uniform float spec_power ; \n" + "out highp vec4 out_color; \n" "void main(void) { \n" @@ -75,7 +76,7 @@ void Viewer::compile_shaders() " highp vec4 diffuse = max(dot(N,L), 0.0) * light_diff * color; \n" " highp vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" - "gl_FragColor = light_amb*color + diffuse ; \n" + "out_color = light_amb*color + diffuse ; \n" "} \n" "\n" }; @@ -111,8 +112,8 @@ void Viewer::compile_shaders() //Vertex source code const char vertex_source_no_ext[] = { - "#version 120 \n" - "attribute highp vec4 vertex;\n" + "#version 150 \n" + "in highp vec4 vertex;\n" "uniform highp mat4 mvp_matrix;\n" "void main(void)\n" "{\n" @@ -123,10 +124,11 @@ void Viewer::compile_shaders() //Vertex source code const char fragment_source_no_ext[] = { - "#version 120 \n" + "#version 150 \n" "uniform highp vec4 color; \n" + "out highp vec4 out_color; \n" "void main(void) { \n" - "gl_FragColor = color; \n" + "out_color = color; \n" "} \n" "\n" }; diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Linear_cell_complex_3_demo.cpp b/Linear_cell_complex/demo/Linear_cell_complex/Linear_cell_complex_3_demo.cpp index 42713752435..1672adad3f8 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Linear_cell_complex_3_demo.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/Linear_cell_complex_3_demo.cpp @@ -23,15 +23,15 @@ int main(int argc, char** argv) // std::cout<<"Size of dart: "<= QT_VERSION_CHECK(5, 3, 0)) + QApplication::setAttribute(Qt::AA_UseDesktopOpenGL); +#endif QApplication application(argc,argv); application.setOrganizationDomain("cgal.org"); application.setOrganizationName("CNRS and LIRIS' Establishments"); application.setApplicationName("3D Linear Cell Complex"); - //for windows -#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)) - application.setAttribute(Qt::AA_UseDesktopOpenGL); -#endif // Import resources from libCGALQt5 // See https://doc.qt.io/qt-5/qdir.html#Q_INIT_RESOURCE diff --git a/Linear_cell_complex/examples/Linear_cell_complex/basic_viewer.h b/Linear_cell_complex/examples/Linear_cell_complex/basic_viewer.h index db5a49f847f..b6b89a1b416 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/basic_viewer.h +++ b/Linear_cell_complex/examples/Linear_cell_complex/basic_viewer.h @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include #include @@ -43,15 +43,15 @@ typedef Local_kernel::Vector_3 Local_vector; //Vertex source code const char vertex_source_mono[] = { - "#version 120 \n" - "attribute highp vec4 vertex;\n" - "attribute highp vec3 normal;\n" + "#version 150 \n" + "in highp vec4 vertex;\n" + "in highp vec3 normal;\n" "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 mv_matrix; \n" - "varying highp vec4 fP; \n" - "varying highp vec3 fN; \n" + "out highp vec4 fP; \n" + "out highp vec3 fN; \n" "void main(void)\n" "{\n" " fP = mv_matrix * vertex; \n" @@ -62,17 +62,17 @@ const char vertex_source_mono[] = const char vertex_source_color[] = { - "#version 120 \n" - "attribute highp vec4 vertex;\n" - "attribute highp vec3 normal;\n" - "attribute highp vec3 color;\n" + "#version 150 \n" + "in highp vec4 vertex;\n" + "in highp vec3 normal;\n" + "in highp vec3 color;\n" "uniform highp mat4 mvp_matrix;\n" "uniform highp mat4 mv_matrix; \n" - "varying highp vec4 fP; \n" - "varying highp vec3 fN; \n" - "varying highp vec4 fColor; \n" + "out highp vec4 fP; \n" + "out highp vec3 fN; \n" + "out highp vec4 fColor; \n" "void main(void)\n" "{\n" " fP = mv_matrix * vertex; \n" @@ -85,15 +85,16 @@ const char vertex_source_color[] = //Vertex source code const char fragment_source_mono[] = { - "#version 120 \n" - "varying highp vec4 fP; \n" - "varying highp vec3 fN; \n" + "#version 150 \n" + "in highp vec4 fP; \n" + "in highp vec3 fN; \n" "uniform highp vec4 color; \n" "uniform highp vec4 light_pos; \n" "uniform highp vec4 light_diff; \n" "uniform highp vec4 light_spec; \n" "uniform highp vec4 light_amb; \n" "uniform float spec_power ; \n" + "out highp vec4 out_color; \n" "void main(void) { \n" @@ -108,22 +109,23 @@ const char fragment_source_mono[] = " highp vec4 diffuse = max(dot(N,L), 0.0) * light_diff * color; \n" " highp vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" - "gl_FragColor = light_amb*color + diffuse ; \n" + "out_color = light_amb*color + diffuse ; \n" "} \n" "\n" }; const char fragment_source_color[] = { - "#version 120 \n" - "varying highp vec4 fP; \n" - "varying highp vec3 fN; \n" - "varying highp vec4 fColor; \n" + "#version 150 \n" + "in highp vec4 fP; \n" + "in highp vec3 fN; \n" + "in highp vec4 fColor; \n" "uniform highp vec4 light_pos; \n" "uniform highp vec4 light_diff; \n" "uniform highp vec4 light_spec; \n" "uniform highp vec4 light_amb; \n" "uniform float spec_power ; \n" + "out highp vec4 out_color; \n" "void main(void) { \n" @@ -138,7 +140,7 @@ const char fragment_source_color[] = " highp vec4 diffuse = max(dot(N,L), 0.0) * light_diff * fColor; \n" " highp vec4 specular = pow(max(dot(R,V), 0.0), spec_power) * light_spec; \n" - "gl_FragColor = light_amb*fColor + diffuse ; \n" + "out_color = light_amb*fColor + diffuse ; \n" "} \n" "\n" }; @@ -146,8 +148,8 @@ const char fragment_source_color[] = //Vertex source code const char vertex_source_p_l[] = { - "#version 120 \n" - "attribute highp vec4 vertex;\n" + "#version 150 \n" + "in highp vec4 vertex;\n" "uniform highp mat4 mvp_matrix;\n" "void main(void)\n" "{\n" @@ -157,10 +159,11 @@ const char vertex_source_p_l[] = //Vertex source code const char fragment_source_p_l[] = { - "#version 120 \n" + "#version 150 \n" "uniform highp vec4 color; \n" + "out highp vec4 out_color; \n" "void main(void) { \n" - "gl_FragColor = color; \n" + "out_color = color; \n" "} \n" "\n" }; @@ -194,7 +197,7 @@ typename K::Vector_3 compute_normal_of_face(const std::vectorsetupUi(w); diff --git a/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Periodic_Lloyd_3.cpp b/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Periodic_Lloyd_3.cpp index 75f1f8ee396..6e0435f4b4e 100644 --- a/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Periodic_Lloyd_3.cpp +++ b/Periodic_3_triangulation_3/demo/Periodic_Lloyd_3/Periodic_Lloyd_3.cpp @@ -4,15 +4,20 @@ int main(int argc, char** argv) { + QSurfaceFormat fmt; + fmt.setVersion(2, 1); + fmt.setRenderableType(QSurfaceFormat::OpenGL); + fmt.setProfile(QSurfaceFormat::CoreProfile); + fmt.setOption(QSurfaceFormat::DebugContext); + QSurfaceFormat::setDefaultFormat(fmt); + //for windows +#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)) + QApplication::setAttribute(Qt::AA_UseDesktopOpenGL); +#endif QApplication application(argc,argv); - application.setOrganizationDomain("inria.fr"); application.setOrganizationName("INRIA"); application.setApplicationName("3D Periodic Lloyd"); - //for windows -#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)) - application.setAttribute(Qt::AA_UseDesktopOpenGL); -#endif // Import resources from libCGAL (QT5). // See https://doc.qt.io/qt-5/qdir.html#Q_INIT_RESOURCE diff --git a/Principal_component_analysis/demo/Principal_component_analysis/PCA_demo.cpp b/Principal_component_analysis/demo/Principal_component_analysis/PCA_demo.cpp index f1b7a78b624..63581649155 100644 --- a/Principal_component_analysis/demo/Principal_component_analysis/PCA_demo.cpp +++ b/Principal_component_analysis/demo/Principal_component_analysis/PCA_demo.cpp @@ -21,6 +21,16 @@ int main(int argc, char **argv) { + QSurfaceFormat fmt; + fmt.setVersion(2, 1); + fmt.setRenderableType(QSurfaceFormat::OpenGL); + fmt.setProfile(QSurfaceFormat::CoreProfile); + fmt.setOption(QSurfaceFormat::DebugContext); + QSurfaceFormat::setDefaultFormat(fmt); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)) + QApplication::setAttribute(Qt::AA_UseDesktopOpenGL); +#endif + QApplication app(argc, argv); app.setOrganizationDomain("inria.fr"); app.setOrganizationName("INRIA"); diff --git a/Triangulation_3/demo/Triangulation_3/T3_demo.cpp b/Triangulation_3/demo/Triangulation_3/T3_demo.cpp index 7b70c57dd07..4d3be25b5ac 100644 --- a/Triangulation_3/demo/Triangulation_3/T3_demo.cpp +++ b/Triangulation_3/demo/Triangulation_3/T3_demo.cpp @@ -16,15 +16,21 @@ int main(int argc, char** argv) { + QSurfaceFormat fmt; + fmt.setVersion(2, 1); + fmt.setRenderableType(QSurfaceFormat::OpenGL); + fmt.setProfile(QSurfaceFormat::CoreProfile); + fmt.setOption(QSurfaceFormat::DebugContext); + QSurfaceFormat::setDefaultFormat(fmt); + //for windows + #if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)) + QApplication::setAttribute(Qt::AA_UseDesktopOpenGL); + #endif QApplication app(argc, argv); app.setOrganizationDomain("inria.fr"); app.setOrganizationName("INRIA"); app.setApplicationName("3D Triangulation Demo"); - //for windows -#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0)) - app.setAttribute(Qt::AA_UseDesktopOpenGL); -#endif MainWindow mw; mw.show();