From 6aa451bd716686765ca9bec8b1713d92cc9f4681 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luis=20Pe=C3=B1aranda?= Date: Wed, 6 Mar 2013 17:35:29 -0300 Subject: [PATCH] more windows compatibility --- openglcanvas.cpp | 55 +++++++++++++++++++++++++++----------------- pano_interface_1.pro | 8 +++++-- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/openglcanvas.cpp b/openglcanvas.cpp index 7dceb9f..9f66797 100644 --- a/openglcanvas.cpp +++ b/openglcanvas.cpp @@ -6,21 +6,34 @@ #include #include // for fstat, getpwuid, getuid #include // for fstat -#ifndef _WIN32 -# include // for getpwuid (TODO: windows?) +#ifdef _WIN32 + #include // for getenv (TODO: use getenv_s) +#else + #include // for getpwuid #endif #include // for fopen, fclose, getc #include -#ifdef _WIN32 +#ifdef _MSC_VER #include #define GET_WORKDIR _getcwd #define OPEN_FILE _open #define LSEEK_FD _lseek + #define FOPEN_RO(_descriptor,_filename) \ + if(fopen_s(&(_descriptor),_filename,"r")){ \ + fprintf(stderr,"unable to open file '%s'\n",_filename); \ + exit(-1); \ + } #else // unistd was included above #define GET_WORKDIR getcwd #define OPEN_FILE open #define LSEEK_FD lseek + #define FOPEN_RO(_descriptor,_filename) \ + (_descriptor=fopen(_filename,"r")); \ + if((_descriptor)==NULL) \ + fprintf(stderr,"unable to open file '%s'\n",_filename); \ + exit(-1); \ + } #endif #define PROGNAME "pano_interface" @@ -195,22 +208,19 @@ void OpenGLCanvas::change_visualization(QString name){ // This function reads the contents of the ~/.panorc file and stores the // options in private variables. -// TODO: windows void OpenGLCanvas::read_config_file(){ #ifdef _WIN32 + char* envvar=(char*)malloc(12*sizeof(char)); + strcpy(envvar,"USERPROFILE\0"); char *filepath=(char*)malloc(512*sizeof(char)); - if(!GET_WORKDIR(filepath,512)){ - fprintf(stderr,"error reading config file\n"); - exit(-1); - } - strcat(filepath,"/panorc"); - // TODO + strcpy(filepath,getenv(envvar)); + free(envvar); + strcat(filepath,"\\.panorc"); #else struct passwd *pw=getpwuid(getuid()); char *filepath=pw->pw_dir; strcat(filepath,"/.panorc"); #endif - fprintf(stderr,"the user config file is %s\n",filepath); shader_dir=(char*)malloc(512*sizeof(char)); shader_dir[0]='\0'; input_image_file=(char*)malloc(512*sizeof(char)); @@ -218,9 +228,10 @@ void OpenGLCanvas::read_config_file(){ char *read_line=(char*)malloc(64*sizeof(char)); struct stat testbuf; if(stat(filepath,&testbuf)){ - fprintf(stderr,"~/.panorc does not exist\n"); + fprintf(stderr,"%s does not exist\n",filepath); }else{ - FILE *rcfile=fopen(filepath,"r"); + FILE *rcfile; + FOPEN_RO(rcfile,filepath); char c; char *line=(char*)malloc(512*sizeof(char)); while((c=getc(rcfile))!=EOF){ @@ -262,6 +273,9 @@ void OpenGLCanvas::read_config_file(){ } fclose(rcfile); } +#ifdef _WIN32 + free(filepath); +#endif emit fov_changed((int)fov); emit max_fov_changed((int)fov_max); } @@ -545,11 +559,8 @@ int OpenGLCanvas::getTextureSize(const char * const progname, const char * textu { struct pam inpam; 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; - } + FILE *in_file; + FOPEN_RO(in_file,texturePath) #ifdef PAM_STRUCT_SIZE pnm_readpaminit(in_file,&inpam,PAM_STRUCT_SIZE(tuple_type)); @@ -577,7 +588,8 @@ void OpenGLCanvas::readTextureBytes(const char * const progname, int row; pm_init(progname, 0); - FILE * in_file = fopen(texturePath, "r"); + FILE *in_file; + FOPEN_RO(in_file,texturePath); #ifdef PAM_STRUCT_SIZE pnm_readpaminit(in_file,&inpam,PAM_STRUCT_SIZE(tuple_type)); @@ -622,14 +634,15 @@ char * OpenGLCanvas::textFileRead(char *fn) { count = LSEEK_FD(f, 0, SEEK_END); // close(f); if (fn != NULL) { - fp = fopen(fn,"rt"); + //fp = fopen(fn,"rt"); + FOPEN_RO(fp,fn); if (fp != NULL) { if (count > 0) { content = (char *)malloc(sizeof(char) * (count+1)); count = fread(content,sizeof(char),count,fp); content[count] = '\0'; } - fclose(fp); + fclose(fp); // maybe this line must be outside the {} } } return content; diff --git a/pano_interface_1.pro b/pano_interface_1.pro index 3d7ff66..505b009 100644 --- a/pano_interface_1.pro +++ b/pano_interface_1.pro @@ -26,12 +26,16 @@ DEFINES += GLEW_STATIC DEFINES += _CRT_SECURE_NO_WARNINGS INCLUDEPATH += "C:/Program Files (x86)/glew-1.5.2/include" DEPENDPATH += "C:/Program Files (x86)/glew-1.5.2/include" +INCLUDEPATH += "C:/Program Files (x86)/freeglut/include" +DEPENDPATH += "C:/Program Files (x86)/freeglut/include" INCLUDEPATH += "C:/Program Files (x86)/GnuWin32/include" DEPENDPATH += "C:/Program Files (x86)/GnuWin32/include" +LIBS += "/nodefaultlib:LIBCMT" +LIBS += -L"C:/Program Files (x86)/freeglut/lib" LIBS += -L"C:/Program Files (x86)/GnuWin32/lib" -LIBS += -lglu32 -lopengl32 -lfreeglut -llibnetpbm10 +LIBS += -L"C:/Program Files (x86)/GnuWin32/bin" LIBS += -L"C:/Program Files (x86)/glew-1.5.2/lib" -LIBS += -lglew32s +LIBS += -lfreeglut -lglu32 -lopengl32 -llibnetpbm10 -lglew32s } TARGET = pano_interface_1 -- GitLab