gnudles / stereograma

Cross-Platform, Open Source Fast Stereogram Creator
GNU General Public License v3.0
48 stars 8 forks source link

Support macOS and upgrade to the newest QT 6.x library #5

Open moreaki opened 8 months ago

moreaki commented 8 months ago

I wanted to test your software on a macOS computer, but it didn't compile. So I did a quick-and-dirty 'eliminate all errors' until the source code compiled. Here is the resulting diff:

diff --git a/glmodelview.cpp b/glmodelview.cpp
index 74bcb5c..3f0d506 100644
--- a/glmodelview.cpp
+++ b/glmodelview.cpp
@@ -1,11 +1,17 @@
 #include "glmodelview.h"
 #include "stereomaker.h"
-#include "imageviewer.h"
+#if defined(__APPLE__)
+#define GL_SILENCE_DEPRECATION
+#include <OpenGL/gl.h>
+#include <OpenGL/glu.h>
+#else
+#include <GL/gl.h>
 #include <GL/glu.h>
+#endif
 #include <math.h>
 #include <stdio.h>
-#include <QGLShader>
-#include <QGLShaderProgram>
+#include <QOpenGLShader>>
+#include <QOpenGLShaderProgram>>
 #include <QMessageBox>
 #include <QProcess>
 #include <QCoreApplication>
@@ -13,7 +19,7 @@
 #include "trirender.h"

 GlModelView::GlModelView(QWidget *parent) :
