summaryrefslogtreecommitdiff
path: root/FL
diff options
context:
space:
mode:
authorManolo Gouy <Manolo>2018-02-07 15:34:44 +0000
committerManolo Gouy <Manolo>2018-02-07 15:34:44 +0000
commitdcc82d8926e447e422f200d01e1aa990233bc16a (patch)
treebc0d120f1381e0e8c0ef5c66262289e93d3b9a08 /FL
parent90630409cbe8740d2c8b66823757a4ea5441aa21 (diff)
STR#3450: Draw text with OpenGL using textures on all platforms.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12650 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'FL')
-rw-r--r--FL/Fl.H22
-rw-r--r--FL/Fl_Gl_Window_Driver.H26
-rw-r--r--FL/Fl_Graphics_Driver.H32
-rw-r--r--FL/gl.h21
4 files changed, 79 insertions, 22 deletions
diff --git a/FL/Fl.H b/FL/Fl.H
index 8cfed7f05..cb7f24ebb 100644
--- a/FL/Fl.H
+++ b/FL/Fl.H
@@ -134,6 +134,7 @@ class FL_EXPORT Fl {
private:
static int use_high_res_GL_;
+ static int draw_GL_text_with_textures_;
public:
@@ -1279,6 +1280,27 @@ int main() {
\version 1.3.4
*/
static int use_high_res_GL() { return use_high_res_GL_; }
+
+ /** sets whether OpenGL uses textures to draw all text.
+ By default, FLTK draws OpenGL text using textures, if the necessary
+ hardware support is available. Call \p Fl::draw_GL_text_with_textures(0)
+ once in your program before the first call to gl_font() to have FLTK
+ draw instead OpenGL text using a legacy, platform-dependent procedure.
+ It's recommended not to deactivate textures under the MacOS platform
+ because the MacOS legacy procedure is extremely rudimentary.
+ \param val use 0 to prevent FLTK from drawing GL text with textures
+ \see gl_texture_pile_height(int max)
+ \version 1.4.0
+ */
+ static void draw_GL_text_with_textures(int val) { draw_GL_text_with_textures_ = val; }
+
+ /** returns whether whether OpenGL uses textures to draw all text.
+ Default is yes.
+ \see draw_GL_text_with_textures(int val)
+ \version 1.4.0
+ */
+ static int draw_GL_text_with_textures() { return draw_GL_text_with_textures_; }
+
#ifdef FLTK_HAVE_CAIRO
/** \defgroup group_cairo Cairo Support Functions and Classes
diff --git a/FL/Fl_Gl_Window_Driver.H b/FL/Fl_Gl_Window_Driver.H
index 7ef89487e..63d08fedf 100644
--- a/FL/Fl_Gl_Window_Driver.H
+++ b/FL/Fl_Gl_Window_Driver.H
@@ -4,7 +4,7 @@
// Definition of class Fl_Gl_Window_Driver, and of its platform-specific derived classes
// for the Fast Light Tool Kit (FLTK).
//
-// Copyright 2016-2017 by Bill Spitzak and others.
+// Copyright 2016-2018 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -44,7 +44,7 @@ public:
void alist(const int *l) { pWindow->alist = l;}
void* overlay() {return pWindow->overlay;}
void draw_overlay() {pWindow->draw_overlay();}
-
+
Fl_Gl_Window_Driver(Fl_Gl_Window *win) : pWindow(win) {}
virtual ~Fl_Gl_Window_Driver() {}
static Fl_Gl_Window_Driver *newGlWindowDriver(Fl_Gl_Window *w);
@@ -79,10 +79,17 @@ public:
virtual void gl_visual(Fl_Gl_Choice*); // support for Fl::gl_visual() function
virtual void gl_start() {} // support for gl_start() function
virtual void* GetProcAddress(const char *procName); // support for glutGetProcAddress()
- virtual void draw_string(const char* str, int n); // support for gl_draw()
+ virtual void draw_string_legacy(const char* str, int n); // support for gl_draw()
+ void draw_string_legacy_get_list(const char* str, int n); // support for gl_draw()
+ static void draw_string_legacy_glut(const char* str, int n); // support for gl_draw()
virtual void get_list(Fl_Font_Descriptor* fd, int r) {} // support for gl_draw() without textures
virtual void gl_bitmap_font(Fl_Font_Descriptor *fl_fontsize) {} // support for gl_font() without textures
virtual int overlay_color(Fl_Color i) {return 0;} // support for gl_color() with HAVE_GL_OVERLAY
+ static void draw_string_with_texture(const char* str, int n); // cross-platform
+ // support for gl_draw(). The cross-platform version may be enough.
+ virtual char *alpha_mask_for_string(const char *str, int n, int w, int h);
+ virtual int genlistsize() { return 0; } // support for gl_draw()
+ virtual Fl_Font_Descriptor** fontnum_to_fontdescriptor(int fnum);
};
#ifdef FL_CFG_GFX_QUARTZ
@@ -111,13 +118,13 @@ class Fl_Cocoa_Gl_Window_Driver : public Fl_Gl_Window_Driver {
virtual void make_overlay_current();
virtual void redraw_overlay();
virtual void gl_start();
- virtual void draw_string(const char* str, int n);
static NSOpenGLContext* create_GLcontext_for_window(NSOpenGLPixelFormat *pixelformat, NSOpenGLContext *shared_ctx, Fl_Window *window);
static NSOpenGLPixelFormat *mode_to_NSOpenGLPixelFormat(int mode, const int*); // uses Objective-c
static void GLcontext_update(NSOpenGLContext*); // uses Objective-c
static void GLcontext_release(NSOpenGLContext*); // uses Objective-c
static void GLcontext_makecurrent(NSOpenGLContext*); // uses Objective-c
static void GL_cleardrawable(void); // uses Objective-c
+ virtual char *alpha_mask_for_string(const char *str, int n, int w, int h);
};
#endif // FL_CFG_GFX_QUARTZ
@@ -141,8 +148,10 @@ class Fl_WinAPI_Gl_Window_Driver : public Fl_Gl_Window_Driver {
virtual void make_overlay_current();
virtual void redraw_overlay();
virtual void* GetProcAddress(const char *procName);
+ virtual void draw_string_legacy(const char* str, int n);
virtual void gl_bitmap_font(Fl_Font_Descriptor *fl_fontsize);
virtual void get_list(Fl_Font_Descriptor *fd, int r);
+ virtual int genlistsize();
#if HAVE_GL_OVERLAY
virtual int can_do_overlay();
virtual int overlay_color(Fl_Color i);
@@ -153,7 +162,7 @@ class Fl_WinAPI_Gl_Window_Driver : public Fl_Gl_Window_Driver {
#ifdef FL_CFG_GFX_XLIB
-#include <X11/Xutil.h>
+#include <X11/Xutil.h> // for XVisualInfo
class Fl_X11_Gl_Window_Driver : public Fl_Gl_Window_Driver {
friend class Fl_Gl_Window_Driver;
Fl_X11_Gl_Window_Driver(Fl_Gl_Window *win) : Fl_Gl_Window_Driver(win) {}
@@ -178,9 +187,14 @@ class Fl_X11_Gl_Window_Driver : public Fl_Gl_Window_Driver {
virtual void waitGL();
virtual void gl_visual(Fl_Gl_Choice*); // support for Fl::gl_visual()
virtual void gl_start();
+ virtual void draw_string_legacy(const char* str, int n);
virtual void gl_bitmap_font(Fl_Font_Descriptor *fl_fontsize);
virtual void get_list(Fl_Font_Descriptor *fd, int r);
-public:
+ virtual int genlistsize();
+#if !USE_XFT
+ virtual Fl_Font_Descriptor** fontnum_to_fontdescriptor(int fnum);
+#endif
+ public:
static GLContext create_gl_context(XVisualInfo* vis);
};
diff --git a/FL/Fl_Graphics_Driver.H b/FL/Fl_Graphics_Driver.H
index 2dc1fb05a..bd4a82326 100644
--- a/FL/Fl_Graphics_Driver.H
+++ b/FL/Fl_Graphics_Driver.H
@@ -4,7 +4,7 @@
// Definition of classes Fl_Graphics_Driver, Fl_Surface_Device, Fl_Display_Device
// for the Fast Light Tool Kit (FLTK).
//
-// Copyright 2010-2017 by Bill Spitzak and others.
+// Copyright 2010-2018 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -90,6 +90,7 @@ class FL_EXPORT Fl_Graphics_Driver {
friend void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
friend FL_EXPORT int fl_draw_pixmap(const char*const* cdata, int x, int y, Fl_Color bg);
friend FL_EXPORT void gl_start();
+ friend FL_EXPORT void gl_finish();
friend FL_EXPORT Fl_Bitmask fl_create_bitmask(int w, int h, const uchar *array);
friend FL_EXPORT void fl_delete_bitmask(Fl_Bitmask);
private:
@@ -387,7 +388,7 @@ public:
/** Some platforms may need to implement this to support fonts */
virtual Fl_Fontdesc* calc_fl_fonts(void) {return NULL;}
/** Support for Fl::set_font() */
- virtual unsigned font_desc_size() {return 0;}
+ virtual unsigned font_desc_size();
/** Support for Fl::get_font() */
virtual const char *font_name(int num) {return NULL;}
/** Support for Fl::set_font() */
@@ -397,6 +398,33 @@ public:
};
#ifndef FL_DOXYGEN
+
+/* This class is not part of FLTK's public API.
+ Platforms usually define a derived class called Fl_XXX_Font_Descriptor
+ containing extra platform-specific data/functions.
+ This is a class for an actual system font, with junk to
+ help choose it and info on character sizes. Each Fl_Fontdesc has a
+ linked list of these. These are created the first time each system
+ font/size combination is used.
+ */
+class Fl_Font_Descriptor {
+public:
+ /** linked list for this Fl_Fontdesc */
+ Fl_Font_Descriptor *next;
+ Fl_Fontsize size; /**< font size */
+ Fl_Font_Descriptor(const char* fontname, Fl_Fontsize size);
+ FL_EXPORT ~Fl_Font_Descriptor() {}
+ short ascent, descent, q_width;
+ unsigned int listbase;// base of display list, 0 = none
+};
+
+// This struct is not part of FLTK's public API.
+struct Fl_Fontdesc {
+ const char *name;
+ char fontname[128]; // "Pretty" font name
+ Fl_Font_Descriptor *first; // linked list of sizes of this style
+};
+
/* Abstract class Fl_Scalable_Graphics_Driver is platform-independent.
It supports the scaling of all graphics coordinates by a
float factor helpful to support HiDPI displays.
diff --git a/FL/gl.h b/FL/gl.h
index 4cf6ca902..8c0e5c6f8 100644
--- a/FL/gl.h
+++ b/FL/gl.h
@@ -3,7 +3,7 @@
//
// OpenGL header file for the Fast Light Tool Kit (FLTK).
//
-// Copyright 1998-2011 by Bill Spitzak and others.
+// Copyright 1998-2018 by Bill Spitzak and others.
//
// You must include this instead of GL/gl.h to get the Microsoft
// APIENTRY stuff included (from <windows.h>) prior to the OpenGL
@@ -28,10 +28,11 @@
*
* To use OpenGL from within an FLTK application you MUST use gl_visual()
* to select the default visual before doing show() on any windows. Mesa
- * will crash if yoy try to use a visual not returned by glxChooseVidual.
+ * will crash if you try to use a visual not returned by glxChooseVisual.
*
- * This does not work with Fl_Double_Window's! It will try to draw
- * into the front buffer. Depending on the system this will either
+ * Historically, this did not always work well with Fl_Double_Window's!
+ * It can try to draw into the front buffer.
+ * Depending on the system this might either
* crash or do nothing (when pixmaps are being used as back buffer
* and GL is being done by hardware), work correctly (when GL is done
* with software, such as Mesa), or draw into the front buffer and
@@ -89,16 +90,8 @@ FL_EXPORT void gl_draw(const char*, int n, int x, int y);
FL_EXPORT void gl_draw(const char*, int n, float x, float y);
FL_EXPORT void gl_draw(const char*, int x, int y, int w, int h, Fl_Align);
FL_EXPORT void gl_measure(const char*, int& x, int& y);
-#ifdef __APPLE__ // PORTME: OpenGL platform texture
-extern FL_EXPORT void gl_texture_pile_height(int max);
-extern FL_EXPORT int gl_texture_pile_height();
-#elif defined(WIN32)
- // not needed
-#elif defined(FL_PORTING)
-# pragma message "FL_PORTING: define functions to control OpenGL texture pile height if supported"
-#else // X11
- // not needed
-#endif
+FL_EXPORT void gl_texture_pile_height(int max);
+FL_EXPORT int gl_texture_pile_height();
FL_EXPORT void gl_draw_image(const uchar *, int x,int y,int w,int h, int d=3, int ld=0);