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 << "\0";
scoreString = scoreStream.str();
// ...in another method:
glRasterPos2i(0, 0);
glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
glutBitmapString(GLUT_BITMAP_HELVETICA_18, scoreString);
This answer告诉我它应该工作,但事实并非如此.
引用那些不想跳的人:
// 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,“要呈现的文本”);)使用字符串文字,这是一个char数组,而不是std :: string.
请记住,OpenGL是一个C库,而C中不存在std :: string.