Mercurial > hg > orthanc-stone
annotate Framework/Fonts/OpenGLTextCoordinates.cpp @ 702:c0a5eb9a4290 refactor-viewport-controller
Merge from default
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Sun, 19 May 2019 16:29:50 +0200 |
parents | 9a474e90e832 |
children | 2d8ab34c8c91 |
rev | line source |
---|---|
577 | 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 | |
693
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
577
diff
changeset
|
38 float rx1 = static_cast<float>(x - box_.GetLeft()); |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
577
diff
changeset
|
39 float ry1 = static_cast<float>(y - box_.GetTop()); |
577 | 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), | |
693
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
577
diff
changeset
|
84 textureWidth_(static_cast<float>(alphabet.GetTextureWidth())), |
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
577
diff
changeset
|
85 textureHeight_(static_cast<float>(alphabet.GetTextureHeight())) |
577 | 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 } |