-
Notifications
You must be signed in to change notification settings - Fork 14
/
ofxsOGLTextRenderer.cpp
153 lines (132 loc) · 5.13 KB
/
ofxsOGLTextRenderer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; -*- */
/* ***** BEGIN LICENSE BLOCK *****
* This file is part of openfx-supportext <https://github.com/NatronGitHub/openfx-supportext>,
* (C) 2018-2021 The Natron Developers
* (C) 2013-2018 INRIA
*
* openfx-supportext is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* openfx-supportext is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with openfx-supportext. If not, see <http://www.gnu.org/licenses/gpl-2.0.html>
* ***** END LICENSE BLOCK ***** */
/*
* Small utility to draw text using OpenGL.
* This code is based on the free glut source code.
*
* Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
* Written by Pawel W. Olszta, <[email protected]>
* Creation date: Thu Dec 2 1999
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "ofxsOGLTextRenderer.h"
#include "ofxsOGLFontUtils.h"
#include <cstdlib>
namespace {
const OFX::SFG_Font*
getFont(OFX::TextRenderer::Font font)
{
switch (font) {
case OFX::TextRenderer::FONT_FIXED_8_X_13:
return &OFX::fgFontFixed8x13;
break;
case OFX::TextRenderer::FONT_FIXED_9_X_15:
return &OFX::fgFontFixed9x15;
break;
case OFX::TextRenderer::FONT_HELVETICA_10:
return &OFX::fgFontHelvetica10;
break;
case OFX::TextRenderer::FONT_HELVETICA_12:
return &OFX::fgFontHelvetica12;
break;
case OFX::TextRenderer::FONT_HELVETICA_18:
return &OFX::fgFontHelvetica18;
break;
case OFX::TextRenderer::FONT_TIMES_ROMAN_10:
return &OFX::fgFontTimesRoman10;
break;
case OFX::TextRenderer::FONT_TIMES_ROMAN_24:
return &OFX::fgFontTimesRoman24;
break;
default:
return (const OFX::SFG_Font*)NULL;
break;
}
}
}
void
OFX::TextRenderer::bitmapString(const char *string,
TextRenderer::Font f)
{
unsigned char c;
float x = 0.0f;
const SFG_Font* font = getFont(f);
if (!font) {
return;
}
if (!string || !*string) {
return;
}
glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT );
glPixelStorei( GL_UNPACK_SWAP_BYTES, GL_FALSE );
glPixelStorei( GL_UNPACK_LSB_FIRST, GL_FALSE );
glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
glPixelStorei( GL_UNPACK_SKIP_ROWS, 0 );
glPixelStorei( GL_UNPACK_SKIP_PIXELS, 0 );
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
/*
* Step through the string, drawing each character.
* A newline will simply translate the next character's insertion
* point back to the start of the line and down one line.
*/
while ( ( c = *string++) ) {
if (c == '\n') {
glBitmap ( 0, 0, 0, 0, -x, (float) -font->Height, NULL );
x = 0.0f;
} else { /* Not an EOL, draw the bitmap character */
const GLubyte* face = font->Characters[ c ];
glBitmap(
face[ 0 ], font->Height, /* Bitmap's width and height */
font->xorig, font->yorig, /* The origin in the font glyph */
( float )( face[ 0 ] ), 0.0f, /* The raster advance; inc. x,y */
( face + 1 ) /* The packed bitmap data... */
);
x += ( float )( face[ 0 ] );
}
}
glPopClientAttrib( );
}
void
OFX::TextRenderer::bitmapString(double x,
double y,
const char*string,
TextRenderer::Font font)
{
//glPushAttrib(GL_CURRENT_BIT); // caller is responsible for protecting attribs
glRasterPos2d(x, y);
bitmapString(string, font);
//glPopAttrib();
}