Skip to content

Commit 1400662

Browse files
authored
Merge pull request #7 from gnudles/mac_integration
Mac integration
2 parents 679f7a5 + 712b04b commit 1400662

7 files changed

+33
-22
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
*.user

glmodelview.cpp

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,60 @@
11
#include "glmodelview.h"
22
#include "stereomaker.h"
3-
#include "imageviewer.h"
3+
#if defined(__APPLE__)
4+
#define GL_SILENCE_DEPRECATION
5+
#include <OpenGL/gl.h>
6+
#include <OpenGL/glu.h>
7+
#else
8+
#include <GL/gl.h>
49
#include <GL/glu.h>
10+
#endif
511
#include <math.h>
612
#include <stdio.h>
7-
#include <QGLShader>
8-
#include <QGLShaderProgram>
13+
#include <QOpenGLShader>
14+
#include <QOpenGLShaderProgram>
915
#include <QMessageBox>
1016
#include <QProcess>
1117
#include <QCoreApplication>
18+
#include <QOpenGLContext>
1219
#include "modeldepthviewer.h"
1320
#include "trirender.h"
1421

1522
GlModelView::GlModelView(QWidget *parent) :
16-
QGLWidget(parent),m_zoom(500),m_contrast(100)
23+
QOpenGLWidget(parent),m_zoom(500),m_contrast(100)
1724
{
1825
m_antialias=true;
1926
m_noShaders=false;
2027
m_new_width=1024;
2128
m_new_height=768;
2229
BasicImageWidget::setBasicImageParent(parent);
30+
QSurfaceFormat glf = QSurfaceFormat::defaultFormat();
31+
glf.setSamples(4);
32+
setFormat(glf);
2333
}
2434

2535
void GlModelView::initializeGL()
2636
{
27-
if (!context()->isValid())
37+
if (!(context()) || !context()->isValid())
2838
{
2939
QMessageBox::warning(this,"No OpenGL Driver","Depth Map generation is still available");
3040
}
3141

32-
33-
if (QGLShader::hasOpenGLShaders(QGLShader::Vertex,context()) )
42+
if (QOpenGLShader::hasOpenGLShaders(QOpenGLShader::Vertex,context()) )
3443
{
3544
QString declarations= "//uniform mat4 gl_ModelViewMatrix; uniform mat4 gl_ProjectionMatrix; attribute vec4 gl_Vertex;\n";
3645
QString codev= "void main() {gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"\
3746
"float zmax=-1.0;"\
3847
"float zmin=1.0;"\
3948
"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); } ";
40-
QGLShader shaderv(QGLShader::Vertex);
49+
QOpenGLShader shaderv(QOpenGLShader::Vertex);
4150
bool compile_success=shaderv.compileSourceCode(declarations+codev);
4251
if (!compile_success)
4352
{
4453
compile_success=shaderv.compileSourceCode(codev);
4554
}
4655
if (compile_success)
4756
{
48-
QGLShaderProgram program(context());
57+
QOpenGLShaderProgram program(context());
4958
program.addShader(&shaderv);
5059
program.link();
5160
program.bind();

glmodelview.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#ifndef GLMODELVIEW_H
22
#define GLMODELVIEW_H
33

4-
#include <QGLWidget>
4+
#include <QOpenGLWidget>
55
#include <QImage>
66
#include <model3d.h>
77
#include "basicimagewidget.h"
88

9-
class GlModelView : public QGLWidget,public BasicImageWidget
9+
class GlModelView : public QOpenGLWidget,public BasicImageWidget
1010
{
1111
Q_OBJECT
1212
public:

main.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
#include <QApplication>
22
#include "mainwindow.h"
3-
#include <QGLFormat>
3+
#include <QSurfaceFormat>
44

55
#include "parse.h"
66
int main(int argc, char *argv[])
77
{
88
QApplication a(argc, argv);
9-
QGLFormat glf = QGLFormat::defaultFormat();
10-
glf.setSampleBuffers(true);
11-
glf.setSamples(4);
12-
QGLFormat::setDefaultFormat(glf);
139
a.setWindowIcon(QIcon(":/images/stereograma.svg"));
1410
QCoreApplication::setOrganizationName("Kapandaria");
1511
QCoreApplication::setApplicationName("Stereograma");

model3d.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#include "model3d.h"
2+
#if defined(__APPLE__)
3+
#define GL_SILENCE_DEPRECATION
4+
#include <OpenGL/gl.h>
5+
#include <qopenglext.h>
6+
#else
27
#include "qgl.h"
8+
#endif
39
#include <stdio.h>
410
#include <math.h>
511
#include <limits.h>

stereograma.pro

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
#
55
#-------------------------------------------------
66

7-
QT += core gui network opengl \
8-
widgets
7+
QT += core gui network opengl widgets
98

109
TARGET = stereograma
1110
TEMPLATE = app
@@ -57,7 +56,6 @@ HEADERS += mainwindow.h \
5756
RPly/rply.h \
5857
RPly/rplyfile.h \
5958
parse.h \
60-
exprtk/exprtk.h \
6159
FormulaGen.h
6260

6361
FORMS += mainwindow.ui \

stereomaker.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//algorithm was taken from http://www.techmind.org/stereo/stech.html
22
#include "stereomaker.h"
33
#include <QPainter>
4-
#include <QTime>
4+
#include <QElapsedTimer>
55

66

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

0 commit comments

Comments
 (0)