-    QGLWidget(parent),m_zoom(500),m_contrast(100)
+    QOpenGLWidget(parent),m_zoom(500),m_contrast(100)
 {
     m_antialias=true;
     m_noShaders=false;
@@ -24,20 +30,20 @@ GlModelView::GlModelView(QWidget *parent) :

 void GlModelView::initializeGL()
 {
+    /* TODO
     if (!context()->isValid())
     {
         QMessageBox::warning(this,"No OpenGL Driver","Depth Map generation is still available");
-    }
-
+    }*/

-    if (QGLShader::hasOpenGLShaders(QGLShader::Vertex,context()) )
+    if (QOpenGLShader::hasOpenGLShaders(QOpenGLShader::Vertex,context()) )
     {
         QString declarations= "//uniform mat4 gl_ModelViewMatrix;  uniform mat4 gl_ProjectionMatrix; attribute vec4 gl_Vertex;\n";
         QString codev=       "void main()  {gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"\
                 "float zmax=-1.0;"\
                 "float zmin=1.0;"\
                 "float scale=(zmax-zmin);float offs=-zmin;float z=(gl_Position.z/gl_Position.w); gl_FrontColor = vec4((z+offs)/scale,(z+offs)/scale,(z+offs)/scale,1.0); } ";
-        QGLShader shaderv(QGLShader::Vertex);
+        QOpenGLShader shaderv(QOpenGLShader::Vertex);
         bool compile_success=shaderv.compileSourceCode(declarations+codev);
         if (!compile_success)
         {
@@ -45,10 +51,11 @@ void GlModelView::initializeGL()
         }
         if (compile_success)
         {
-            QGLShaderProgram program(context());
-            program.addShader(&shaderv);
-            program.link();
-            program.bind();
+            QOpenGLShaderProgram *program;
+            program = new QOpenGLShaderProgram(this);
+            program->addShader(&shaderv);
+            program->link();
+            program->bind();
         }
         else
             m_noShaders=true;
diff --git a/glmodelview.h b/glmodelview.h
index 52c8e75..a3e08e5 100644
--- a/glmodelview.h
+++ b/glmodelview.h
@@ -1,12 +1,12 @@
 #ifndef GLMODELVIEW_H
 #define GLMODELVIEW_H

-#include <QGLWidget>
+#include <QOpenGLWidget>
 #include <QImage>
 #include <model3d.h>
 #include "basicimagewidget.h"

-class GlModelView : public QGLWidget,public BasicImageWidget
+class GlModelView : public QOpenGLWidget,public BasicImageWidget
 {
     Q_OBJECT
 public:
diff --git a/main.cpp b/main.cpp
index 0b8d633..d97f398 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,15 +1,15 @@
 #include <QApplication>
 #include "mainwindow.h"
-#include <QGLFormat>
+#include <QSurfaceFormat>

 #include "parse.h"
 int main(int argc, char *argv[])
 {
     QApplication a(argc, argv);
-    QGLFormat glf = QGLFormat::defaultFormat();
-    glf.setSampleBuffers(true);
+    QSurfaceFormat glf = QSurfaceFormat::defaultFormat();
+    //TODO: glf.setSampleBuffers(true);
     glf.setSamples(4);
-    QGLFormat::setDefaultFormat(glf);
+    QSurfaceFormat::setDefaultFormat(glf);
     a.setWindowIcon(QIcon(":/images/stereograma.svg"));
     QCoreApplication::setOrganizationName("Kapandaria");
     QCoreApplication::setApplicationName("Stereograma");
diff --git a/model3d.cpp b/model3d.cpp
index 84b1796..be7b16f 100644
--- a/model3d.cpp
+++ b/model3d.cpp
@@ -1,5 +1,11 @@
 #include "model3d.h"
+#if defined(__APPLE__)
+#define GL_SILENCE_DEPRECATION
+#include <OpenGL/gl.h>
+#include <qopenglext.h>
+#else
 #include "qgl.h"
+#endif
 #include <stdio.h>
 #include <math.h>
 #include <limits.h>
diff --git a/stereograma.pro b/stereograma.pro
index d7448c6..d3c3d3b 100644
--- a/stereograma.pro
+++ b/stereograma.pro
@@ -4,8 +4,7 @@
 #
 #-------------------------------------------------

-QT       += core gui network opengl \
-    widgets
+QT       += core gui network openglwidgets widgets

 TARGET = stereograma
 TEMPLATE = app
diff --git a/stereomaker.cpp b/stereomaker.cpp
index 5581997..9fa1322 100644
--- a/stereomaker.cpp
+++ b/stereomaker.cpp
@@ -1,7 +1,7 @@
 //algorithm was taken from http://www.techmind.org/stereo/stech.html
 #include "stereomaker.h"
 #include <QPainter>
-#include <QTime>
+#include <QElapsedTimer>

 QVector<QRgb> StereoMaker::grayscale;
@@ -149,7 +149,7 @@ QImage StereoMaker::render(const QImage & map, const QImage & ptrn, Preset *pset
     int progbarval=0;
     int maxheight=dpi*(psettings->getMaximumDepth()-psettings->getMinimumDepth());
     //benchmark
-    QTime t_time;
+    QElapsedTimer t_time;
     t_time.start();
     unsigned int **patternptr=(unsigned int **)malloc(pattern_height*sizeof(void*));
     for (int i=pattern_height-1;i>=0;i--)
@@ -263,7 +263,7 @@ QImage StereoMaker::render(const QImage & map, const QImage & ptrn, Preset *pset
             qpbar->setValue(progbarval);
         }
     }
-    qDebug("Time elapsed: %d ms", t_time.elapsed());
+    qDebug("Time elapsed: %lld ms", t_time.elapsed());
     free(lookL);
     free(lookR);
     free(mapptr);

If you feel like this is something you'd like to add, let me know and I open a proper MR. The application starts up, and I can load some stuff (albeit, I have no idea what I need to do):

image
gnudles commented 8 months ago

Thank you for your efforts, I really appreciate your work. I never had the chance to check my software on mac, because I do not own one. I also need to port this software to Qt 6. I am a bit busy now, I hope I will have a chance to look at it in the following month

בתאריך שבת, 13 בינו׳ 2024, 1:29, מאת moreaki @.***>:

I wanted to test your software on a macOS computer, but it didn't compile. So I did a quick-and-dirty 'eliminate all errors' until the source code compiled. Here is the resulting diff:

diff --git a/glmodelview.cpp b/glmodelview.cpp index 74bcb5c..3f0d506 100644--- a/glmodelview.cpp+++ b/glmodelview.cpp@@ -1,11 +1,17 @@

include "glmodelview.h"

include "stereomaker.h"-#include "imageviewer.h"+#if defined(APPLE)+#define GL_SILENCE_DEPRECATION+#include <OpenGL/gl.h>+#include <OpenGL/glu.h>+#else+#include <GL/gl.h>

include <GL/glu.h>+#endif

include

include -#include -#include +#include >+#include >

include

include

include @@ -13,7 +19,7 @@

include "trirender.h"

GlModelView::GlModelView(QWidget parent) :- QGLWidget(parent),m_zoom(500),m_contrast(100)+ QOpenGLWidget(parent),m_zoom(500),m_contrast(100) { m_antialias=true; m_noShaders=false;@@ -24,20 +30,20 @@ GlModelView::GlModelView(QWidget parent) :

void GlModelView::initializeGL() {+ / TODO if (!context()->isValid()) { QMessageBox::warning(this,"No OpenGL Driver","Depth Map generation is still available");- }-+ }/

  • if (QGLShader::hasOpenGLShaders(QGLShader::Vertex,context()) )+ if (QOpenGLShader::hasOpenGLShaders(QOpenGLShader::Vertex,context()) ) { QString declarations= "//uniform mat4 gl_ModelViewMatrix; uniform mat4 gl_ProjectionMatrix; attribute vec4 gl_Vertex;\n"; QString codev= "void main() {gl_Position = gl_ModelViewProjectionMatrix gl_Vertex;"\ "float zmax=-1.0;"\ "float zmin=1.0;"\ "float scale=(zmax-zmin);float offs=-zmin;float z=(gl_Position.z/gl_Position.w); gl_FrontColor = vec4((z+offs)/scale,(z+offs)/scale,(z+offs)/scale,1.0); } ";- QGLShader shaderv(QGLShader::Vertex);+ QOpenGLShader shaderv(QOpenGLShader::Vertex); bool compile_success=shaderv.compileSourceCode(declarations+codev); if (!compile_success) {@@ -45,10 +51,11 @@ void GlModelView::initializeGL() } if (compile_success) {- QGLShaderProgram program(context());- program.addShader(&shaderv);- program.link();- program.bind();+ QOpenGLShaderProgram program;+ program = new QOpenGLShaderProgram(this);+ program->addShader(&shaderv);+ program->link();+ program->bind(); } else m_noShaders=true;diff --git a/glmodelview.h b/glmodelview.h index 52c8e75..a3e08e5 100644--- a/glmodelview.h+++ b/glmodelview.h@@ -1,12 +1,12 @@

    ifndef GLMODELVIEW_H

    define GLMODELVIEW_H

    -#include +#include

    include

    include

    include "basicimagewidget.h"

    -class GlModelView : public QGLWidget,public BasicImageWidget+class GlModelView : public QOpenGLWidget,public BasicImageWidget { Q_OBJECT public:diff --git a/main.cpp b/main.cpp index 0b8d633..d97f398 100644--- a/main.cpp+++ b/main.cpp@@ -1,15 +1,15 @@

    include

    include "mainwindow.h"-#include +#include

    include "parse.h"

    int main(int argc, char *argv[]) { QApplication a(argc, argv);- QGLFormat glf = QGLFormat::defaultFormat();- glf.setSampleBuffers(true);+ QSurfaceFormat glf = QSurfaceFormat::defaultFormat();+ //TODO: glf.setSampleBuffers(true); glf.setSamples(4);- QGLFormat::setDefaultFormat(glf);+ QSurfaceFormat::setDefaultFormat(glf); a.setWindowIcon(QIcon(":/images/stereograma.svg")); QCoreApplication::setOrganizationName("Kapandaria"); QCoreApplication::setApplicationName("Stereograma");diff --git a/model3d.cpp b/model3d.cpp index 84b1796..be7b16f 100644--- a/model3d.cpp+++ b/model3d.cpp@@ -1,5 +1,11 @@

    include "model3d.h"+#if defined(APPLE)+#define GL_SILENCE_DEPRECATION+#include <OpenGL/gl.h>+#include +#else

    include "qgl.h"+#endif

    include

    include

    include diff --git a/stereograma.pro b/stereograma.pro

    index d7448c6..d3c3d3b 100644--- a/stereograma.pro+++ b/stereograma.pro@@ -4,8 +4,7 @@ #

    -------------------------------------------------

    -QT += core gui network opengl - widgets+QT += core gui network openglwidgets widgets

    TARGET = stereograma TEMPLATE = appdiff --git a/stereomaker.cpp b/stereomaker.cpp index 5581997..9fa1322 100644--- a/stereomaker.cpp+++ b/stereomaker.cpp@@ -1,7 +1,7 @@ //algorithm was taken from http://www.techmind.org/stereo/stech.html

    include "stereomaker.h"

    include -#include +#include

    QVector StereoMaker::grayscale;@@ -149,7 +149,7 @@ QImage StereoMaker::render(const QImage & map, const QImage & ptrn, Preset pset int progbarval=0; int maxheight=dpi(psettings->getMaximumDepth()-psettings->getMinimumDepth()); //benchmark- QTime t_time;+ QElapsedTimer t_time; t_time.start(); unsigned int patternptr=(unsigned int )malloc(pattern_heightsizeof(void)); for (int i=pattern_height-1;i>=0;i--)@@ -263,7 +263,7 @@ QImage StereoMaker::render(const QImage & map, const QImage & ptrn, Preset *pset qpbar->setValue(progbarval); } }- qDebug("Time elapsed: %d ms", t_time.elapsed());+ qDebug("Time elapsed: %lld ms", t_time.elapsed()); free(lookL); free(lookR); free(mapptr);

If you feel like this is something you'd like to add, let me know and I open a proper MR. The application starts up, and I can load some stuff (albeit, I have no idea what I need to do): image.png (view on web) https://github.com/gnudles/stereograma/assets/1086603/71a1fa08-d48b-465a-a281-5479ed47eb02

— Reply to this email directly, view it on GitHub https://github.com/gnudles/stereograma/issues/5, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADAPYJWXLNK3BZWJN73TLE3YOHBN3AVCNFSM6AAAAABBY233UGVHI2DSMVQWIX3LMV43ASLTON2WKOZSGA3TSOBXHEZTINQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>