glfont.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
00055
00056 void glfntInit(void) {}
00057 void glfntClose(void) {}
00058 void glfntWriteBitmap(float , float , char * ) {}
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 }
00161
00162 }
00163
00164 }
00165