Commit 67bcbe56 authored by Luis Peñaranda's avatar Luis Peñaranda

make it compile also on linux

parent 57233cc4
......@@ -4,15 +4,20 @@
#endif
#include "openglcanvas.h"
#include <cmath>
#ifdef WINDOWS
#include <direct.h>
#define GET_WORKDIR _getcwd
#else
#include <unistd.h>
#define GET_WORKDIR getcwd
#endif
#include <sys/types.h> // for fstat
#include <sys/stat.h> // for fstat
#define PROGNAME "pano_interface"
#define ROOT_DIR /Users/lvelho/Desktop/Work/omni/pano_interface_1
#define INPUT_IMAGE_FILE "/Users/lvelho/Desktop/pano_interface_1/input_images/image_4_input.pnm"
#define VERT_SHADER_FILE "/Users/lvelho/Desktop/pano_interface_1/shaders/test_vertex_shader.vert"
#define FRAG_SHADER_FILE "/Users/lvelho/Desktop/pano_interface_1/shaders/fragment_shader.frag"
#define INPUT_IMAGE_FILE "input_images/image_4_input.pnm"
#define VERT_SHADER_FILE "shaders/test_vertex_shader.vert"
#define FRAG_SHADER_FILE "shaders/fragment_shader.frag"
OpenGLCanvas::OpenGLCanvas(QWidget *parent) :
QGLWidget(parent)
......@@ -103,6 +108,13 @@ void OpenGLCanvas::change_visualization(QString name){
}
void OpenGLCanvas::change_input_image(){
QString path = QFileDialog::getExistingDirectory(this,tr("Choose directory"),directory.path());
if(path.isNull()==false)
directory.setPath(path);
updateGL();
}
void OpenGLCanvas::initializeGL(){
glShadeModel(GL_SMOOTH);
glClearColor(1.0f,1.0f,1.0f,0.0f);
......@@ -111,13 +123,28 @@ void OpenGLCanvas::initializeGL(){
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
//in Mac
char *input_image=(char*)malloc(512*sizeof(char*));
GET_WORKDIR(input_image,512);
strcat(input_image,"/\0");
strcat(input_image,INPUT_IMAGE_FILE);
#ifdef __APPLE__
const char * const progname = "PROJ_ROOT_DIR";
const char * input_image = INPUT_IMAGE_FILE;
//const char * input_image = INPUT_IMAGE_FILE;
#else
// progname is a file name or a path???
const char * const progname = (char*)(PROGNAME);
//const char * input_image = (char*)(INPUT_IMAGE_FILE);
#endif
// // in Linux
// const char * const progname = "/home/leo-ks/Research_PHD/Panoramic_Videos-2012-June-to-August/src/Qt-Creator/pano_interface_1-build-desktop-Qt_in_PATH_Release/pano_interface_1";
// const char * input_image = "/home/leo-ks/Research_PHD/Panoramic_Videos-2012-June-to-August/src/Qt-Creator/pano_interface_1/input_images/image_8_input.pnm";
fprintf(stderr,"progname=%s\n",progname);
fprintf(stderr,"image=%s\n",input_image);
// exit if the input file does not exist
struct stat testbuf;
if(stat(input_image,&testbuf)){
fprintf(stderr,"the file does not exist!\n");
free(input_image);
exit(-1);
}
int textureSize = getTextureSize(progname,input_image);
unsigned char * textureBytes = (unsigned char*)malloc(textureSize);
......@@ -164,6 +191,7 @@ void OpenGLCanvas::initializeGL(){
numberOfIndices = meshNumIndices;
triangleIndices = indices;
free(input_image);
setShaders();
}
......@@ -364,20 +392,24 @@ void OpenGLCanvas::define_triangle_indices(unsigned int * indices, int m, int n)
int OpenGLCanvas::getTextureSize(const char * const progname, const char * texturePath)
{
struct pam inpam;
pm_init(progname, 0);
FILE * in_file = fopen(texturePath,"r");
if (in_file==NULL){
printf("\n ERROR in getTextureSize: unable to open specified file \n");
return -1;
}
pm_init(progname, 0);
FILE * in_file = fopen(texturePath,"r");
if (in_file==NULL){
fprintf(stderr,"ERROR in getTextureSize: unable to open specified file\n");
return -1;
}
pnm_readpaminit(in_file, &inpam,PAM_STRUCT_SIZE(tuple_type)); // IN MAC
// pnm_readpaminit(in_file, &inpam,sizeof(inpam)); //in linux
#ifdef PAM_STRUCT_SIZE
pnm_readpaminit(in_file,&inpam,PAM_STRUCT_SIZE(tuple_type));
#else
pnm_readpaminit(in_file,&inpam,sizeof(struct pam));
#endif
int size = inpam.width*inpam.height*inpam.depth*inpam.bytes_per_sample;
pm_close(in_file);
int size = inpam.width*inpam.height*inpam.depth*inpam.bytes_per_sample;
pm_close(in_file);
return size;
//fprintf(stderr,"size=%d\n",size);
return size;
}
void OpenGLCanvas::readTextureBytes(const char * const progname,
......@@ -393,8 +425,11 @@ void OpenGLCanvas::readTextureBytes(const char * const progname,
pm_init(progname, 0);
FILE * in_file = fopen(texturePath, "r");
pnm_readpaminit(in_file, &inpam,PAM_STRUCT_SIZE(tuple_type)); // IN MAC
// pnm_readpaminit(in_file, &inpam,sizeof(inpam)); //in linux
#ifdef PAM_STRUCT_SIZE
pnm_readpaminit(in_file,&inpam,PAM_STRUCT_SIZE(tuple_type));
#else
pnm_readpaminit(in_file,&inpam,sizeof(struct pam));
#endif
tuplerow = pnm_allocpamrow(&inpam);
......@@ -448,16 +483,46 @@ void OpenGLCanvas::setShaders() {
char *vs,*fs;
#ifdef GLEW_VERSION_1_5
GLenum err=glewInit();
if(err!=GLEW_OK){
fprintf(stderr,"error in GLEW initialization: %s\n",glewGetString(err));
exit(-1);
}
#endif
GLuint v = glCreateShader(GL_VERTEX_SHADER);
GLuint f = glCreateShader(GL_FRAGMENT_SHADER);
// in Mac
vs = textFileRead(VERT_SHADER_FILE);
fs = textFileRead(FRAG_SHADER_FILE);
char *vs_file=(char*)malloc(512*sizeof(char*));
GET_WORKDIR(vs_file,512);
strcat(vs_file,"/\0");
strcat(vs_file,VERT_SHADER_FILE);
fprintf(stderr,"vs_file=%s\n",vs_file);
char *fs_file=(char*)malloc(512*sizeof(char*));
GET_WORKDIR(fs_file,512);
strcat(fs_file,"/\0");
strcat(fs_file,FRAG_SHADER_FILE);
fprintf(stderr,"fs_file=%s\n",fs_file);
struct stat vs_testbuf,fs_testbuf;
if(stat(vs_file,&vs_testbuf)||stat(fs_file,&fs_testbuf)){
fprintf(stderr,"a shader file does not exist!\n");
free(vs_file);
free(fs_file);
exit(-1);
}
// // in Linux
// vs = textFileRead("/home/leo-ks/Research_PHD/Panoramic_Videos-2012-June-to-August/src/Qt-Creator/pano_interface_1/shaders/test_vertex_shader.vert");
// fs = textFileRead("/home/leo-ks/Research_PHD/Panoramic_Videos-2012-June-to-August/src/Qt-Creator/pano_interface_1/shaders/fragment_shader.frag");
//#ifdef __APPLE__
// in Mac
//vs = textFileRead(VERT_SHADER_FILE);
//fs = textFileRead(FRAG_SHADER_FILE);
//#else
// in Linux (I think this would also work in mac, I just need to try)
vs=textFileRead(vs_file);
fs=textFileRead(fs_file);
//#endif
const char * vv = vs;
const char * ff = fs;
......@@ -466,6 +531,7 @@ void OpenGLCanvas::setShaders() {
glShaderSource(f, 1, &ff,NULL);
free(vs);free(fs);
free(vs_file);free(fs_file);
glCompileShader(v);
glCompileShader(f);
......
#ifndef OPENGLCANVAS_H
#define OPENGLCANVAS_H
#ifndef GL_VERSION_3_1
#include <GL/glew.h>
#if (!defined GLEW_VERSION_1_5) || (!defined GL_VERSION_3_1)
#error OpenGL 3.1 or GLEW 1.5.2 is required
#endif
#endif
#include <QGLWidget>
#include <fcntl.h>
#include <unistd.h>
......@@ -14,10 +21,20 @@ extern "C" {
}
#define GL_GLEXT_PROTOTYPES 1
#include<OpenGL/gl.h>
#include<OpenGL/glu.h>
#include<Glut/glut.h>
#include<OpenGL/glext.h>
#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
#include <QDir>
#include <QFileDialog>
class OpenGLCanvas : public QGLWidget
{
......@@ -37,7 +54,7 @@ protected:
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);
void setShaders(void);
void setShaders();
signals:
void fps(QString newFPS);
......@@ -49,6 +66,7 @@ public slots:
void change_center_phi(double phi);
void change_fov_scale_relation(QString name);
void change_visualization(QString name);
void change_input_image();
void slotTimer();
private:
......@@ -58,6 +76,7 @@ private:
double center_phi;
QString fov_scale_relation;
QString visualization;
QDir directory;
Chronos time_time;
QTimer time_timer;
......
......@@ -6,31 +6,24 @@
QT += core gui opengl
#mac-os {
mac {
LIBS += -L/opt/local/lib
LIBS += -lpng -lpnm
LIBS += -framework Carbon -framework OpenGL -framework GLUT
INCLUDEPATH += /opt/local/include/netpbm/ \
/opt/local/include/
#}
#linux-g++-64 {
} else:unix {
#LIBS += -lm -lpng -lpetsc -lglut -lGL -lnetpbm
LIBS += -lm -lglut -lGL -lGLEW -lnetpbm
# GLee is required when the version of opengl is old
#SOURCES += GLee.c
#HEADERS += GLee.h
#DEFINES += NEEDGLEE
#}
}
TARGET = pano_interface_1
TEMPLATE = app
SOURCES += main.cpp\
panowindow1.cpp \
openglcanvas.cpp \
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment