26 #include "DrawTextGL.hh"
27 #include <Gui/biasgl.h>
30 # if defined(BIAS_HAVE_GLEW) || defined(MIP_HAVE_GLEW)
31 # include <GL/glxew.h>
40 # include <X11/extensions/xf86vmode.h>
41 # include <X11/keysym.h>
42 # include <X11/Intrinsic.h>
47 #include <Base/Debug/Error.hh>
48 #include <Base/Debug/DebugSimple.hh>
56 #define CHARS_START 32
61 DrawTextGL::~DrawTextGL()
67 DrawTextGL::DrawTextGL()
81 const std::string theFontname,
89 BIASASSERT(handleDC!=NULL);
98 base = glGenLists(CHARS_N);
114 FF_DONTCARE|DEFAULT_PITCH,
118 oldfont = (HFONT)SelectObject(HDC(handleDC), font);
120 BIASERR(
"SelectObject failed. NULL");
124 wglUseFontBitmaps(HDC(handleDC), CHARS_START, CHARS_N,
base);
127 SelectObject(HDC(handleDC), oldfont);
137 Display* display=NULL;
140 display = XOpenDisplay(0);
141 if (display == NULL){
142 BIASERR(
"XOpenDisplay failed for GLX font initialization. aborting");
147 XFontStruct *fontX = NULL;
149 base = glGenLists(CHARS_N);
151 fontX = XLoadQueryFont(display
161 fontX = XLoadQueryFont( display
167 BIASERR(
"Problem loading font - fallback failed, too: "<<
fontname);;
174 glXUseXFont(fontX->fid, CHARS_START, CHARS_N,
base);
182 XCloseDisplay(display);
197 glDeleteLists(
base, CHARS_N);
203 const float & xpos,
const float & ypos)
const
206 if ((0>xpos)|(xpos>1) | (0>ypos)|(ypos>1) )
207 BIASERR(
"("<<xpos<<
","<<ypos<<
" is out of normalized 0..1 coordinate bounds. Is this intentional?");
211 glMatrixMode(GL_PROJECTION);
218 glMatrixMode(GL_MODELVIEW);
223 glTranslatef(0.0, 0.0, -0.5);
224 glRasterPos2f(xpos, ypos);
227 glMatrixMode(GL_MODELVIEW);
230 glMatrixMode(GL_PROJECTION);
235 #include <Base/Common/BIASpragmaStart.hh>
238 const int & xpos,
const int & ypos,
239 const int & winWidthFallback,
const int &winHeightFallback)
const
241 #ifdef BIAS_HAVE_GLEW
242 if (GL_ARB_window_pos) {
244 glWindowPos2f(xpos, ypos);
247 #endif // BIAS_HAVE_GLEW
250 glMatrixMode(GL_PROJECTION);
255 0.0,
float(winWidthFallback),
256 0.0,
float(winHeightFallback)
258 glMatrixMode(GL_MODELVIEW);
264 glMatrixMode(GL_MODELVIEW);
267 glMatrixMode(GL_PROJECTION);
271 #include <Base/Common/BIASpragmaEnd.hh>
276 const float & xpos,
const float & ypos,
const float & zpos)
const
278 glRasterPos3f(xpos, ypos, zpos);
285 const float & xpos,
const float & ypos,
const float & zpos)
const
287 glMatrixMode(GL_MODELVIEW);
291 Print3D(text, xpos, ypos, zpos);
293 glMatrixMode(GL_MODELVIEW);
302 cout<<
"You must call InitFont before using DrawTextGL::Print (JW), aborting."<<endl;
306 glMatrixMode(GL_MODELVIEW);
312 glPushAttrib(GL_LIST_BIT);
314 glListBase(
base - CHARS_START);
316 glCallLists( text.size(), GL_UNSIGNED_BYTE, text.c_str() );
unsigned int base
inde xof our first display list:
void Print3D(const std::string &text, const float &xpos, const float &ypos, const float &zpos) const
void Print3DAbsolute(const std::string &text, const float &xpos, const float &ypos, const float &zpos) const
draw text in 3d at absolute position, thus ModelView matrix is set to identity (using push and pop)...
bool initialized
true if we created the font as display lists
int InitFont(void *handleDC, const std::string theFontname=std::string(DrawTextGL_DEFAULT_FONTNAME), const int fontHeight=DrawTextGL_DEFAULT_FONTSIZE)
set the font up
void Print(const std::string &text) const
print text on OpenGL screen using current RasterPosition , settings etc.
void DeleteFont()
frees the display lists JW
void PrintNormCoords(const std::string &text, const float &xpos, const float &ypos) const
print text on OpenGL screen in 0..1 normalized coordinates with origin at lower left corner with 0...
std::string fontname
the name of our font, e.g. "Arial" or "-*-helvetica-bold-r-normal--24-*-*-*-p-*-iso8859-1");" ...
void PrintWinCoords(const std::string &text, const int &xpos, const int &ypos, const int &winWidthFallback=640, const int &winHeightFallback=480) const
print text on OpenGL screen at 2D pos (xpos,ypos) in windows (pixel) coordiantes. ...