3D 空间中的文本 - 如何回车?(openGL, C++, OSX)
text in 3d space - how to carriage return? (openGL, C++, OSX)
这是我检测到炸弹威胁的if语句(只是我正在制作的游戏)...
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();
}
我想要的是"string exodus2"和"string exodus2b"之间的回车符。但是,它始终在一行上。而且我在屏幕上没有这方面的房地产。
是否可以在我的字符串迭代器中的某个位置添加回车符?
不幸的是,使用"glTranslatef"和"glRasterPos3i"只会导致两行文本之间的距离在我移动相机时不一致。
您需要单独渲染每个字符串,并修改相应的栅格位置以重置字符串的位置。 如果使用 glutBitmapHeight
,则可以确定需要将栅格位置"向下"移动多远才能模拟新线。
如果希望字符串在 3D 中定位,但随后又"操作",就像它们在 2D 中被限制在同一个平面上一样,则可以使用 glBitmap
命令修改屏幕空间中的栅格位置。
int lineHeight = glutBitmapHeight( font ); // number of pixels between "lines"
int stringLength = glutBitmapLength( font, s1 ); // returns length of string 1 in pixels
glutBitmap( 0, 0, 0, 0, -stringLength, lineHeight, NULL ); // move raster position
glutBitmapString( font, s2 );
glBitmap
的第五个和第六个参数控制栅格位置的移动距离。
或者,如果您希望将这些字符串锚定在相对于窗口的位置(而不是 3D 空间中的点),请查看glWindowPos
。
顺便说一下,所有这些函数在 OpenGL 3.0 中都已弃用,在 OpenGL 3.1 中删除,除非您在大于 3.2 的 OpenGL 版本中使用兼容性上下文。
相关文章:
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- 命名空间中具有.h和.cpp文件的类
- 从父命名空间重载类型
- 当在同一名称空间中有两个具有相同签名的函数时,会发生什么
- 在命名空间中定义函数还是限定函数
- 了解 GLM- openGL 中的相机转换
- C++:对不存在的命名空间使用命名空间指令
- OpenGL相机和相机空间转型的困惑
- 当对象在屏幕空间中较小时,OpenGL 更新缓慢
- OpenGL-绘制相机空间后,将模型放置在世界空间中
- 我的3D OpenGL对象围绕世界来源,而不是本地空间来源.我在做什么错或误会
- 在OpenGL 2.1中,即使在2D空间(具有2D纹理),也可以安全使用3D TEX坐标
- OpenGL 在 3D 空间中渲染 2D
- OpenGL 不会为不在命名空间中的对象绘制多边形
- OpenGL:从许多帧缓冲纹理中读取空间像素数据的有效方法
- 用简单的opengl图像库(SOIL)加载一张图像(颜色空间:GRAY)
- OpenGL函数在命名空间gl中的缺点是什么?
- 为什么我们要在OpenGL管道的片段阶段使用眼空间坐标
- 3D 空间中的文本 - 如何回车?(openGL, C++, OSX)