質問編集履歴
1
文章を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,30 +12,250 @@
|
|
12
12
|
|
13
13
|
```cpp
|
14
14
|
|
15
|
+
// ##################################### フォーマット書式描画 #####################################
|
16
|
+
|
17
|
+
void FrameWork::Text::DrawFormatString(glm::vec2 pos, glm::vec4 color, const char* str)
|
18
|
+
|
19
|
+
{
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
std::vector<Character> textData(0); //文字データを格納
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
if (str != NULL)
|
28
|
+
|
29
|
+
{
|
30
|
+
|
31
|
+
///////////////////////////////////////////////////////////////////////////////////////////////
|
32
|
+
|
15
|
-
//マルチバイト文字をワイド文字変換
|
33
|
+
//マルチバイト文字をワイド文字変換
|
16
34
|
|
17
35
|
wchar_t txt[1000] = { L'\0' };
|
18
36
|
|
19
|
-
char text[1000];
|
37
|
+
char text[1000] = {'\0'};
|
20
38
|
|
21
39
|
|
22
40
|
|
23
41
|
va_list args = NULL;
|
24
42
|
|
25
|
-
va_list args2 = NULL;
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
va_start(args
|
43
|
+
va_start(args, str);
|
30
|
-
|
31
|
-
va_copy(args,args2);
|
32
|
-
|
33
|
-
|
34
44
|
|
35
45
|
vsprintf_s(text, sizeof(text), str, args);
|
36
46
|
|
37
47
|
va_end(args);
|
38
48
|
|
49
|
+
//////////////////////////////////////////////////////////////////////////////////////////////
|
50
|
+
|
51
|
+
int i, j, f;
|
52
|
+
|
53
|
+
for (i = 0, j = 0; text[j]; i++, j += f)
|
54
|
+
|
55
|
+
{
|
56
|
+
|
57
|
+
f = (int)mbrtowc(txt + i, &text[j], (size_t)MB_CUR_MAX, nullptr);
|
58
|
+
|
59
|
+
}
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
//文字をロード
|
64
|
+
|
65
|
+
for (int i = 0; txt[i] != L'\0'; i++)
|
66
|
+
|
67
|
+
{
|
68
|
+
|
69
|
+
//グリフをロード
|
70
|
+
|
71
|
+
FT_Load_Glyph(face, FT_Get_Char_Index(face, txt[i]), FT_LOAD_RENDER);
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
Character ch =
|
76
|
+
|
77
|
+
{
|
78
|
+
|
79
|
+
0,
|
80
|
+
|
81
|
+
glm::ivec2(face->glyph->bitmap.width, face->glyph->bitmap.rows),
|
82
|
+
|
83
|
+
glm::ivec2(face->glyph->bitmap_left, face->glyph->bitmap_top),
|
84
|
+
|
85
|
+
(unsigned int)face->glyph->advance.x
|
86
|
+
|
87
|
+
};
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
glGenTextures(1, &ch.textureID);
|
92
|
+
|
93
|
+
glBindTexture(GL_TEXTURE_2D, ch.textureID);
|
94
|
+
|
95
|
+
glActiveTexture(GL_TEXTURE0);
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
glTexImage2D
|
100
|
+
|
101
|
+
(
|
102
|
+
|
103
|
+
GL_TEXTURE_2D,
|
104
|
+
|
105
|
+
0,
|
106
|
+
|
107
|
+
GL_RED,
|
108
|
+
|
109
|
+
face->glyph->bitmap.width,
|
110
|
+
|
111
|
+
face->glyph->bitmap.rows,
|
112
|
+
|
113
|
+
0,
|
114
|
+
|
115
|
+
GL_RED,
|
116
|
+
|
117
|
+
GL_UNSIGNED_BYTE,
|
118
|
+
|
119
|
+
face->glyph->bitmap.buffer
|
120
|
+
|
121
|
+
);
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
//テクスチャタイプを設定
|
126
|
+
|
127
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
128
|
+
|
129
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
130
|
+
|
131
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
132
|
+
|
133
|
+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
//テクスチャを生成
|
140
|
+
|
141
|
+
textData.push_back(ch);
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
shader->setEnable(); //シェーダーを有効にする
|
154
|
+
|
155
|
+
glBindVertexArray(vao);
|
156
|
+
|
157
|
+
glBindBuffer(GL_ARRAY_BUFFER, vbo);
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
//色をRGBにして位置を反転
|
162
|
+
|
163
|
+
pos.y = FrameWork::getWindowContext()->getSize().y - pos.y - charSize;
|
164
|
+
|
165
|
+
float c = 1.0f / 255.0f;
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
//Unform
|
170
|
+
|
171
|
+
shader->setUniform4f("uTextColor", color * c);
|
172
|
+
|
173
|
+
shader->setUniformMatrix4fv("uViewProjection", glm::ortho(0.0f, FrameWork::getWindowContext()->getSize().x, 0.0f, FrameWork::getWindowContext()->getSize().y));
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
for (std::vector<Character>::iterator itr = textData.begin(); itr != textData.end(); itr++)
|
178
|
+
|
179
|
+
{
|
180
|
+
|
181
|
+
#define SCALE 1.0f //文字の大きさ
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
float xpos = pos.x + itr->Bearing.x * SCALE;
|
186
|
+
|
187
|
+
float ypos = pos.y - (itr->Size.y - itr->Bearing.y) * SCALE;
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
float w = itr->Size.x * SCALE;
|
192
|
+
|
193
|
+
float h = itr->Size.y * SCALE;
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
float vertices[6][4] =
|
198
|
+
|
199
|
+
{
|
200
|
+
|
201
|
+
{ xpos, ypos + h, 0.0f, 0.0f },
|
202
|
+
|
203
|
+
{ xpos, ypos, 0.0f, 1.0f },
|
204
|
+
|
205
|
+
{ xpos + w, ypos, 1.0f, 1.0f },
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
{ xpos, ypos + h, 0.0f, 0.0f },
|
210
|
+
|
211
|
+
{ xpos + w, ypos, 1.0f, 1.0f },
|
212
|
+
|
213
|
+
{ xpos + w, ypos + h, 1.0f, 0.0f }
|
214
|
+
|
215
|
+
};
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
glBindTexture(GL_TEXTURE_2D, itr->textureID);
|
220
|
+
|
221
|
+
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
|
222
|
+
|
223
|
+
glDrawArrays(GL_TRIANGLES, 0, 6);
|
224
|
+
|
225
|
+
glBindTexture(GL_TEXTURE_2D, 0);
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
pos.x += ((itr->Advance >> 6) * SCALE); //次のグリフに進める
|
230
|
+
|
231
|
+
#undef SCALE
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
glBindVertexArray(0);
|
238
|
+
|
239
|
+
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
240
|
+
|
241
|
+
shader->setDisable(); //シェーダーを無効にする
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
250
|
+
|
251
|
+
glBindVertexArray(0);
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
|
258
|
+
|
39
259
|
|
40
260
|
|
41
261
|
```
|