Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracting OpenGL text calls. This is a minimum implementation for te…
…sting. 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
- Loading branch information
Matthias Melcher
committed
Jan 24, 2016
1 parent
60c114b
commit 6a12d16
Showing
8 changed files
with
181 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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$". | ||
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters