Here is my if statement that detects a bomb threat (just a game I’m making)…
if (exodus2_bomb == 1)
{
float exodus2_theta_math = (exodus2_theta)/10.0*M_PI;
float exodus2_phi_math = (exodus2_phi)/10.0*2*M_PI;
r_exodus2_x = radius_exodus_pos * sin(exodus2_theta_math) * cos(exodus2_phi_math);
r_exodus2_y = radius_exodus_pos * sin(exodus2_theta_math) * sin(exodus2_phi_math);
r_exodus2_z = radius_exodus_pos * cos(exodus2_theta_math);
glPushMatrix();
glTranslatef(r_exodus2_x,r_exodus2_y,r_exodus2_z);
glColor3f (1.0, 0.0, 0.0);
glRasterPos3i(exodus2_x/10,exodus2_y/10,exodus2_z/10);
string exodus2 = "BOMB!!";
void * fontexodus2 = GLUT_BITMAP_HELVETICA_10;
for (string::iterator i = exodus2.begin(); i != exodus2.end(); ++i)
{
char c = *i;
glutBitmapCharacter(fontexodus2, c);
}
glEnd();
glPopMatrix();
glPushMatrix();
glTranslatef(r_exodus2_x,r_exodus2_y,r_exodus2_z);
glColor3f (1.0, 0.0, 0.0);
glRasterPos3i(exodus2_x/10,exodus2_y/10,exodus2_z/10);
string exodus2b = "\n THREAT LEVEL 1";
void * fontexodus2b = GLUT_BITMAP_HELVETICA_10;
for (string::iterator i = exodus2b.begin(); i != exodus2b.end(); ++i)
{
char c = *i;
glutBitmapCharacter(fontexodus2b, c);
}
glEnd();
glPopMatrix();
}
What I would like to have is a carriage return between “string exodus2” and “string exodus2b”. However, it is always on one line. And I don’t have the real estate onscreen for that.
Is it possible to add a carriage return somewhere in my string iterator?
Unfortunately, screwing around with “glTranslatef” and “glRasterPos3i” only results in the distance between the two lines of text NOT being consistent as I move the camera.
You need to render each string separately, and modify the raster position appropriate to reset the string’s position. If you use
glutBitmapHeight, you can determine how far you need to move the raster position “down” to emulate a new line.If you want the strings to be positioned in 3D, but then to “act” like they’re restricted to the same plane in 2D, you can use the
glBitmapcommand to modify the raster position in screen space.the fifth and sixth parameters of
glBitmapcontrol how far the raster position is moved.Alternatively, if you want these strings to be anchored in a position relative to the window, as compared to a point in your 3D space, check out
glWindowPos.By the way, all of these functions are deprecated with OpenGL 3.0, removed in OpenGL 3.1, unless you use a compatibility context in verisons of OpenGL greater than 3.2.