質問編集履歴

2

再度文章を修正

2021/05/10 10:18

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,12 +1,14 @@
1
- Openglでfreetypeを使って日本語の文字を描画したいです。 提示サイトでは英語の文字表示をやり方が乗っている通り描画したのですが英語しか描画されません、日本語を描画させるにどういっ行為を行うのでしょうか? 色々調べましたわかりません。
1
+ Openglでfreetypeを使って日本語の文字を描画したいです。 提示サイトでは英語の文字表示をやり方が乗っているやり方は事前に用意したアルファベット文字を描画していますが日本語ははずです。提示コード//////コメント内部のfor文参考サイトを参考に
2
+
2
-
3
+ const char16_t型にキャストして日本語文字の描画を試みましたが字の枠しか描画されませんこれはどうしたらいいのでしょうか?
4
+
5
+
6
+
7
+
8
+
9
+
10
+
3
-
11
+ ![イメージ説明](3a3c2811ee4c418acc232cc701b82478.png)
4
-
5
-
6
-
7
-
8
-
9
-
10
12
 
11
13
  参考サイト: http://blendgimper.hatenablog.jp/entry/2016/01/01/074615
12
14
 
@@ -130,31 +132,89 @@
130
132
 
131
133
 
132
134
 
135
+ //アルファブレンドを有効
136
+
137
+ glEnable(GL_BLEND);
138
+
139
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
140
+
141
+ }
142
+
143
+
144
+
145
+ void FrameWork::Text::Draw(glm::vec2 pos,const char16_t* text,float scale, glm::vec3 color)
146
+
147
+ {
148
+
149
+ setEnable(); //シェーダーを有効にする
150
+
151
+
152
+
153
+ pos.y = windowContext->getSize().y - pos.y - charSize;
154
+
155
+
156
+
157
+ //テクスチャをアクティブ
158
+
159
+ glActiveTexture(GL_TEXTURE0);
160
+
161
+ glBindVertexArray(vao);
162
+
163
+
164
+
133
- /*
165
+ //Unform
166
+
134
-
167
+ setUniform3f("textColor",color);
168
+
169
+ setUniformMatrix4fv("uViewProjection", glm::ortho(0.0f, windowContext->getSize().x, 0.0f, windowContext->getSize().y));
170
+
171
+ ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
172
+
135
- for (unsigned char c = 0; c < 128; c++)
173
+ for (int i = 0; text[i] != '\0'; i++)
136
174
 
137
175
  {
138
176
 
177
+
178
+
179
+ unsigned int texture = 0;
180
+
181
+
182
+
139
183
  // load character glyph
140
184
 
141
- if (FT_Load_Char(face, c, FT_LOAD_RENDER))
185
+ FT_Load_Glyph(face, FT_Get_Char_Index(face, (char16_t)text[i]), FT_LOAD_RENDER);
142
-
143
- {
186
+
144
-
187
+
188
+
189
+
190
+
145
- std::cout << "ERROR::FREETYTPE: Failed to load Glyph" << std::endl;
191
+ // now store character for later use
192
+
146
-
193
+ Character ch = {
194
+
147
- continue;
195
+ texture,
196
+
148
-
197
+ glm::ivec2(face->glyph->bitmap.width, face->glyph->bitmap.rows),
198
+
199
+ glm::ivec2(face->glyph->bitmap_left, face->glyph->bitmap_top),
200
+
201
+ (unsigned int)face->glyph->advance.x
202
+
203
+
204
+
149
- }
205
+ };
206
+
207
+
208
+
209
+
150
210
 
151
211
  // generate texture
152
212
 
153
- unsigned int texture;
154
-
155
- glGenTextures(1, &texture);
213
+ glGenTextures(1, &ch.textureID);
156
-
214
+
157
- glBindTexture(GL_TEXTURE_2D, texture);
215
+ glBindTexture(GL_TEXTURE_2D, ch.textureID);
216
+
217
+
158
218
 
159
219
  glTexImage2D(
160
220
 
@@ -190,338 +250,100 @@
190
250
 
191
251
  // now store character for later use
192
252
 
253
+
254
+
255
+
256
+
257
+
258
+
259
+ float xpos = pos.x + ch.Bearing.x * scale;
260
+
261
+ float ypos = pos.y - (ch.Size.y - ch.Bearing.y) * scale;
262
+
263
+
264
+
265
+ float w = ch.Size.x * scale;
266
+
267
+ float h = ch.Size.y * scale;
268
+
269
+ // update VBO for each character
270
+
193
- Character character = {
271
+ float vertices[6][4] = {
194
-
195
- texture,
272
+
196
-
197
- glm::ivec2(face->glyph->bitmap.width, face->glyph->bitmap.rows),
198
-
199
- glm::ivec2(face->glyph->bitmap_left, face->glyph->bitmap_top),
200
-
201
- (unsigned int)face->glyph->advance.x
273
+ { xpos, ypos + h, 0.0f, 0.0f },
274
+
202
-
275
+ { xpos, ypos, 0.0f, 1.0f },
276
+
203
-
277
+ { xpos + w, ypos, 1.0f, 1.0f },
278
+
279
+
280
+
281
+ { xpos, ypos + h, 0.0f, 0.0f },
282
+
283
+ { xpos + w, ypos, 1.0f, 1.0f },
284
+
285
+ { xpos + w, ypos + h, 1.0f, 0.0f }
204
286
 
205
287
  };
206
288
 
207
-
289
+ // render glyph texture over quad
290
+
208
-
291
+ // update content of VBO memory
292
+
293
+ glBindBuffer(GL_ARRAY_BUFFER, vbo);
294
+
209
- Characters.insert(std::pair<char, Character>(c, character));
295
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
296
+
210
-
297
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
298
+
299
+
300
+
211
-
301
+ // render quad
302
+
212
-
303
+ glDrawArrays(GL_TRIANGLES, 0, 6);
304
+
305
+
306
+
307
+
308
+
309
+
310
+
311
+ // now advance cursors for next glyph (note that advance is number of 1/64 pixels)
312
+
313
+ pos.x += ((ch.Advance >> 6) * scale); // bitshift by 6 to get value in pixels (2^6 = 64)
314
+
213
- }
315
+ }
214
-
316
+
215
- */
317
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
216
-
217
-
218
-
219
-
220
-
221
-
222
-
223
-
224
-
318
+
225
- //アルファブレンドを有効
319
+ glBindVertexArray(0);
226
-
320
+
227
- glEnable(GL_BLEND);
321
+ glBindTexture(GL_TEXTURE_2D, 0);
228
-
322
+
229
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
323
+ setDisable(); //シェーダーを無効にする
230
324
 
231
325
  }
