glfont.cpp

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                              SOFA :: Framework                              *
00020 *                                                                             *
00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024 *                                                                             *
00025 * Contact information: contact@sofa-framework.org                             *
00026 ******************************************************************************/
00027 #include <sofa/helper/system/gl.h>
00028 #if defined (__linux__)
00029 # include <X11/Xlib.h>
00030 # include <X11/Xutil.h>
00031 # include <GL/glx.h>
00032 #endif
00033 
00034 #include <string.h>
00035 
00036 
00037 #include <sofa/helper/gl/glfont.h>
00038 
00039 #ifdef SGI_CC
00040 extern "C" Display * glXGetCurrentDisplayEXT (void);
00041 #endif
00042 
00043 namespace sofa
00044 {
00045 
00046 namespace helper
00047 {
00048 
00049 namespace gl
00050 {
00051     
00052 #if __APPLE__
00053     
00054 // nothing yet
00055     
00056 void glfntInit(void) {}
00057 void glfntClose(void) {}
00058 void glfntWriteBitmap(float /*x*/, float /*y*/, char * /*s*/ ) {}
00059 
00060 #endif
00061     
00062 #ifdef WIN32
00063 
00064 static GLuint LettersDL=0;
00065 
00066 void glfntInit(void)
00067 {
00068   HDC hdc;
00069 
00070   if (LettersDL!=0) return;
00071   hdc=wglGetCurrentDC();
00072   SelectObject(hdc,GetStockObject(SYSTEM_FONT));
00073   LettersDL=glGenLists(128);
00074   wglUseFontBitmaps(hdc,32,127,LettersDL+32);
00075 }
00076 
00077 void glfntClose(void)
00078 {
00079   if (LettersDL==0) return;
00080   glDeleteLists(LettersDL,128);
00081   LettersDL=0;
00082 }
00083 
00084 void glfntWriteBitmap(float x,float y,char *s)
00085 {
00086     GLint CurBase;
00087     
00088     if (LettersDL==0) return;
00089     glRasterPos2f(x,y);
00090     
00091     glGetIntegerv(GL_LIST_BASE,&CurBase);
00092     glListBase(LettersDL);
00093     glCallLists(strlen(s),GL_UNSIGNED_BYTE,s);
00094     glListBase(CurBase);
00095 }
00096 #endif // WIN32
00097 
00098 #ifdef __linux__
00099 
00100 static GLuint LettersDL=0;
00101 
00102 static unsigned int last;
00103 
00104 void glfntInit(void)
00105 {
00106 
00107   Display *dpy;
00108   
00109   XFontStruct *fontInfo;
00110   Font id;
00111   unsigned int first;
00112 
00113   if (LettersDL!=0) return;
00114 #ifdef SGI_CC
00115   dpy=glXGetCurrentDisplayEXT();
00116 #else  
00117   dpy=glXGetCurrentDisplay();
00118 #endif  
00119    if (dpy==NULL) return;
00120   fontInfo = XLoadQueryFont(dpy,
00121         "-adobe-times-medium-r-normal--17-120-100-100-p-88-iso8859-1");    
00122   if (fontInfo == NULL) return;
00123 
00124   id = fontInfo->fid;
00125   first = fontInfo->min_char_or_byte2;
00126   last = fontInfo->max_char_or_byte2;
00127   if (first<32) first=32;
00128   if (last>127) last=127;
00129 
00130   LettersDL=glGenLists(last+1);
00131   if (LettersDL==0) return;
00132   glXUseXFont(id, first, last-first+1, LettersDL+first);
00133   
00134 }
00135 
00136 void glfntClose(void)
00137 {
00138   if (LettersDL==0) return;
00139   glDeleteLists(LettersDL,last+1);
00140   LettersDL=0;
00141 }
00142 
00143 void glfntWriteBitmap(float x,float y,char *s)
00144 {
00145     GLint CurBase;
00146     
00147     if (LettersDL==0) return;
00148     glRasterPos2f(x,y);
00149     
00150     glGetIntegerv(GL_LIST_BASE,&CurBase);
00151     glListBase(LettersDL);
00152     glCallLists(strlen(s),GL_UNSIGNED_BYTE,s);
00153     glListBase(CurBase);
00154 }
00155 
00156 #endif // __linux__
00157 
00158 
00159 
00160 } // namespace gl
00161 
00162 } // namespace helper
00163 
00164 } // namespace sofa
00165 

Generated on Sun Nov 23 02:29:29 2008 for Sofa by  doxygen 1.5.7.1