Mercurial > hg > orthanc-stone
comparison Framework/Fonts/OpenGLTextCoordinates.cpp @ 577:b098a3aaf694
alphabet of glyphs
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 19 Apr 2019 15:42:57 +0200 |
parents | |
children | 9a474e90e832 |
comparison
equal
deleted
inserted
replaced
576:529c9617654b | 577:b098a3aaf694 |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #include "OpenGLTextCoordinates.h" | |
23 | |
24 #include <Core/OrthancException.h> | |
25 | |
26 namespace OrthancStone | |
27 { | |
28 namespace OpenGL | |
29 { | |
30 void OpenGLTextCoordinates::Visit(uint32_t unicode, | |
31 int x, | |
32 int y, | |
33 unsigned int width, | |
34 unsigned int height, | |
35 const Orthanc::IDynamicObject* payload) | |
36 { | |
37 // Rendering coordinates | |
38 float rx1 = x - box_.GetLeft(); | |
39 float ry1 = y - box_.GetTop(); | |
40 float rx2 = rx1 + static_cast<float>(width); | |
41 float ry2 = ry1 + static_cast<float>(height); | |
42 | |
43 // Texture coordinates | |
44 assert(payload != NULL); | |
45 const GlyphTextureAlphabet::TextureLocation& location = | |
46 *dynamic_cast<const GlyphTextureAlphabet::TextureLocation*>(payload); | |
47 | |
48 float tx1 = location.GetX() / textureWidth_; | |
49 float ty1 = location.GetY() / textureHeight_; | |
50 float tx2 = tx1 + (static_cast<float>(width) / textureWidth_); | |
51 float ty2 = ty1 + (static_cast<float>(height) / textureHeight_); | |
52 | |
53 const float rpos[6][2] = { | |
54 { rx1, ry1 }, | |
55 { rx1, ry2 }, | |
56 { rx2, ry1 }, | |
57 { rx2, ry1 }, | |
58 { rx1, ry2 }, | |
59 { rx2, ry2 } | |
60 }; | |
61 | |
62 const float tpos[6][2] = { | |
63 { tx1, ty1 }, | |
64 { tx1, ty2 }, | |
65 { tx2, ty1 }, | |
66 { tx2, ty1 }, | |
67 { tx1, ty2 }, | |
68 { tx2, ty2 } | |
69 }; | |
70 | |
71 for (unsigned int i = 0; i < 6; i++) | |
72 { | |
73 renderingCoords_.push_back(rpos[i][0]); | |
74 renderingCoords_.push_back(rpos[i][1]); | |
75 textureCoords_.push_back(tpos[i][0]); | |
76 textureCoords_.push_back(tpos[i][1]); | |
77 } | |
78 } | |
79 | |
80 | |
81 OpenGLTextCoordinates::OpenGLTextCoordinates(const GlyphTextureAlphabet& alphabet, | |
82 const std::string& utf8) : | |
83 box_(alphabet.GetAlphabet(), utf8), | |
84 textureWidth_(alphabet.GetTextureWidth()), | |
85 textureHeight_(alphabet.GetTextureHeight()) | |
86 { | |
87 if (textureWidth_ <= 0 || | |
88 textureHeight_ <= 0) | |
89 { | |
90 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
91 } | |
92 | |
93 width_ = static_cast<float>(box_.GetWidth()); | |
94 height_ = static_cast<float>(box_.GetHeight()); | |
95 | |
96 // Each character is made of two 2D triangles (= 2 * 3 * 2 = 12) | |
97 renderingCoords_.reserve(box_.GetCharactersCount() * 12); | |
98 textureCoords_.reserve(box_.GetCharactersCount() * 12); | |
99 | |
100 alphabet.GetAlphabet().Apply(*this, utf8); | |
101 } | |
102 | |
103 | |
104 const std::vector<float>& OpenGLTextCoordinates::GetRenderingCoords() const | |
105 { | |
106 assert(renderingCoords_.size() == textureCoords_.size()); | |
107 return renderingCoords_; | |
108 } | |
109 | |
110 | |
111 const std::vector<float>& OpenGLTextCoordinates::GetTextureCoords() const | |
112 { | |
113 assert(renderingCoords_.size() == textureCoords_.size()); | |
114 return textureCoords_; | |
115 } | |
116 } | |
117 } |