Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
moreaki opened this issue Jan 12, 2024 · 1 comment
Open

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

moreaki opened this issue Jan 12, 2024 · 1 comment

Comments

@moreaki
Copy link
Contributor

moreaki commented Jan 12, 2024

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
Copy link
Owner

gnudles commented Jan 13, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants