From 30ab8d9e64596417634ee329b94e3c3a104430ef Mon Sep 17 00:00:00 2001 From: moreaki Date: Sat, 13 Jan 2024 04:56:14 +0100 Subject: [PATCH 1/2] Create .gitignore Add *.user to ignore .pro.user files generated by QT Creator --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e31cfb2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ + +*.user From 34707b7c92e535ff792b3f81ddf155a422ea5085 Mon Sep 17 00:00:00 2001 From: moreaki Date: Sat, 13 Jan 2024 04:57:15 +0100 Subject: [PATCH 2/2] Add macOS support Add macOS support, and support QT 6.x --- glmodelview.cpp | 31 +++++++++++++++++++------------ glmodelview.h | 4 ++-- main.cpp | 8 ++++---- model3d.cpp | 6 ++++++ stereograma.pro | 3 +-- stereomaker.cpp | 6 +++--- 6 files changed, 35 insertions(+), 23 deletions(-) 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 +#include +#else +#include #include +#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 +#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 = 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 -#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_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);