00001 #include <cassert>
00002
00003 #include "TridOpenGLGlobal.h"
00004
00005 #include "TROOT.h"
00006 #include "TSystem.h"
00007
00008 #include "GL/gl.h"
00009 #include "glf.h"
00010 #include <dlfcn.h>
00011
00012 #include "MessageService/MsgService.h"
00013
00014
00015
00016 TridOpenGLGlobal* TridOpenGLGlobal::sInstance = NULL;
00017
00018
00019 CVSID("$Id: TridOpenGLGlobal.cxx,v 1.9 2006/12/03 02:08:16 gmieg Exp $");
00020
00021
00022 TridOpenGLGlobal& TridOpenGLGlobal::Instance( void )
00023 {
00024 if(sInstance==NULL) {
00025 sInstance = new TridOpenGLGlobal();
00026 }
00027 assert(sInstance);
00028 return (*sInstance);
00029 }
00030
00031
00032 TridOpenGLGlobal::TridOpenGLGlobal( void )
00033 {
00034 fGL_Started = false;
00035 fGLF_Started = false;
00036 fGLF_Font = "";
00037
00038
00039
00040 fGL_Started = true;
00041
00042 #ifdef __APPLE__
00043 fLibGLHandle = dlopen("libGL.dylib", RTLD_LAZY);
00044 if(!fLibGLHandle) {
00045 fGL_Started = false;
00046 cerr << "Error on load of libGL: " << dlerror() << endl;
00047 }
00048 fLibGLUHandle = dlopen("libGLU.dylib", RTLD_LAZY | RTLD_GLOBAL);
00049 if(!fLibGLUHandle) {
00050 fGL_Started = false;
00051 cerr << "Error on load of libGLU: " << dlerror() << endl;
00052 }
00053 #else
00054 fLibGLHandle = dlopen("libGL.so", RTLD_LAZY);
00055 if(!fLibGLHandle) {
00056 fGL_Started = false;
00057 cerr << "Error on load of libGL: " << dlerror() << endl;
00058 }
00059 fLibGLUHandle = dlopen("libGLU.so", RTLD_LAZY | RTLD_GLOBAL);
00060 if(!fLibGLUHandle) {
00061 fGL_Started = false;
00062 cerr << "Error on load of libGLU: " << dlerror() << endl;
00063 }
00064 #endif
00065
00066 if(fGL_Started == false) {
00067 cerr << "TriD could not load the GL libraries!" << endl;
00068 cerr << "Make sure your system has OpenGL (or Mesa) installed correctly!" << endl;
00069
00070 }
00071 }
00072
00073
00074
00075 TridOpenGLGlobal::~TridOpenGLGlobal( void )
00076 {
00077 if(fGLF_Started) glfUnloadFont();
00078 if(fLibGLHandle) dlclose(fLibGLHandle);
00079 if(fLibGLHandle) dlclose(fLibGLUHandle);
00080 }
00081
00082
00083
00084 int TridOpenGLGlobal::GlfLoadFont(const char* fontfile)
00085 {
00086
00087 string basename = fontfile;
00088 if(strlen(fontfile)==0) basename = "arial1.glf";
00089
00090
00091
00092
00093
00094 const char* private_context = gSystem->Getenv("SRT_PRIVATE_CONTEXT");
00095 const char* public_context = gSystem->Getenv("SRT_PUBLIC_CONTEXT");
00096 const char* trid_dir = gSystem->Getenv("TRID");
00097
00098 string path = "./";
00099 if(private_context) path += string(":") + string(private_context) + string("/TriD/fonts/");
00100 if(public_context) path += string(":") + string(public_context) + string("/TriD/fonts/");
00101 if(trid_dir) path += string(":") + string(trid_dir);
00102
00103 char* pathname = gSystem->Which(path.c_str(),basename.c_str());
00104 if(pathname==0) {
00105 MSG("TriD",Msg::kFatal) << "TridOpenGLGlobal: Cannot find requested font " << basename << endl;
00106 return 1;
00107 }
00108 MSG("TriD",Msg::kDebug) << "Found font path: " << pathname << endl;
00109
00110 if(fGLF_Started == false) {
00111 glfInit();
00112 fGLF_Started=true;
00113 } else {
00114 glfUnloadFont();
00115 }
00116 glfLoadFont(pathname);
00117 return 0;
00118 }