Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How exactly can I use glutBitmapString?
C++
glColor4f(1.0, 1.0, 0.0, 1.0);
glRasterPos2i(200, 200);
glutBitmapString(GLUT_BITMAP_HELVETICA_18, "text");

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

But when I write this:
C++
glColor4f(1.0, 1.0, 0.0, 1.0);
glRasterPos2i(200, 200);
glutBitmapString(GLUT_BITMAP_HELVETICA_18, (const unsigned char *)"text");

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!

[EDIT]
here is the snippet of my display function:
C++
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]
Posted
Updated 18-Aug-11 1:50am
v2

1 solution

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.
 
Share this answer
 
Comments
arcodist 18-Aug-11 7:33am    
with out glutBitmapString, the program runs well. Can you help me check out the code? Thank you.
Richard MacCutchan 18-Aug-11 7:53am    
Sorry I don't have this library, you will need to use your debugger to check what is happening. You may also get a better response by talking to the real experts on the GLUT website
arcodist 18-Aug-11 8:07am    
Thank you all the same

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900