質問編集履歴

1

文章を修正しました。

2021/06/26 04:14

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  提示コードは参考サイトのコードですが FT_Errrr_String();関数を実行しても例外エラーが出るだけしたのでやり方がわかりません。
4
4
 
5
+ また参考サイト3のコードを入力して実装を試みたのですがエラーが出てコンパイルできません。
6
+
7
+
8
+
9
+ エラー[ 重大度レベル コード 説明 プロジェクト ファイル 行 抑制状態
10
+
11
+ エラー LNK1169 1 つ以上の複数回定義されているシンボルが見つかりました。 FrameWork C:\Users\yw325\Desktop\ActionGame\FrameWork\x64\Debug\FrameWork.exe 1
12
+
13
+ ]
14
+
5
15
 
6
16
 
7
17
 
@@ -10,6 +20,10 @@
10
20
 
11
21
  参考サイト2: https://www.freetype.org/freetype2/docs/reference/ft2-error_code_values.html
12
22
 
23
+ 参考サイト3: https://stackoverflow.com/questions/31161284/how-can-i-get-the-corresponding-error-string-from-an-ft-error-code
24
+
25
+
26
+
13
27
 
14
28
 
15
29
 
@@ -51,3 +65,363 @@
51
65
  FT_Error_String( FT_Error error_code );
52
66
 
