g2o
Toggle main menu visibility
Loading...
Searching...
No Matches
g2o
EXTERNAL
freeglut
freeglut_font.cpp
Go to the documentation of this file.
1
/*
2
* freeglut_font.c
3
*
4
* Bitmap and stroke fonts displaying.
5
*
6
* Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7
* Written by Pawel W. Olszta, <olszta@sourceforge.net>
8
* Creation date: Thu Dec 16 1999
9
*
10
* Permission is hereby granted, free of charge, to any person obtaining a
11
* copy of this software and associated documentation files (the "Software"),
12
* to deal in the Software without restriction, including without limitation
13
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
14
* and/or sell copies of the Software, and to permit persons to whom the
15
* Software is furnished to do so, subject to the following conditions:
16
*
17
* The above copyright notice and this permission notice shall be included
18
* in all copies or substantial portions of the Software.
19
*
20
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23
* PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
*/
27
28
#include <iostream>
29
30
#include "
freeglut_minimal.h
"
31
32
#define freeglut_return_if_fail(expr) \
33
if (!(expr)) return;
34
#define freeglut_return_val_if_fail(expr, val) \
35
if (!(expr)) return val;
36
37
namespace
freeglut_minimal
{
38
39
/*
40
* Matches a font ID with a SFG_StrokeFont structure pointer.
41
* This was changed to match the GLUT header style.
42
*/
43
static
SFG_StrokeFont
*
fghStrokeByID
(
FontID
font) {
44
if
(font ==
GLUT_STROKE_ROMAN
)
return
(
SFG_StrokeFont
*)&
fgStrokeRoman
;
45
if
(font ==
GLUT_STROKE_MONO_ROMAN
)
46
return
(
SFG_StrokeFont
*)&
fgStrokeMonoRoman
;
47
48
std::cerr <<
"stroke font "
<< (int)font <<
" not found"
<< std::endl;
49
return
0;
50
}
51
52
void
glutStrokeString
(
FontID
fontID,
const
char
* string_) {
53
const
unsigned
char
*
string
=
reinterpret_cast<
const
unsigned
char
*
>
(string_);
54
unsigned
char
c;
55
int
i, j;
56
float
length = 0.0;
57
SFG_StrokeFont
* font;
58
// FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeString" );
59
font =
fghStrokeByID
(fontID);
60
freeglut_return_if_fail
(font);
61
if
(!
string
|| !*
string
)
return
;
62
63
/*
64
* Step through the string, drawing each character.
65
* A newline will simply translate the next character's insertion
66
* point back to the start of the line and down one line.
67
*/
68
while
((c = *
string
++))
69
if
(c < font->Quantity) {
70
if
(c ==
'\n'
) {
71
glTranslatef(-length, -(
float
)(font->
Height
), 0.0);
72
length = 0.0;
73
}
else
/* Not an EOL, draw the bitmap character */
74
{
75
const
SFG_StrokeChar
* schar = font->
Characters
[c];
76
if
(schar) {
77
const
SFG_StrokeStrip
* strip = schar->
Strips
;
78
79
for
(i = 0; i < schar->
Number
; i++, strip++) {
80
glBegin(GL_LINE_STRIP);
81
for
(j = 0; j < strip->
Number
; j++)
82
glVertex2f(strip->
Vertices
[j].
X
, strip->
Vertices
[j].
Y
);
83
84
glEnd();
85
}
86
87
length += schar->
Right
;
88
glTranslatef(schar->
Right
, 0.0f, 0.0f);
89
}
90
}
91
}
92
}
93
94
/*
95
* Return the width of a string drawn using a stroke font
96
*/
97
int
glutStrokeLength
(
FontID
fontID,
const
char
* string_) {
98
const
unsigned
char
*
string
=
reinterpret_cast<
const
unsigned
char
*
>
(string_);
99
unsigned
char
c;
100
float
length = 0.0;
101
float
this_line_length = 0.0;
102
SFG_StrokeFont
* font;
103
// FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeLength" );
104
font =
fghStrokeByID
(fontID);
105
freeglut_return_val_if_fail
(font, 0);
106
if
(!
string
|| !*
string
)
return
0;
107
108
while
((c = *
string
++))
109
if
(c < font->Quantity) {
110
if
(c ==
'\n'
)
/* EOL; reset the length of this line */
111
{
112
if
(length < this_line_length) length = this_line_length;
113
this_line_length = 0.0;
114
}
else
/* Not an EOL, increment the length of this line */
115
{
116
const
SFG_StrokeChar
* schar = font->
Characters
[c];
117
if
(schar) this_line_length += schar->
Right
;
118
}
119
}
120
if
(length < this_line_length) length = this_line_length;
121
return
(
int
)(length + 0.5);
122
}
123
124
/*
125
* Returns the height of a stroke font
126
*/
127
GLfloat
glutStrokeHeight
(
FontID
fontID) {
128
SFG_StrokeFont
* font;
129
// FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutStrokeHeight" );
130
font =
fghStrokeByID
(fontID);
131
freeglut_return_val_if_fail
(font, 0.0);
132
return
font->
Height
;
133
}
134
135
}
// namespace freeglut_minimal
136
137
/*** END OF FILE ***/
freeglut_return_if_fail
#define freeglut_return_if_fail(expr)
Definition
freeglut_font.cpp:32
freeglut_return_val_if_fail
#define freeglut_return_val_if_fail(expr, val)
Definition
freeglut_font.cpp:34
freeglut_minimal.h
freeglut_minimal
Definition
freeglut_font.cpp:37
freeglut_minimal::SFG_StrokeChar
struct tagSFG_StrokeChar SFG_StrokeChar
Definition
freeglut_minimal.h:76
freeglut_minimal::fgStrokeMonoRoman
const SFG_StrokeFont fgStrokeMonoRoman
Definition
freeglut_stroke_mono_roman.cpp:1473
freeglut_minimal::fghStrokeByID
static SFG_StrokeFont * fghStrokeByID(FontID font)
Definition
freeglut_font.cpp:43
freeglut_minimal::FontID
FontID
Definition
freeglut_minimal.h:61
freeglut_minimal::GLUT_STROKE_MONO_ROMAN
@ GLUT_STROKE_MONO_ROMAN
Definition
freeglut_minimal.h:61
freeglut_minimal::GLUT_STROKE_ROMAN
@ GLUT_STROKE_ROMAN
Definition
freeglut_minimal.h:61
freeglut_minimal::glutStrokeString
void glutStrokeString(FontID fontID, const char *string_)
Definition
freeglut_font.cpp:52
freeglut_minimal::fgStrokeRoman
const SFG_StrokeFont fgStrokeRoman
Definition
freeglut_stroke_roman.cpp:1438
freeglut_minimal::SFG_StrokeFont
struct tagSFG_StrokeFont SFG_StrokeFont
Definition
freeglut_minimal.h:83
freeglut_minimal::SFG_StrokeStrip
struct tagSFG_StrokeStrip SFG_StrokeStrip
Definition
freeglut_minimal.h:70
freeglut_minimal::glutStrokeLength
int glutStrokeLength(FontID fontID, const char *string_)
Definition
freeglut_font.cpp:97
freeglut_minimal::glutStrokeHeight
GLfloat glutStrokeHeight(FontID fontID)
Definition
freeglut_font.cpp:127
freeglut_minimal::tagSFG_StrokeChar::Number
int Number
Definition
freeglut_minimal.h:79
freeglut_minimal::tagSFG_StrokeChar::Right
GLfloat Right
Definition
freeglut_minimal.h:78
freeglut_minimal::tagSFG_StrokeChar::Strips
const SFG_StrokeStrip * Strips
Definition
freeglut_minimal.h:80
freeglut_minimal::tagSFG_StrokeFont::Height
GLfloat Height
Definition
freeglut_minimal.h:87
freeglut_minimal::tagSFG_StrokeFont::Characters
const SFG_StrokeChar ** Characters
Definition
freeglut_minimal.h:88
freeglut_minimal::tagSFG_StrokeStrip::Vertices
const SFG_StrokeVertex * Vertices
Definition
freeglut_minimal.h:73
freeglut_minimal::tagSFG_StrokeStrip::Number
int Number
Definition
freeglut_minimal.h:72
freeglut_minimal::tagSFG_StrokeVertex::X
GLfloat X
Definition
freeglut_minimal.h:67
freeglut_minimal::tagSFG_StrokeVertex::Y
GLfloat Y
Definition
freeglut_minimal.h:67
Generated on
for g2o by
1.17.0