QUESTION (题)
I am trying to update the score after each iteration in my display.
(我试图在显示屏上的每次迭代后更新分数。)
How to do so with The following Function. (如何使用以下功能。)
Code (码)
void DrawString(int x, int y, int width, int height,const string &score,
float*color) {
float fx = (float)x / width * 2 - 1, fy = (float)y / height * 2 - 1;
DrawString(fx, fy, score, color);
}
// Function draws a string at given x,y coordinates
void DrawString(float x, float y, const string& score, float * color) {
glPushMatrix();
glLoadIdentity();
glDisable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
GLvoid *font_style = GLUT_BITMAP_TIMES_ROMAN_24;
if (color)
glColor3fv(color);
glRasterPos3f(x, y, 1);
// Draw the characters one by one
for (int i = 0; i < score.size(); i++)
glutBitmapCharacter(font_style, score[i]);
glPopMatrix();
}
int main(){
int score = 45;
DrawString(250,650,"score : " + score ,colors[RED]);
//EXAMPLE
score++;
ERROR (错误)
error: invalid operands of types 'const char [9]' and 'float' to binary 'operator+'
(错误:类型为'const char [9]'和'float'的类型为二进制'operator +'的无效操作数)
DrawString(250,650,"score : " + score,colors[RED]);
(DrawString(250,650,“ score:” + score,colors [RED]);)
ask by TechJuice02 translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…