232
326
 
233
327
 
234
328
 
329
+
330
+
331
+
332
+
235
- void FrameWork::Text::Draw(glm::vec2 pos,std::string text,float scale, glm::vec3 color)
333
+ FrameWork::Text::~Text()
236
334
 
237
335
  {
238
336
 
239
- setEnable(); //シェーダーを有効にする
240
-
241
-
242
-
243
- pos.y = windowContext->getSize().y - pos.y - charSize;
244
-
245
-
246
-
247
- //テクスチャをアクティブ
248
-
249
- glActiveTexture(GL_TEXTURE0);
250
-
251
- glBindVertexArray(vao);
252
-
253
-
254
-
255
- //Unform
337
+ //グリフ解放
256
-
257
- setUniform3f("textColor",color);
338
+
258
-
259
- setUniformMatrix4fv("uViewProjection", glm::ortho(0.0f, windowContext->getSize().x, 0.0f, windowContext->getSize().y));
260
-
261
-
262
-
263
-
264
-
265
-
266
-
267
-
268
-
269
-
270
-
271
-
272
-
273
- std::string::const_iterator c;
274
-
275
- for (c = text.begin(); c != text.end(); c++)
276
-
277
- {
278
-
279
-
280
-
281
- unsigned int texture = 0;
339
+ FT_Done_Face(face);
282
-
283
-
284
-
285
- // load character glyph
340
+
286
-
287
- FT_Load_Glyph(face, FT_Get_Char_Index(face, *c), FT_LOAD_RENDER);
288
-
289
-
290
-
291
-
292
-
293
- // now store character for later use
294
-
295
- Character ch = {
296
-
297
- texture,
298
-
299
- glm::ivec2(face->glyph->bitmap.width, face->glyph->bitmap.rows),
300
-
301
- glm::ivec2(face->glyph->bitmap_left, face->glyph->bitmap_top),
302
-
303
- (unsigned int)face->glyph->advance.x
304
-
305
-
306
-
307
- };
308
-
309
-
310
-
311
-
312
-
313
- // generate texture
314
-
315
- glGenTextures(1, &texture);
316
-
317
- glBindTexture(GL_TEXTURE_2D, texture);
318
-
319
- glTexImage2D(
320
-
321
- GL_TEXTURE_2D,
322
-
323
- 0,
324
-
325
- GL_RED,
326
-
327
- face->glyph->bitmap.width,
328
-
329
- face->glyph->bitmap.rows,
330
-
331
- 0,
332
-
333
- GL_RED,
334
-
335
- GL_UNSIGNED_BYTE,
336
-
337
- face->glyph->bitmap.buffer
338
-
339
- );
340
-
341
- // set texture options
342
-
343
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
344
-
345
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
346
-
347
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
348
-
349
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
350
-
351
- // now store character for later use
352
-
353
-
354
-
355
-
356
-
357
-
358
-
359
- float xpos = pos.x + ch.Bearing.x * scale;
360
-
361
- float ypos = pos.y - (ch.Size.y - ch.Bearing.y) * scale;
362
-
363
-
364
-
365
- float w = ch.Size.x * scale;
366
-
367
- float h = ch.Size.y * scale;
368
-
369
- // update VBO for each character
370
-
371
- float vertices[6][4] = {
372
-
373
- { xpos, ypos + h, 0.0f, 0.0f },
374
-
375
- { xpos, ypos, 0.0f, 1.0f },
376
-
377
- { xpos + w, ypos, 1.0f, 1.0f },
378
-
379
-
380
-
381
- { xpos, ypos + h, 0.0f, 0.0f },
382
-
383
- { xpos + w, ypos, 1.0f, 1.0f },
384
-
385
- { xpos + w, ypos + h, 1.0f, 0.0f }
386
-
387
- };
388
-
389
- // render glyph texture over quad
390
-
391
- glBindTexture(GL_TEXTURE_2D, ch.textureID);
392
-
393
- // update content of VBO memory
394
-
395
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
396
-
397
- glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
398
-
399
- glBindBuffer(GL_ARRAY_BUFFER, 0);
400
-
401
-
402
-
403
- // render quad
404
-
405
- glDrawArrays(GL_TRIANGLES, 0, 6);
406
-
407
-
408
-
409
-
410
-
411
-
412
-
413
- // now advance cursors for next glyph (note that advance is number of 1/64 pixels)
414
-
415
- pos.x += ((ch.Advance >> 6) * scale); // bitshift by 6 to get value in pixels (2^6 = 64)
416
-
417
- }
418
-
419
-
420
-
421
- /*
422
-
423
- // iterate through all characters
424
-
425
- std::string::const_iterator c;
426
-
427
- for (c = text.begin(); c != text.end(); c++)
428
-
429
- {
430
-
431
- Character ch = Characters[*c];
432
-
433
-
434
-
435
-
436
-
437
- float xpos = pos.x + ch.Bearing.x * scale;
438
-
439
- float ypos = pos.y - (ch.Size.y - ch.Bearing.y) * scale;
440
-
441
-
442
-
443
- float w = ch.Size.x * scale;
444
-
445
- float h = ch.Size.y * scale;
446
-
447
- // update VBO for each character
448
-
449
- float vertices[6][4] = {
450
-
451
- { xpos, ypos + h, 0.0f, 0.0f },
452
-
453
- { xpos, ypos, 0.0f, 1.0f },
454
-
455
- { xpos + w, ypos, 1.0f, 1.0f },
456
-
457
-
458
-
459
- { xpos, ypos + h, 0.0f, 0.0f },
460
-
461
- { xpos + w, ypos, 1.0f, 1.0f },
462
-
463
- { xpos + w, ypos + h, 1.0f, 0.0f }
464
-
465
- };
466
-
467
- // render glyph texture over quad
468
-
469
- glBindTexture(GL_TEXTURE_2D, ch.textureID);
470
-
471
- // update content of VBO memory
472
-
473
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
474
-
475
- glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
476
-
477
- glBindBuffer(GL_ARRAY_BUFFER, 0);
478
-
479
- // render quad
480
-
481
- glDrawArrays(GL_TRIANGLES, 0, 6);
482
-
483
-
484
-
485
- // now advance cursors for next glyph (note that advance is number of 1/64 pixels)
486
-
487
- pos.x += ((ch.Advance >> 6) * scale); // bitshift by 6 to get value in pixels (2^6 = 64)
488
-
489
-
490
-
491
- }
492
-
493
- */
494
-
495
-
496
-
497
- glBindVertexArray(0);
341
+ FT_Done_FreeType(ft);
498
-
499
- glBindTexture(GL_TEXTURE_2D, 0);
342
+
500
-
501
- setDisable(); //シェーダーを無効にする
343
+
502
344
 
503
345
  }