53
67
  ```
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+ ```cpp
76
+
77
+ #ifndef ___TEXT_HPP_
78
+
79
+ #define ___TEXT_HPP_
80
+
81
+ #include "Transform_2D.hpp"
82
+
83
+ #include "Help.hpp"
84
+
85
+ #include <vector>
86
+
87
+ #include <format>
88
+
89
+
90
+
91
+ #include "glm/glm.hpp"
92
+
93
+ #include <map>
94
+
95
+ #include "ft2build.h"
96
+
97
+ #include FT_FREETYPE_H
98
+
99
+
100
+
101
+ /*#########################################################################
102
+
103
+ # 文字描画クラス
104
+
105
+
106
+
107
+ 説明
108
+
109
+ 文字を描画する
110
+
111
+ ###########################################################################*/
112
+
113
+
114
+
115
+
116
+
117
+
118
+
119
+
120
+
121
+ #define DEFAULT_FONT "Font/SourceHanCodeJP.ttc"
122
+
123
+
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+ namespace FrameWork
132
+
133
+ {
134
+
135
+ /////////////////////////////////////////////////////////////////////
136
+
137
+ const char* getError(FT_Error err)
138
+
139
+ {
140
+
141
+ #undef FTERRORS_H_
142
+
143
+ #define FT_ERRORDEF( e, v, s ) case e: return s;
144
+
145
+ #define FT_ERROR_START_LIST switch (err) {
146
+
147
+ #define FT_ERROR_END_LIST }
148
+
149
+ #include FT_ERRORS_H
150
+
151
+ return "(Unknown error)";
152
+
153
+ }
154
+
155
+ ////////////////////////////////////////////////////////////////////
156
+
157
+ class Window;
158
+
159
+
160
+
161
+ class Text : protected FrameWork::Transform_2D
162
+
163
+ {
164
+
165
+
166
+
167
+ public:
168
+
169
+
170
+
171
+ Text(); //コンストラクタ
172
+
173
+ ~Text(); //デストラクタ
174
+
175
+
176
+
177
+
178
+
179
+ glm::lowp_i16vec2 getTextSize(const unsigned int num); //文字列のサイズ取得
180
+
181
+
182
+
183
+ // ##################################### 固定長文字列 文字列 設定 #####################################
184
+
185
+ template <typename... Args>
186
+
187
+ void setString(const char* fontName, unsigned short pixelSize, const glm::vec4 color, const char* text, const Args& ... args)
188
+
189
+ {
190
+
191
+ //マルチバイト文字をワイド文字変換
192
+
193
+ if (text != NULL)
194
+
195
+ {
196
+
197
+ std::string str = std::format(text, args...);
198
+
199
+ CharacterString character;
200
+
201
+
202
+
203
+ //フォント指定 NULLの場合は既定のフォントを設定
204
+
205
+ if (fontName == NULL)
206
+
207
+ {
208
+
209
+ character.fontName = std::string(DEFAULT_FONT);
210
+
211
+ }
212
+
213
+ else
214
+
215
+ {
216
+
217
+ character.fontName = std::string(fontName);
218
+
219
+ }
220
+
221
+
222
+
223
+ //ピクセルサイズが1以下の場合
224
+
225
+ if (pixelSize <= 0)
226
+
227
+ {
228
+
229
+ std::cerr << "Text ピクセルサイズ: " << pixelSize << std::endl;
230
+
231
+ assert(0);
232
+
233
+ }
234
+
235
+
236
+
237
+ character.pixelSize = pixelSize; //ピクセルサイズ
238
+
239
+ character.color = color; //カラー
240
+
241
+
242
+
243
+ setFontName(character.fontName.c_str(), character.face); //フォント設定
244
+
245
+ setPixelSize(character.pixelSize, character.face); //ピクセルサイズ設定
246
+
247
+
248
+
249
+ character.text = getTexture(getWchar_t(str.c_str()), character.fontName.c_str(), character.pixelSize, character.face); //テクスチャ生成
250
+
251
+
252
+
253
+ setTextSize(character.textSize, character.text); //文字列サイズを設定
254
+
255
+ characterText->push_back(character); //文字列を格納
256
+
257
+ }
258
+
259
+ else
260
+
261
+ {
262
+
263
+ std::cerr <<"Text テキストがNULLです。"<< std::endl;
264
+
265
+ assert(0);
266
+
267
+ }
268
+
269
+
270
+
271
+ }
272
+
273
+
274
+
275
+ // ##################################### 固定長文字列 文字列 再設定 #####################################
276
+
277
+ template <typename... Args>
278
+
279
+ void ResetString(unsigned int num ,const char* fontName, unsigned short pixelSize, const glm::vec4 color, const char* text, const Args& ... args)
280
+
281
+ {
282
+
283
+ if (text != NULL)
284
+
285
+ {
286
+
287
+ //マルチバイト文字をワイド文字変換
288
+
289
+ std::string str = std::format(text, args...);
290
+
291
+
292
+
293
+ //フォント、ピクセルサイズ、カラー どれかが違うとき
294
+
295
+ if ( (characterText->at(num).fontName != std::string(fontName)) || (characterText->at(num).pixelSize != pixelSize) || (characterText->at(num).color != color) )
296
+
297
+ {
298
+
299
+ characterText->at(num).fontName = std::string(fontName); //フォント
300
+
301
+ characterText->at(num).pixelSize = pixelSize; //ピクセルサイズ
302
+
303
+ characterText->at(num).color = color; //カラー
304
+
305
+
306
+
307
+ setFontName(characterText->at(num).fontName.c_str(), characterText->at(num).face); //フォント設定
308
+
309
+ setPixelSize(characterText->at(num).pixelSize, characterText->at(num).face); //ピクセルサイズ設定
310
+
311
+
312
+
313
+ characterText->at(num).text = getTexture(getWchar_t(str.c_str()), characterText->at(num).fontName.c_str(), characterText->at(num).pixelSize, characterText->at(num).face); //テクスチャ生成
314
+
315
+ setTextSize(characterText->at(num).textSize, characterText->at(num).text); //文字列サイズを設定
316
+
317
+ }
318
+
319
+ else if (str != getString(characterText->at(num).text))
320
+
321
+ {
322
+
323
+ std::cout << "あああ" << std::endl;
324
+
325
+ FixText(characterText->at(num),getWchar_t(str.c_str()));
326
+
327
+ std::cout << "いいい" << std::endl;
328
+
329
+
330
+
331
+ }
332
+
333
+ }
334
+
335
+ }
336
+
337
+ void DrawString(const glm::vec2 pos,const unsigned short num); //固定長文字列 文字列 描画
338
+
339
+
340
+
341
+ private:
342
+
343
+
344
+
345
+ //文字構造体
346
+
347
+ struct Character
348
+
349
+ {
350
+
351
+ unsigned int textureID; //グリフのテクスチャID
352
+
353
+ glm::ivec2 size; //グリフサイズ
354
+
355
+ glm::ivec2 bearing; //グリフのベースライン
356
+
357
+ unsigned int advance; //次のグリフまでのオフセット
358
+
359
+ wchar_t character; //文字
360
+
361
+ };
362
+
363
+
364
+
365
+ //文字列構造体
366
+
367
+ struct CharacterString
368
+
369
+ {
370
+
371
+ std::vector<Character> text; //文字列
372
+
373
+ glm::vec4 color; //描画色
374
+
375
+ glm::lowp_i16vec2 textSize; //文字列のサイズ
376
+
377
+ unsigned short pixelSize; //ピクセルサイズ
378
+
379
+ std::string fontName; //フォント名
380
+
381
+ FT_Face face; //フェイス
382
+
383
+ };
384
+
385
+
386
+
387
+ std::shared_ptr<std::vector<CharacterString>> characterText; //描画文字
388
+
389
+
390
+
391
+ std::vector<Character> getTexture(const std::vector<wchar_t>& text, const char* fontName, const unsigned short& fontSize, FT_Face& face); //テクスチャを生成
392
+
393
+ std::vector<wchar_t> getWchar_t(const char* str); //wchar_t型の文字列を取得
394
+
395
+ std::string getString(std::vector<Character>& charcter); //string型データを取得
396
+
397
+ void setTextSize(glm::lowp_i16vec2 &size,const std::vector<Character> &character); //文字列のサイズを取得
398
+
399
+ void RenderCharacter(glm::vec2 pos, const unsigned short& FontSize, const glm::vec4 &color, const std::vector<Character> &character); //文字列を描画
400
+
401
+ void FixText(CharacterString &character, const std::vector<wchar_t> newText); //文字列を修正
402
+
403
+
404
+
405
+ void setPixelSize(unsigned short n,FT_Face &face); //ピクセルサイズ設定
406
+
407
+ void setFontName(const char* str,FT_Face& face); //フォント設定
408
+
409
+
410
+
411
+
412
+
413
+ FT_Library ft; //freetype
414
+
415
+
416
+
417
+
418
+
419
+
420
+
421
+ };
422
+
423
+ };
424
+
425
+ #endif
426
+
427
+ ```