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

Make it work on macOS and update to QT 6.x #6

Open
wants to merge 2 commits into
base: mac_integration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

*.user
31 changes: 19 additions & 12 deletions glmodelview.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
#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>
#include "modeldepthviewer.h"
#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;
Expand All @@ -24,31 +30,32 @@ 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)
{
compile_success=shaderv.compileSourceCode(codev);
}
if (compile_success)
{
QGLShaderProgram program(context());
program.addShader(&shaderv);
program.link();
program.bind();
QOpenGLShaderProgram *program;
program = new QOpenGLShaderProgram(this);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this memory allocation getting released?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question ;). I'm a bit swamped with work, but I'll try to update the PR.

program->addShader(&shaderv);
program->link();
program->bind();
}
else
m_noShaders=true;
Expand Down
4 changes: 2 additions & 2 deletions glmodelview.h
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
8 changes: 4 additions & 4 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
6 changes: 6 additions & 0 deletions model3d.cpp
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
3 changes: 1 addition & 2 deletions stereograma.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
#
#-------------------------------------------------

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

TARGET = stereograma
TEMPLATE = app
Expand Down
6 changes: 3 additions & 3 deletions stereomaker.cpp
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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--)
Expand Down Expand Up @@ -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);
Expand Down