Fl_OpenGL_Graphics_Driver : use gl_font()/gl_draw() to draw text in a GL window.

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12162 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Manolo Gouy 2017-01-10 15:33:14 +00:00
parent 0e22ca28dd
commit 723012c2bd
2 changed files with 41 additions and 1 deletions

View File

@ -83,7 +83,8 @@ public:
void color(Fl_Color c);
Fl_Color color() { return color_; }
void color(uchar r, uchar g, uchar b);
// --- implementation is in src/fl_font.cxx which includes src/cfg_gfx/xxx_font.cxx
// --- implementation is in Fl_OpenGL_Graphics_Driver_font.cxx
void font(Fl_Font face, Fl_Fontsize fsize);
void draw(const char *str, int n, int x, int y);
double width(const char *str, int n);
void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h);

View File

@ -93,6 +93,9 @@ static const char *font_data[128] = {
};
void Fl_OpenGL_Graphics_Driver::font(Fl_Font face, Fl_Fontsize fsize) {
Fl_Graphics_Driver::font(face, fsize);
}
double Fl_OpenGL_Graphics_Driver::width(const char *str, int n) {
return size_*n*0.5;
@ -169,10 +172,46 @@ FL_EXPORT int glutStrokeWidth(void *font, int character);
#else
// use gl_font()/gl_draw() to draw GL text
void Fl_OpenGL_Graphics_Driver::font(Fl_Font face, Fl_Fontsize fsize) {
Fl_Surface_Device::push_current(Fl_Display_Device::display_device());
gl_font(face, fsize);
Fl_Surface_Device::pop_current();
}
void Fl_OpenGL_Graphics_Driver::draw(const char* str, int n, int x, int y) {
gl_draw(str, n, x, y);
}
double Fl_OpenGL_Graphics_Driver::width(const char *str, int n) {
Fl_Surface_Device::push_current(Fl_Display_Device::display_device());
double w = fl_width(str, n);
Fl_Surface_Device::pop_current();
return w;
}
int Fl_OpenGL_Graphics_Driver::descent() {
Fl_Surface_Device::push_current(Fl_Display_Device::display_device());
int d = fl_descent();
Fl_Surface_Device::pop_current();
return d;
}
int Fl_OpenGL_Graphics_Driver::height() {
Fl_Surface_Device::push_current(Fl_Display_Device::display_device());
int h = fl_height();
Fl_Surface_Device::pop_current();
return h;
}
void Fl_OpenGL_Graphics_Driver::text_extents(const char *str, int n, int& dx, int& dy, int& w, int& h)
{
Fl_Surface_Device::push_current(Fl_Display_Device::display_device());
fl_text_extents(str, n, dx, dy, w, h);
Fl_Surface_Device::pop_current();
}
#endif