glutBitmapString有什么问题?

问题描述:

我究竟该如何使用glutBitmapString?

How exactly can I use glutBitmapString?

glColor4f(1.0, 1.0, 0.0, 1.0);
glRasterPos2i(200, 200);
glutBitmapString(GLUT_BITMAP_HELVETICA_18, "text");


VS08显示:无法将参数2从"const char [5]"转换为"const unsigned char *"

但是当我这样写的时候:


VS08 shows: cannot convert argument 2 from "const char [5]" to "const unsigned char *"

But when I write this:

glColor4f(1.0, 1.0, 0.0, 1.0);
glRasterPos2i(200, 200);
glutBitmapString(GLUT_BITMAP_HELVETICA_18, (const unsigned char *)"text");


我可以编译,但程序会自动关闭.
我该如何解决这个问题?
顺便说一句,为什么这个函数必须使用const unsigned char *,特别是unsigned?
提前谢谢!


这是我的显示功能的代码段:


I can get through compilation but the program will automatically close.
How can I fix this problem?
BTW, why this function must use const unsigned char*, particularly unsigned?
Thanks in advance!


here is the snippet of my display function:

void display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();//the display would be strange if this routine does not be called! reason is that the glTranslatef will be continuously accumulated!!!!!!!!!
	glTranslatef(0.0, 0.0, zoom);
	glRotatef(xrot, 1.0, 0.0, 0.0);
	glRotatef(yrot, 0.0, 1.0, 0.0);

	glBindTexture(GL_TEXTURE_2D, textureId[filter]);
	glBegin(GL_QUADS);
		glNormal3f(0.0, 0.0, 1.0);//front face
		glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, 1.0);
		glTexCoord2f(1.0, 0.0); glVertex3f(1.0, -1.0, 1.0);
		glTexCoord2f(1.0, 1.0); glVertex3f(1.0, 1.0, 1.0);
		glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0, 1.0);

		glNormal3f(0.0, 0.0, -1.0);//back face
		glTexCoord2f(0.0, 0.0); glVertex3f(1.0, -1.0, -1.0);
		glTexCoord2f(1.0, 0.0); glVertex3f(-1.0, -1.0, -1.0);
		glTexCoord2f(1.0, 1.0); glVertex3f(-1.0, 1.0, -1.0);
		glTexCoord2f(0.0, 1.0); glVertex3f(1.0, 1.0, -1.0);

		glNormal3f(-1.0, 0.0, 0.0);//left face
		glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, -1.0);
		glTexCoord2f(1.0, 0.0); glVertex3f(-1.0, -1.0, 1.0);
		glTexCoord2f(1.0, 1.0); glVertex3f(-1.0, 1.0, 1.0);
		glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0, -1.0);

		glNormal3f(1.0, 0.0, 0.0);//right face
		glTexCoord2f(0.0, 0.0); glVertex3f(1.0, -1.0, 1.0);
		glTexCoord2f(1.0, 0.0); glVertex3f(1.0, -1.0, -1.0);
		glTexCoord2f(1.0, 1.0); glVertex3f(1.0, 1.0, -1.0);
		glTexCoord2f(0.0, 1.0); glVertex3f(1.0, 1.0, 1.0);

		glNormal3f(0.0, 1.0, 0.0);//up face
		glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, 1.0, 1.0);
		glTexCoord2f(1.0, 0.0); glVertex3f(1.0, 1.0, 1.0);
		glTexCoord2f(1.0, 1.0); glVertex3f(1.0, 1.0, -1.0);
		glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0, -1.0);

		glNormal3f(0.0, -1.0, 0.0);//bottom face
		glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, -1.0);
		glTexCoord2f(1.0, 0.0); glVertex3f(1.0, -1.0, -1.0);
		glTexCoord2f(1.0, 1.0); glVertex3f(1.0, -1.0, 1.0);
		glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, -1.0, 1.0);
	glEnd();

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glColor4f(1.0, 1.0, 0.0, 1.0);
	glRasterPos2i(200, 200);
	glutBitmapString(GLUT_BITMAP_HELVETICA_18, "text");

	glFlush();//must be added in the end of display function
	glutSwapBuffers();
}


[/EDIT]


[/EDIT]

,但程序将自动关闭.
不可能在没有看到更多代码的情况下回答此问题.

为什么此函数必须使用const unsigned char *,尤其是unsigned
因为这就是GLUT库的设计者所定义的方式.
but the program will automatically close.
Impossible to answer this without seeing more code.

why this function must use const unsigned char*, particularly unsigned
Because that is how it has been defined by the designers of the GLUT library.