504
346
 
505
347
 
506
348
 
507
-
508
-
509
-
510
-
511
- FrameWork::Text::~Text()
512
-
513
- {
514
-
515
- //グリフ解放
516
-
517
- FT_Done_Face(face);
518
-
519
- FT_Done_FreeType(ft);
520
-
521
-
522
-
523
- }
524
-
525
-
526
-
527
349
  ```

1

提示コードを修正

2021/05/10 10:18

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -88,7 +88,7 @@
88
88
 
89
89
  //初期化
90
90
 
91
- FT_Library ft;
91
+
92
92
 
93
93
  if (FT_Init_FreeType(&ft) != 0)
94
94
 
@@ -104,11 +104,9 @@
104
104
 
105
105
  //フェイス作成
106
106
 
107
- FT_Face face;
107
+
108
-
109
-
110
-
108
+
111
- if (FT_New_Face(ft, "Font/ariali.ttf", 0, &face) != 0)
109
+ if (FT_New_Face(ft, "C:\Windows\Fonts\meiryo.ttc", 0, &face) != 0)
112
110
 
113
111
  {
114
112
 
@@ -132,6 +130,8 @@
132
130
 
133
131
 
134
132
 
133
+ /*
134
+
135
135
  for (unsigned char c = 0; c < 128; c++)
136
136
 
137
137
  {
@@ -204,17 +204,313 @@
204
204
 
205
205
  };
206
206
 
207
+
208
+
207
209
  Characters.insert(std::pair<char, Character>(c, character));
208
210
 
209
- }
210
-
211
-
212
-
213
-
214
-
215
-
216
-
217
-
211
+
212
+
213
+ }
214
+
215
+ */
216
+
217
+
218
+
219
+
220
+
221
+
222
+
223
+
224
+
225
+ //アルファブレンドを有効
226
+
227
+ glEnable(GL_BLEND);
228
+
229
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
230
+
231
+ }
232
+
233
+
234
+
235
+ void FrameWork::Text::Draw(glm::vec2 pos,std::string text,float scale, glm::vec3 color)
236
+
237
+ {
238
+
239
+ setEnable(); //シェーダーを有効にする
240
+
241
+
242
+
243
+ pos.y = windowContext->getSize().y - pos.y - charSize;
244
+
245
+
246
+
247
+ //テクスチャをアクティブ
248
+
249
+ glActiveTexture(GL_TEXTURE0);
250
+
251
+ glBindVertexArray(vao);
252
+
253
+
254
+
255
+ //Unform
256
+
257
+ setUniform3f("textColor",color);
258
+
259
+ setUniformMatrix4fv("uViewProjection", glm::ortho(0.0f, windowContext->getSize().x, 0.0f, windowContext->getSize().y));
260
+
261
+
262
+
263
+
264
+
265
+
266
+
267
+
268
+
269
+
270
+
271
+
272
+
273
+ std::string::const_iterator c;
274
+
275
+ for (c = text.begin(); c != text.end(); c++)
276
+
277
+ {
278
+
279
+
280
+
281
+ unsigned int texture = 0;
282
+
283
+
284
+
285
+ // load character glyph
286
+
287
+ FT_Load_Glyph(face, FT_Get_Char_Index(face, *c), FT_LOAD_RENDER);
288
+
289
+
290
+
291
+
292
+
293
+ // now store character for later use
294
+
295
+ Character ch = {
296
+
297
+ texture,
298
+
299
+ glm::ivec2(face->glyph->bitmap.width, face->glyph->bitmap.rows),
300
+
301
+ glm::ivec2(face->glyph->bitmap_left, face->glyph->bitmap_top),
302
+
303
+ (unsigned int)face->glyph->advance.x
304
+
305
+
306
+
307
+ };
308
+
309
+
310
+
311
+
312
+
313
+ // generate texture
314
+
315
+ glGenTextures(1, &texture);
316
+
317
+ glBindTexture(GL_TEXTURE_2D, texture);
318
+
319
+ glTexImage2D(
320
+
321
+ GL_TEXTURE_2D,
322
+
323
+ 0,
324
+
325
+ GL_RED,
326
+
327
+ face->glyph->bitmap.width,
328
+
329
+ face->glyph->bitmap.rows,
330
+
331
+ 0,
332
+
333
+ GL_RED,
334
+
335
+ GL_UNSIGNED_BYTE,
336
+
337
+ face->glyph->bitmap.buffer
338
+
339
+ );
340
+
341
+ // set texture options
342
+
343
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
344
+
345
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
346
+
347
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
348
+
349
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
350
+
351
+ // now store character for later use
352
+
353
+
354
+
355
+
356
+
357
+
358
+
359
+ float xpos = pos.x + ch.Bearing.x * scale;
360
+
361
+ float ypos = pos.y - (ch.Size.y - ch.Bearing.y) * scale;
362
+
363
+
364
+
365
+ float w = ch.Size.x * scale;
366
+
367
+ float h = ch.Size.y * scale;
368
+
369
+ // update VBO for each character
370
+
371
+ float vertices[6][4] = {
372
+
373
+ { xpos, ypos + h, 0.0f, 0.0f },
374
+
375
+ { xpos, ypos, 0.0f, 1.0f },
376
+
377
+ { xpos + w, ypos, 1.0f, 1.0f },
378
+
379
+
380
+
381
+ { xpos, ypos + h, 0.0f, 0.0f },
382
+
383
+ { xpos + w, ypos, 1.0f, 1.0f },
384
+
385
+ { xpos + w, ypos + h, 1.0f, 0.0f }
386
+
387
+ };
388
+
389
+ // render glyph texture over quad
390
+
391
+ glBindTexture(GL_TEXTURE_2D, ch.textureID);
392
+
393
+ // update content of VBO memory
394
+
395
+ glBindBuffer(GL_ARRAY_BUFFER, vbo);
396
+
397
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
398
+
399
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
400
+
401
+
402
+
403
+ // render quad
404
+
405
+ glDrawArrays(GL_TRIANGLES, 0, 6);
406
+
407
+
408
+
409
+
410
+
411
+
412
+
413
+ // now advance cursors for next glyph (note that advance is number of 1/64 pixels)
414
+
415
+ pos.x += ((ch.Advance >> 6) * scale); // bitshift by 6 to get value in pixels (2^6 = 64)
416
+
417
+ }
418
+
419
+
420
+
421
+ /*
422
+
423
+ // iterate through all characters
424
+
425
+ std::string::const_iterator c;
426
+
427
+ for (c = text.begin(); c != text.end(); c++)
428
+
429
+ {
430
+
431
+ Character ch = Characters[*c];
432
+
433
+
434
+
435
+
436
+
437
+ float xpos = pos.x + ch.Bearing.x * scale;
438
+
439
+ float ypos = pos.y - (ch.Size.y - ch.Bearing.y) * scale;
440
+
441
+
442
+
443
+ float w = ch.Size.x * scale;
444
+
445
+ float h = ch.Size.y * scale;
446
+
447
+ // update VBO for each character
448
+
449
+ float vertices[6][4] = {
450
+
451
+ { xpos, ypos + h, 0.0f, 0.0f },
452
+
453
+ { xpos, ypos, 0.0f, 1.0f },
454
+
455
+ { xpos + w, ypos, 1.0f, 1.0f },
456
+
457
+
458
+
459
+ { xpos, ypos + h, 0.0f, 0.0f },
460
+
461
+ { xpos + w, ypos, 1.0f, 1.0f },
462
+
463
+ { xpos + w, ypos + h, 1.0f, 0.0f }
464
+
465
+ };
466
+
467
+ // render glyph texture over quad
468
+
469
+ glBindTexture(GL_TEXTURE_2D, ch.textureID);
470
+
471
+ // update content of VBO memory
472
+
473
+ glBindBuffer(GL_ARRAY_BUFFER, vbo);
474
+
475
+ glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
476
+
477
+ glBindBuffer(GL_ARRAY_BUFFER, 0);
478
+
479
+ // render quad
480
+
481
+ glDrawArrays(GL_TRIANGLES, 0, 6);
482
+
483
+
484
+
485
+ // now advance cursors for next glyph (note that advance is number of 1/64 pixels)
486
+
487
+ pos.x += ((ch.Advance >> 6) * scale); // bitshift by 6 to get value in pixels (2^6 = 64)
488
+
489
+
490
+
491
+ }
492
+
493
+ */
494
+
495
+
496
+
497
+ glBindVertexArray(0);
498
+
499
+ glBindTexture(GL_TEXTURE_2D, 0);
500
+
501
+ setDisable(); //シェーダーを無効にする
502
+
503
+ }
504
+
505
+
506
+
507
+
508
+
509
+
510
+
511
+ FrameWork::Text::~Text()
512
+
513
+ {
218
514
 
219
515
  //グリフ解放
220
516
 
@@ -222,146 +518,10 @@
222
518
 
223
519
  FT_Done_FreeType(ft);
224
520
 
225
-
226
-
227
- //アルファブレンドを有効
521
+
228
-
229
- glEnable(GL_BLEND);
230
-
231
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
232
522
 
233
523
  }
234
524
 
235
525
 
236
526
 
237
- void FrameWork::Text::Draw(glm::vec2 pos,std::string text,float scale, glm::vec3 color)
238
-
239
- {
240
-
241
- setEnable(); //シェーダーを有効にする
242
-
243
-
244
-
245
- pos.y = windowContext->getSize().y - pos.y - charSize;
246
-
247
-
248
-
249
- //テクスチャをアクティブ
250
-
251
- glActiveTexture(GL_TEXTURE0);
252
-
253
- glBindVertexArray(vao);
254
-
255
-
256
-
257
- //Unform
258
-
259
- setUniform3f("textColor",color);
260
-
261
-
262
-
263
- // glm::ortho(0.0f, 800.0f, 0.0f, 600.0f);
264
-
265
- setUniformMatrix4fv("uViewProjection", glm::ortho(0.0f, windowContext->getSize().x, 0.0f, windowContext->getSize().y));
266
-
267
-
268
-
269
- // iterate through all characters
270
-
271
- std::string::const_iterator c;
272
-
273
- for (c = text.begin(); c != text.end(); c++)
274
-
275
- {
276
-
277
- Character ch = Characters[*c];
278
-
279
-
280
-
281
-
282
-
283
- float xpos = pos.x + ch.Bearing.x * scale;
284
-
285
- float ypos = pos.y - (ch.Size.y - ch.Bearing.y) * scale;
286
-
287
-
288
-
289
- float w = ch.Size.x * scale;
290
-
291
- float h = ch.Size.y * scale;
292
-
293
- // update VBO for each character
294
-
295
- float vertices[6][4] = {
296
-
297
- { xpos, ypos + h, 0.0f, 0.0f },
298
-
299
- { xpos, ypos, 0.0f, 1.0f },
300
-
301
- { xpos + w, ypos, 1.0f, 1.0f },
302
-
303
-
304
-
305
- { xpos, ypos + h, 0.0f, 0.0f },
306
-
307
- { xpos + w, ypos, 1.0f, 1.0f },
308
-
309
- { xpos + w, ypos + h, 1.0f, 0.0f }
310
-
311
- };
312
-
313
- // render glyph texture over quad
314
-
315
- glBindTexture(GL_TEXTURE_2D, ch.textureID);
316
-
317
- // update content of VBO memory
318
-
319
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
320
-
321
- glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
322
-
323
- glBindBuffer(GL_ARRAY_BUFFER, 0);
324
-
325
- // render quad
326
-
327
- glDrawArrays(GL_TRIANGLES, 0, 6);
328
-
329
-
330
-
331
- // now advance cursors for next glyph (note that advance is number of 1/64 pixels)
332
-
333
- pos.x += ((ch.Advance >> 6) * scale); // bitshift by 6 to get value in pixels (2^6 = 64)
334
-
335
-
336
-
337
- }
338
-
339
-
340
-
341
-
342
-
343
- glBindVertexArray(0);
344
-
345
- glBindTexture(GL_TEXTURE_2D, 0);
346
-
347
- setDisable(); //シェーダーを無効にする
348
-
349
- }
350
-
351
-
352
-
353
-
354
-
355
-
356
-
357
- FrameWork::Text::~Text()
358
-
359
- {
360
-
361
-
362
-
363
- }
364
-
365
-
366
-
367
527
  ```