glutBitmapString/glutStrokeString似乎需要常量无符号字符* - 字符串不起作用
glutBitmapString/glutStrokeString seem to require const unsigned char* - strings don't work
Ubuntu 11.04、G++、freeglut和GLUT。
我一点也不明白。这是我得到的错误:
whatever.cc:315:59: error: cannot convert ‘std::string’ to ‘const unsigned char*’ for argument ‘2’ to ‘void glutStrokeString(void*, const unsigned char*)’
如果我尝试glutBitmapString:
whatever.cc:315:59: error: cannot convert ‘std::string’ to ‘const unsigned char*’ for argument ‘2’ to ‘void glutBitmapString(void*, const unsigned char*)’
这是相关的代码(我想)。
scoreStream << "Score: " << score << " ";
scoreString = scoreStream.str();
// ...in another method:
glRasterPos2i(0, 0);
glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
glutBitmapString(GLUT_BITMAP_HELVETICA_18, scoreString);
这个答案告诉我它应该起作用,但它就是不起作用。
那些不想跳的人的报价:
// Draw blue text at screen coordinates (100, 120), where (0, 0) is the top-left of the
// screen in an 18-point Helvetica font
glRasterPos2i(100, 120);
glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
glutBitmapString(GLUT_BITMAP_HELVETICA_18, "text to render");
(另外,我试着在那里留下一个直接的字符串,比如"要渲染的文本"。没有骰子。)
whatever.cc:315:64: error: invalid conversion from ‘const char*’ to ‘const unsigned char*’
我很困惑。据我记忆所及,这是我关于SO的第一个问题,如果组合不太好,请道歉。我会提供任何我能提供的额外信息。
没有std::string
到char const*
的自动转换。但是,您可以使用std::string::c_str()
从std::string
中获取char const*
。
例如glutBitmapString(GLUT_BITMAP_HELVETICA_18, scoreString.c_str());
注意:您链接到的答案并没有说明您可以使用std::string
。它给出的示例(glutBitmapString(GLUT_BITMAP_HELVETICA_18, "text to render");
)使用字符串文字,它是char
的数组,而不是std::string
。
请记住OpenGL是一个C库,std::string
在C中不存在。
相关文章:
- 从矢量<无符号字符>转换为字符* 包括垃圾数据
- C++中无符号字符溢出
- 使用无符号字符数组有效存储内存
- 在 std::无符号字符的向量处存储 int 的十六进制表示形式
- 如何在保持其值的同时将 c++ 无符号字符变量转换为 char 变量
- 从 std::vector<无符号字符>切片中提取 int?
- 将无符号字符的向量存储在数组中会给我 std::bad_alloc
- 使用 fopen 打开 .pak 文件并使该文件应用于 const 无符号字符* (C++)
- 库特无符号字符
- 寻找一种更好的方法来表示无符号字符数组
- C++ 无符号字符 *{varName};-> C#
- 如何返回/复制unique_ptr<无符号字符[]>的值?
- 将浮点数转换为无符号字符数组并打印出来
- 在函数中返回无符号字符数组,但不返回指针
- 如何在 C/C++ 中将无符号字符*转换为无符号字符数组?
- 如何返回实际值(在我的例子中是无符号字符数组)而不是来自 C++ 函数的指针?
- 如何将带有十六进制值的 std::string 转换为 std::vector<无符号字符>
- 无符号字符打印其 ASCII 值
- 字符数组到无符号字符 *
- 是否可以在 c++ 中将两位数保存在无符号字符中