mirror of
https://github.com/fltk/fltk.git
synced 2026-06-05 08:06:35 +08:00
Extracting OpenGL text calls. This is a minimum implementation for testing. Don;t worry. I have a cunning plan for rendering perfect antialiased text into OpenGL contexts quickly on all platforms.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11048 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
+26
-83
@@ -113,9 +113,11 @@ public:
|
||||
to support all FLTK drawing functions.
|
||||
*/
|
||||
class FL_EXPORT Fl_Graphics_Driver : public Fl_Device {
|
||||
friend class Fl_Pixmap;
|
||||
friend class Fl_Bitmap;
|
||||
friend class Fl_RGB_Image;
|
||||
public:
|
||||
/** A 2D coordinate transformation matrix
|
||||
*/
|
||||
/** A 2D coordinate transformation matrix */
|
||||
struct matrix {double a, b, c, d, x, y;};
|
||||
protected:
|
||||
static const matrix m0;
|
||||
@@ -134,64 +136,16 @@ protected:
|
||||
static const int region_stack_max = FL_REGION_STACK_SIZE - 1;
|
||||
Fl_Region rstack[FL_REGION_STACK_SIZE];
|
||||
Fl_Font_Descriptor *font_descriptor_;
|
||||
|
||||
protected:
|
||||
#ifndef FL_DOXYGEN
|
||||
enum {LINE, LOOP, POLYGON, POINT_};
|
||||
inline int vertex_no() { return n; }
|
||||
inline XPOINT *vertices() {return p;}
|
||||
inline int vertex_kind() {return what;}
|
||||
#endif
|
||||
/* ** \brief red color for background and/or mixing if device does not support masking or alpha *
|
||||
uchar bg_r_;
|
||||
** \brief green color for background and/or mixing if device does not support masking or alpha *
|
||||
uchar bg_g_;
|
||||
** \brief blue color for background and/or mixing if device does not support masking or alpha *
|
||||
uchar bg_b_; */
|
||||
friend class Fl_Pixmap;
|
||||
friend class Fl_Bitmap;
|
||||
friend class Fl_RGB_Image;
|
||||
friend void fl_draw(const char *str, int n, int x, int y);
|
||||
#ifdef __APPLE__
|
||||
friend void fl_draw(const char *str, int n, float x, float y);
|
||||
#elif defined(WIN32)
|
||||
// not needed
|
||||
#elif defined(FL_PORTING)
|
||||
# pragma message "FL_PORTING: add floating point text positioning if your platform supports it"
|
||||
#else
|
||||
// not needed
|
||||
#endif
|
||||
friend void fl_draw(int angle, const char *str, int n, int x, int y);
|
||||
friend void fl_rtl_draw(const char *str, int n, int x, int y);
|
||||
friend void fl_font(Fl_Font face, Fl_Fontsize size);
|
||||
|
||||
friend void fl_draw_image(const uchar* buf, int X,int Y,int W,int H, int D, int L);
|
||||
friend void fl_draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D, int L);
|
||||
friend void fl_draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D);
|
||||
friend FL_EXPORT void fl_draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D);
|
||||
friend FL_EXPORT void gl_start();
|
||||
friend void fl_copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
|
||||
matrix *fl_matrix; /**< Points to the current coordinate transformation matrix */
|
||||
|
||||
/** \brief The constructor. */
|
||||
Fl_Graphics_Driver();
|
||||
/** \brief see fl_draw(const char *str, int n, int x, int y). */
|
||||
virtual void draw(const char *str, int n, int x, int y) {}
|
||||
#ifdef __APPLE__
|
||||
virtual void draw(const char *str, int n, float x, float y) { draw(str, n, (int)(x+0.5), (int)(y+0.5));}
|
||||
#elif defined(WIN32)
|
||||
// not needed
|
||||
#elif defined(FL_PORTING)
|
||||
# pragma message "FL_PORTING: add floating point text positioning if your platform supports it"
|
||||
#else
|
||||
// not needed
|
||||
#endif
|
||||
/** \brief see fl_draw(int angle, const char *str, int n, int x, int y). */
|
||||
virtual void draw(int angle, const char *str, int n, int x, int y) {}
|
||||
/** \brief see fl_rtl_draw(const char *str, int n, int x, int y). */
|
||||
virtual void rtl_draw(const char *str, int n, int x, int y) {};
|
||||
|
||||
// Images
|
||||
public:
|
||||
// ---- Images
|
||||
/** \brief see fl_draw_image(const uchar* buf, int X,int Y,int W,int H, int D, int L). */
|
||||
virtual void draw_image(const uchar* buf, int X,int Y,int W,int H, int D=3, int L=0) {}
|
||||
/** \brief see fl_draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D, int L). */
|
||||
@@ -219,42 +173,16 @@ protected:
|
||||
the image offset by the cx and cy arguments.
|
||||
*/
|
||||
virtual void draw(Fl_Bitmap *bm, int XP, int YP, int WP, int HP, int cx, int cy) {}
|
||||
#if FLTK_ABI_VERSION >= 10301
|
||||
virtual
|
||||
#endif
|
||||
void copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
|
||||
virtual int draw_scaled(Fl_Image *img, int X, int Y, int W, int H);
|
||||
virtual void copy_offscreen(int x, int y, int w, int h, Fl_Offscreen pixmap, int srcx, int srcy);
|
||||
|
||||
|
||||
// === all code below in this class has been to the reorganisation FL_PORTING process
|
||||
public:
|
||||
static const char *class_id;
|
||||
virtual const char *class_name() {return class_id;};
|
||||
/** \brief see fl_font(Fl_Font face, Fl_Fontsize size). */
|
||||
virtual void font(Fl_Font face, Fl_Fontsize fsize) {font_ = face; size_ = fsize;}
|
||||
/** \brief see fl_font(void). */
|
||||
Fl_Font font() {return font_; }
|
||||
/** \brief see fl_size(). */
|
||||
Fl_Fontsize size() {return size_; }
|
||||
/** \brief see fl_width(const char *str, int n). */
|
||||
virtual double width(const char *str, int n) {return 0;}
|
||||
/** \brief see fl_width(unsigned int n). */
|
||||
virtual inline double width(unsigned int c) { char ch = (char)c; return width(&ch, 1); }
|
||||
/** \brief see fl_text_extents(const char*, int n, int& dx, int& dy, int& w, int& h). */
|
||||
virtual void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h);
|
||||
/** \brief see fl_height(). */
|
||||
virtual int height() {return size();}
|
||||
/** \brief see fl_descent(). */
|
||||
virtual int descent() {return 0;}
|
||||
/** Returns a pointer to the current Fl_Font_Descriptor for the graphics driver */
|
||||
inline Fl_Font_Descriptor *font_descriptor() { return font_descriptor_;}
|
||||
/** Sets the current Fl_Font_Descriptor for the graphics driver */
|
||||
inline void font_descriptor(Fl_Font_Descriptor *d) { font_descriptor_ = d;}
|
||||
#if FLTK_ABI_VERSION >= 10304 || defined(FL_DOXYGEN)
|
||||
virtual
|
||||
#endif
|
||||
int draw_scaled(Fl_Image *img, int X, int Y, int W, int H);
|
||||
/** \brief The destructor */
|
||||
Fl_Graphics_Driver();
|
||||
virtual ~Fl_Graphics_Driver() { if (p) free(p); }
|
||||
|
||||
// === all code below in this class has been to the reorganisation FL_PORTING process
|
||||
public:
|
||||
// --- implementation is in src/fl_rect.cxx which includes src/cfg_gfx/xxx_rect.cxx
|
||||
virtual void point(int x, int y) = 0;
|
||||
@@ -320,6 +248,21 @@ public:
|
||||
virtual void color(Fl_Color c) { color_ = c; }
|
||||
virtual Fl_Color color() { return color_; }
|
||||
virtual void color(uchar r, uchar g, uchar b) = 0;
|
||||
// --- implementation is in src/fl_font.cxx which includes src/cfg_gfx/xxx_font.cxx
|
||||
virtual void draw(const char *str, int n, int x, int y) = 0;
|
||||
virtual void draw(const char *str, int n, float x, float y) { draw(str, n, (int)(x+0.5), (int)(y+0.5));}
|
||||
virtual void draw(int angle, const char *str, int n, int x, int y) { draw(str, n, x, y); }
|
||||
virtual void rtl_draw(const char *str, int n, int x, int y) { draw(str, n, x, y); }
|
||||
virtual void font(Fl_Font face, Fl_Fontsize fsize) {font_ = face; size_ = fsize;}
|
||||
virtual Fl_Font font() {return font_; }
|
||||
virtual Fl_Fontsize size() {return size_; }
|
||||
virtual double width(const char *str, int n) { return 0; }
|
||||
virtual double width(unsigned int c) { char ch = (char)c; return width(&ch, 1); }
|
||||
virtual void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h);
|
||||
virtual int height() { return size(); }
|
||||
virtual int descent() { return 0; }
|
||||
virtual Fl_Font_Descriptor *font_descriptor() { return font_descriptor_;}
|
||||
virtual void font_descriptor(Fl_Font_Descriptor *d) { font_descriptor_ = d;}
|
||||
|
||||
protected:
|
||||
// --- implementation is in src/fl_vertex.cxx which includes src/cfg_gfx/xxx_rect.cxx
|
||||
|
||||
@@ -55,6 +55,7 @@ const char *Fl_OpenGL_Display_Device::class_id = "Fl_OpenGL_Display_Device";
|
||||
|
||||
#include "cfg_gfx/opengl_arci.cxx"
|
||||
#include "cfg_gfx/opengl_color.cxx"
|
||||
#include "cfg_gfx/opengl_font.cxx"
|
||||
#include "cfg_gfx/opengl_line_style.cxx"
|
||||
#include "cfg_gfx/opengl_rect.cxx"
|
||||
#include "cfg_gfx/opengl_vertex.cxx"
|
||||
|
||||
@@ -35,7 +35,6 @@ class FL_EXPORT Fl_OpenGL_Graphics_Driver : public Fl_Graphics_Driver {
|
||||
public:
|
||||
static const char *class_id;
|
||||
const char *class_name() {return class_id;};
|
||||
void draw(const char* str, int n, int x, int y);
|
||||
// --- line and polygon drawing with integer coordinates
|
||||
void point(int x, int y);
|
||||
void rect(int x, int y, int w, int h);
|
||||
@@ -86,6 +85,12 @@ 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
|
||||
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);
|
||||
int height();
|
||||
int descent();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
//
|
||||
// "$Id$"
|
||||
//
|
||||
// Standard X11 font selection code for the Fast Light Tool Kit (FLTK).
|
||||
//
|
||||
// Copyright 1998-2016 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
|
||||
// file is missing or damaged, see the license at:
|
||||
//
|
||||
// http://www.fltk.org/COPYING.php
|
||||
//
|
||||
// Please report all bugs and problems on the following page:
|
||||
//
|
||||
// http://www.fltk.org/str.php
|
||||
//
|
||||
|
||||
/*
|
||||
This module implements a lowest-common-denominator font for OpenGL.
|
||||
It will always work, even if the main graphics library does not support
|
||||
rendering text into a texture buffer.
|
||||
|
||||
The font is limited to a single face and ASCII characters. It is drawn using
|
||||
lines which makes it arbitrarily scalable. I am trying to keep font data really
|
||||
compact.
|
||||
*/
|
||||
|
||||
|
||||
#include <FL/gl.h>
|
||||
|
||||
/*
|
||||
|01234567|
|
||||
-+--------+
|
||||
0| |____
|
||||
1|++++++++|font
|
||||
2|++++++++|
|
||||
3|++++++++|
|
||||
4|++++++++|
|
||||
5|++++++++|____
|
||||
6| |descent
|
||||
7| |
|
||||
-+--------+
|
||||
*/
|
||||
|
||||
|
||||
static const char *font_data[128] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, /*T*/"\11\71\100\41\45", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
|
||||
0, 0, 0, 0, 0, /*e*/"\55\25\14\13\22\52\63\64\14", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, /*s*/"\62\22\13\64\55\15", /*t*/"\41\44\55\65\100\22\62", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
void Fl_OpenGL_Graphics_Driver::draw(const char* str, int n, int x, int y) {
|
||||
gl_draw(str, n, x, y);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
double Fl_OpenGL_Graphics_Driver::width(const char *str, int n) {
|
||||
return size_*n*0.5;
|
||||
}
|
||||
|
||||
int Fl_OpenGL_Graphics_Driver::descent() {
|
||||
return (int)(size_ - size_*0.8);
|
||||
}
|
||||
|
||||
int Fl_OpenGL_Graphics_Driver::height() {
|
||||
return (int)(size_*0.8);
|
||||
}
|
||||
|
||||
void Fl_OpenGL_Graphics_Driver::text_extents(const char *str, int n, int& dx, int& dy, int& w, int& h)
|
||||
{
|
||||
dx = 0;
|
||||
dy = descent();
|
||||
w = width(str, n);
|
||||
h = size_;
|
||||
}
|
||||
|
||||
void Fl_OpenGL_Graphics_Driver::draw(const char *str, int n, int x, int y)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<n; i++) {
|
||||
char c = str[i] & 0x7f;
|
||||
const char *fd = font_data[(int)c];
|
||||
if (fd) {
|
||||
char rendering = 0;
|
||||
float px, py;
|
||||
for (;;) {
|
||||
char cmd = *fd++;
|
||||
if (cmd==0) {
|
||||
if (rendering) {
|
||||
glEnd();
|
||||
glBegin(GL_POINTS); glVertex2f(px, py); glEnd();
|
||||
rendering = 0;
|
||||
}
|
||||
break;
|
||||
} else if (cmd>63) {
|
||||
if (cmd=='\100' && rendering) {
|
||||
glEnd();
|
||||
glBegin(GL_POINTS); glVertex2f(px, py); glEnd();
|
||||
rendering = 0;
|
||||
}
|
||||
} else {
|
||||
if (!rendering) { glBegin(GL_LINE_STRIP); rendering = 1; }
|
||||
int vx = (cmd & '\70')>>3;
|
||||
int vy = (cmd & '\07');
|
||||
px = 0.5+x+vx*size_*0.5/8.0;
|
||||
py = 0.5+y+vy*size_/8.0-0.8*size_;
|
||||
glVertex2f(px, py);
|
||||
}
|
||||
}
|
||||
}
|
||||
x += size_*0.5;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
//
|
||||
// End of "$Id$".
|
||||
//
|
||||
@@ -28,10 +28,6 @@
|
||||
#include <FL/gl.h>
|
||||
#include "opengl.H"
|
||||
|
||||
void Fl_OpenGL_Graphics_Driver::draw(const char* str, int n, int x, int y) {
|
||||
gl_draw(str, n, x, y);
|
||||
}
|
||||
|
||||
// --- line and polygon drawing with integer coordinates
|
||||
|
||||
void Fl_OpenGL_Graphics_Driver::point(int x, int y) {
|
||||
|
||||
+12
-12
@@ -43,13 +43,7 @@ class FL_EXPORT Fl_Quartz_Graphics_Driver : public Fl_Graphics_Driver {
|
||||
public:
|
||||
static const char *class_id;
|
||||
const char *class_name() {return class_id;};
|
||||
void draw(const char* str, int n, int x, int y);
|
||||
#ifdef __APPLE__
|
||||
void draw(const char *str, int n, float x, float y);
|
||||
#endif
|
||||
void draw(int angle, const char *str, int n, int x, int y);
|
||||
void rtl_draw(const char* str, int n, int x, int y);
|
||||
void font(Fl_Font face, Fl_Fontsize size);
|
||||
|
||||
void draw(Fl_Pixmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
|
||||
void draw(Fl_Bitmap *pxm, int XP, int YP, int WP, int HP, int cx, int cy);
|
||||
void draw(Fl_RGB_Image *img, int XP, int YP, int WP, int HP, int cx, int cy);
|
||||
@@ -58,11 +52,6 @@ public:
|
||||
void draw_image(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=3);
|
||||
void draw_image_mono(const uchar* buf, int X,int Y,int W,int H, int D=1, int L=0);
|
||||
void draw_image_mono(Fl_Draw_Image_Cb cb, void* data, int X,int Y,int W,int H, int D=1);
|
||||
double width(const char *str, int n);
|
||||
double width(unsigned int c);
|
||||
void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h);
|
||||
int height();
|
||||
int descent();
|
||||
#if ! defined(FL_DOXYGEN)
|
||||
static Fl_Offscreen create_offscreen_with_alpha(int w, int h);
|
||||
#endif
|
||||
@@ -113,6 +102,17 @@ protected:
|
||||
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
|
||||
void draw(const char *str, int n, int x, int y);
|
||||
void draw(const char *str, int n, float x, float y);
|
||||
void draw(int angle, const char *str, int n, int x, int y);
|
||||
void rtl_draw(const char *str, int n, int x, int y);
|
||||
void font(Fl_Font face, Fl_Fontsize fsize);
|
||||
double width(const char *str, int n);
|
||||
double width(unsigned int c);
|
||||
void text_extents(const char*, int n, int& dx, int& dy, int& w, int& h);
|
||||
int height();
|
||||
int descent();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
//
|
||||
// MacOS font selection routines for the Fast Light Tool Kit (FLTK).
|
||||
//
|
||||
// Copyright 1998-2015 by Bill Spitzak and others.
|
||||
// Copyright 1998-2016 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
|
||||
+1
-1
@@ -48,7 +48,7 @@
|
||||
#ifdef WIN32
|
||||
# include "fl_font_win32.cxx"
|
||||
#elif defined(__APPLE__)
|
||||
# include "fl_font_mac.cxx"
|
||||
# include "cfg_gfx/quartz_font.cxx"
|
||||
#elif USE_XFT
|
||||
# include "fl_font_xft.cxx"
|
||||
#elif defined(FL_PORTING)
|
||||
|
||||
Reference in New Issue
Block a user