openglcanvas.h 2.44 KB
Newer Older
Luis Peñaranda's avatar
Luis Peñaranda committed
1
2
3
#ifndef OPENGLCANVAS_H
#define OPENGLCANVAS_H

Luis Penaranda's avatar
Luis Penaranda committed
4
5
6
7
// GLew might not be needed if a recent version of OpenGL is present
#include <GL/glew.h>
#if (!defined GLEW_VERSION_1_5) || (!defined GL_VERSION_3_1)
    #error GLEW 1.5.2 is required
8
9
#endif

Luis Peñaranda's avatar
Luis Peñaranda committed
10
#define GL_GLEXT_PROTOTYPES 1
11
12
13
14
15
16
17
18
19
20
21
22
#ifdef __APPLE__
  #include<OpenGL/gl.h>
  #include<OpenGL/glu.h>
  #include<Glut/glut.h>
  #include<OpenGL/glext.h>
#else
  #include <GL/gl.h>
  #include <GL/glu.h>
  #include <GL/glut.h>
  #include <GL/glext.h>
#endif

Luis Penaranda's avatar
Luis Penaranda committed
23
24
#include <QGLWidget>
#include <QTimer>
25
#include <QFile>
26
#include <QFileDialog>
Luis Penaranda's avatar
Luis Penaranda committed
27
28
29
30
31
32
33
34
35
#include <fcntl.h>
#include <unistd.h>
#include "chronos.h"

extern "C" {
#include <ppm.h>
#include <pm.h>
#include <pam.h>
}
Luis Peñaranda's avatar
Luis Peñaranda committed
36
37
38
39
40
41
42
43

class OpenGLCanvas : public QGLWidget
{
    Q_OBJECT
public:
    explicit OpenGLCanvas(QWidget *parent = 0);

protected:
44
    void load_image(const char *new_image);
Luis Peñaranda's avatar
Luis Peñaranda committed
45
46
47
48
49
50
51
52
53
54
55
    void initializeGL();
    void resizeGL(int w, int h);
    void paintGL();
    void define_texture_coordinates(float *texCoord, int m, int n, float min_phi, float max_phi, float min_lambda, float max_lambda);
    void vertex_transformation(float *positions, int m, int n, float center_lambda, float center_phi, float fov_rads, float scale);
    void load_sphere_mesh(float *positions, int m, int n);
    float calculate_extent(float fov_rads);
    void define_triangle_indices(unsigned int * indices, int m, int n);
    int getTextureSize(const char * const progname, const char * texturePath);
    void readTextureBytes(const char * const progname, const char * texturePath,unsigned char * textureBytes,int * outImageWidth, int * outImageHeight);
    char *textFileRead(char *fn);
56
    void setShaders();
Luis Peñaranda's avatar
Luis Peñaranda committed
57
58
59
60
61
62
63
64
65
66
67

signals:
    void fps(QString newFPS);

public slots:
    void change_fov(double f);
//    void change_scale(double s);
    void change_center_lambda(double lambda);
    void change_center_phi(double phi);
    void change_fov_scale_relation(QString name);
    void change_visualization(QString name);
68
    void change_input_image();
Luis Peñaranda's avatar
Luis Peñaranda committed
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
    void slotTimer();

private:
    double fov;
    double scale;
    double center_lambda;
    double center_phi;
    QString fov_scale_relation;
    QString visualization;

    Chronos time_time;
    QTimer time_timer;
    int time_frames;
    double time_start;
    double time_fps;

    unsigned int numberOfIndices;
    unsigned int * triangleIndices;
    float * verticesPositions;
    float * textureCoordinates;
    float windowWidth;
    float windowHeight;

};

#endif // OPENGLCANVAS_H