teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

文章を編集しました。

2021/05/19 12:33

投稿

退会済みユーザー
title CHANGED
@@ -1,1 +1,1 @@
1
- mbrtoc16()関数を使ってchar型配列文字列をchar16_t型変数に格納したい。
1
+ char型配列文字列をchar16_t型変数に格納したい。
body CHANGED
File without changes

2

文章を修正

2021/05/19 12:32

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,112 +1,34 @@
1
- 提示コードの/////コメント内部のコードですが const char型配列で来た文字をchar16_t型配列変数に代入したいのですがその先のforでアクセスエラー発生しす。エラーコード-1です。なぜアクセスエラーが発生するのでしょうか?
1
+ 提示コードの/////コメント内部のコードですが const char型配列で来た文字をchar16_t型配列変数に代入したいのですが文格納されせんこれはなぜでしょうか?戻り値は1です。
2
2
 
3
- エラー[ エンコード・エラー発生した場合 (次の n または それよりも少バイト数で完全で有効なマルチバイト文字の作成に使用できいとき)EILSEQ マクロの値errno保管され、変換状態は未指定です。 ]
3
+ エラー[ 1カウント されます。次の カウント を含むか、有効マルチバイト文字を入力します。 返れる値は、マルチバイト文字を完するの必要バイト数ですWchar が null ポインターでない場合、それに相当するワイド文字wchar格納されす。 ]
4
4
 
5
5
  参考サイト1: https://www.ibm.com/docs/ja/zos/2.3.0?topic=functions-mbrtoc16-convert-multibyte-character-char16-t-character
6
6
  参考サイト2: https://programming-place.net/ppp/contents/c/appendix/reference/mbrtoc16.html
7
7
 
8
8
 
9
+ ![イメージ説明](4409ad212b5828934ba02e78a98955ba.png)
9
10
 
10
-
11
11
  ```cpp
12
-
13
- void FrameWork::Text::Draw(glm::vec2 pos, const char* text, float scale, glm::vec3 color)
12
+ #include <iostream>
14
- //void FrameWork::Text::Draw(glm::vec2 pos, std::string text,float scale, glm::vec3 color)
13
+ int main()
15
14
  {
16
- setEnable(); //シェーダーを有効にする
15
+ const char text[] = "テスト";
17
16
 
18
- pos.y = windowContext->getSize().y - pos.y - charSize;
19
17
 
20
- //テクスチャをアクティブ
18
+ wchar_t txt[20] = { '\0' };
21
- glActiveTexture(GL_TEXTURE0);
22
- glBindVertexArray(vao);
23
19
 
24
- //Unform
25
- setUniform3f("textColor",color);
26
- setUniformMatrix4fv("uViewProjection", glm::ortho(0.0f, windowContext->getSize().x, 0.0f, windowContext->getSize().y));
27
-
28
- /////////////////////////////////////////////////////////////////////
29
- char16_t* txt = nullptr;
30
- int f = mbrtoc16(txt,text,strlen(text),nullptr);
20
+ int f = mbrtowc(txt, text, (size_t)strlen(text), nullptr);
31
21
  std::cout << f << std::endl;
32
- ////////////////////////////////////////////////////////////////////
22
+
33
-
23
+
34
24
  for (int i = 0; txt[i] != '\0'; i++)
35
25
  {
26
+ std::cout << txt[i] << std::endl;
27
+ }
36
28
 
37
- unsigned int texture = 0;
38
29
 
39
- // load character glyph
40
- FT_Load_Glyph(face, FT_Get_Char_Index(face, txt[i]), FT_LOAD_RENDER);
41
30
 
42
31
 
43
- // now store character for later use
44
- Character ch = {
45
- texture,
32
+ return 0;
46
- glm::ivec2(face->glyph->bitmap.width, face->glyph->bitmap.rows),
47
- glm::ivec2(face->glyph->bitmap_left, face->glyph->bitmap_top),
48
- (unsigned int)face->glyph->advance.x
49
-
50
- };
51
-
52
-
53
- // generate texture
54
- glGenTextures(1, &ch.textureID);
55
- glBindTexture(GL_TEXTURE_2D, ch.textureID);
56
-
57
- glTexImage2D(
58
- GL_TEXTURE_2D,
59
- 0,
60
- GL_RED,
61
- face->glyph->bitmap.width,
62
- face->glyph->bitmap.rows,
63
- 0,
64
- GL_RED,
65
- GL_UNSIGNED_BYTE,
66
- face->glyph->bitmap.buffer
67
- );
68
- // set texture options
69
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
70
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
71
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
72
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
73
- // now store character for later use
74
-
75
-
76
-
77
- float xpos = pos.x + ch.Bearing.x * scale;
78
- float ypos = pos.y - (ch.Size.y - ch.Bearing.y) * scale;
79
-
80
- float w = ch.Size.x * scale;
81
- float h = ch.Size.y * scale;
82
- // update VBO for each character
83
- float vertices[6][4] = {
84
- { xpos, ypos + h, 0.0f, 0.0f },
85
- { xpos, ypos, 0.0f, 1.0f },
86
- { xpos + w, ypos, 1.0f, 1.0f },
87
-
88
- { xpos, ypos + h, 0.0f, 0.0f },
89
- { xpos + w, ypos, 1.0f, 1.0f },
90
- { xpos + w, ypos + h, 1.0f, 0.0f }
91
- };
92
- // render glyph texture over quad
93
- // update content of VBO memory
94
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
95
- glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
96
- glBindBuffer(GL_ARRAY_BUFFER, 0);
97
-
98
- // render quad
99
- glDrawArrays(GL_TRIANGLES, 0, 6);
100
-
101
-
102
-
103
- // now advance cursors for next glyph (note that advance is number of 1/64 pixels)
104
- pos.x += ((ch.Advance >> 6) * scale); // bitshift by 6 to get value in pixels (2^6 = 64)
105
- }
106
-
107
- glBindVertexArray(0);
108
- glBindTexture(GL_TEXTURE_2D, 0);
109
- setDisable(); //シェーダーを無効にする
110
33
  }
111
-
112
34
  ```

1

文章を修正

2021/05/19 10:35

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,4 @@
1
- 提示コードの/////コメント内部のコードですが const char型配列で来た文字をchar16_t型配列変数に代入したいのですがどうすればいいのでしょか?その先のfor文でアクセスエラーが発生します。エラーコードは-1です。
1
+ 提示コードの/////コメント内部のコードですが const char型配列で来た文字をchar16_t型配列変数に代入したいのですがその先のfor文でアクセスエラーが発生します。エラーコードは-1です。なぜアクセスエラーが発生するのでしょうか?
2
2
 
3
3
  エラー[ エンコード・エラーが発生した場合 (次の n または それよりも少ないバイト数でさえ、完全で有効なマルチバイト文字の作成に使用できないとき)。EILSEQ マクロの値は errno に保管され、変換状態は未指定です。 ]
4
4
 
@@ -7,6 +7,7 @@
7
7
 
8
8
 
9
9
 
10
+
10
11
  ```cpp
11
12
 
12
13
  void FrameWork::Text::Draw(glm::vec2 pos, const char* text, float scale, glm::vec3 color)