Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Fonts/OpenGLTextCoordinates.cpp @ 1985:bb307007f8e2
improved interaction with rectangle probes
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 31 Oct 2022 15:01:09 +0100 |
parents | 7053b8a0aaec |
children | 07964689cb0b |
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 | |
1871
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
577 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
577 | 10 * as published by the Free Software Foundation, either version 3 of |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
16 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
17 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
577 | 21 **/ |
22 | |
23 | |
24 #include "OpenGLTextCoordinates.h" | |
25 | |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1270
diff
changeset
|
26 #include <OrthancException.h> |
577 | 27 |
28 namespace OrthancStone | |
29 { | |
30 namespace OpenGL | |
31 { | |
32 void OpenGLTextCoordinates::Visit(uint32_t unicode, | |
33 int x, | |
34 int y, | |
35 unsigned int width, | |
36 unsigned int height, | |
37 const Orthanc::IDynamicObject* payload) | |
38 { | |
39 // 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
|
40 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
|
41 float ry1 = static_cast<float>(y - box_.GetTop()); |
577 | 42 float rx2 = rx1 + static_cast<float>(width); |
43 float ry2 = ry1 + static_cast<float>(height); | |
44 | |
45 // Texture coordinates | |
46 assert(payload != NULL); | |
47 const GlyphTextureAlphabet::TextureLocation& location = | |
48 *dynamic_cast<const GlyphTextureAlphabet::TextureLocation*>(payload); | |
49 | |
50 float tx1 = location.GetX() / textureWidth_; | |
51 float ty1 = location.GetY() / textureHeight_; | |
52 float tx2 = tx1 + (static_cast<float>(width) / textureWidth_); | |
53 float ty2 = ty1 + (static_cast<float>(height) / textureHeight_); | |
54 | |
55 const float rpos[6][2] = { | |
56 { rx1, ry1 }, | |
57 { rx1, ry2 }, | |
58 { rx2, ry1 }, | |
59 { rx2, ry1 }, | |
60 { rx1, ry2 }, | |
61 { rx2, ry2 } | |
62 }; | |
63 | |
64 const float tpos[6][2] = { | |
65 { tx1, ty1 }, | |
66 { tx1, ty2 }, | |
67 { tx2, ty1 }, | |
68 { tx2, ty1 }, | |
69 { tx1, ty2 }, | |
70 { tx2, ty2 } | |
71 }; | |
72 | |
73 for (unsigned int i = 0; i < 6; i++) | |
74 { | |
75 renderingCoords_.push_back(rpos[i][0]); | |
76 renderingCoords_.push_back(rpos[i][1]); | |
77 textureCoords_.push_back(tpos[i][0]); | |
78 textureCoords_.push_back(tpos[i][1]); | |
79 } | |
80 } | |
81 | |
82 | |
83 OpenGLTextCoordinates::OpenGLTextCoordinates(const GlyphTextureAlphabet& alphabet, | |
84 const std::string& utf8) : | |
85 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
|
86 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
|
87 textureHeight_(static_cast<float>(alphabet.GetTextureHeight())) |
577 | 88 { |
89 if (textureWidth_ <= 0 || | |
90 textureHeight_ <= 0) | |
91 { | |
92 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
93 } | |
94 | |
95 width_ = static_cast<float>(box_.GetWidth()); | |
96 height_ = static_cast<float>(box_.GetHeight()); | |
97 | |
98 // Each character is made of two 2D triangles (= 2 * 3 * 2 = 12) | |
99 renderingCoords_.reserve(box_.GetCharactersCount() * 12); | |
100 textureCoords_.reserve(box_.GetCharactersCount() * 12); | |
101 | |
102 alphabet.GetAlphabet().Apply(*this, utf8); | |
103 } | |
104 | |
105 | |
106 const std::vector<float>& OpenGLTextCoordinates::GetRenderingCoords() const | |
107 { | |
108 assert(renderingCoords_.size() == textureCoords_.size()); | |
109 return renderingCoords_; | |
110 } | |
111 | |
112 | |
113 const std::vector<float>& OpenGLTextCoordinates::GetTextureCoords() const | |
114 { | |
115 assert(renderingCoords_.size() == textureCoords_.size()); | |
116 return textureCoords_; | |
117 } | |
118 } | |
119 } |