glTranslatef没有它的等价物

时间:2012-08-04 00:07:39

标签: c++ opengl

好的,所以我正在玩游戏以从中检索数据并使用它。我得到了挂钩文字(通过CallLists)。

游戏使用:

enter image description here

glNewlist()
glBegin(GL_QUADS)
glVertex2i(....);    //Stored the location of each char in the bitmap above..
glTexCoords2f(....); //Not sure what this is..
glEnd()
glEndList()

glCallList(876);   //Represents a single character in the above bitmap.
glLoadIdentity();   //Resets the matrix.
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);
glTranslatef(336, 196, 0);  //Places it on screen somehow! :S? This is what I need to know.
glColor4ub(0, 0, 0, 255);  //Colours the text.
LoadIdentity();            //Resets the matrix and does the next character.
glCallList(877);           //Next char.

将文字渲染到屏幕上。有没有办法可以找出屏幕上文字的坐标?我可以通过Detours访问所有功能。

我不确定glTranslate做了什么。如何获取文本的X和Y?

我用它来从glTranslate投射coords,但它仍然错误地预测它。我将什么传递给我的WorldVector?它只是一个带有X,Y,Z的结构。我已经将它传递给了glTranslate coords,但这不起作用。

bool WorldToScreen(GLfloat &X, GLfloat &Y, Vector3D World, GLdouble* ModelViewMatrix, GLdouble* ProjectionMatrix)
{
    GLint ViewPort[4];
    GLdouble Screen[3];
    glGetIntegerv(GL_VIEWPORT, ViewPort);

    if(gluProject(World.X, World.Y, World.Z, ModelViewMatrix, ProjectionMatrix, ViewPort, &Screen[0], &Screen[1], &Screen[2]) == GL_TRUE)
    {
        X = Screen[0];
        Y = ViewPort[3] - Screen[1];
        return true;
    }
    return false;
}

2 个答案:

答案 0 :(得分:1)

这真的取决于,如果你正在以正交模式绘制文本,无论你传递到glTranslatef中的是实际的屏幕坐标,如果你处于透视模式,你将不得不通过转换管道传递它们以获得屏幕坐标,我相信这样做的功能将在名为gluProject的GLU库中,其中gluUnProject将屏幕坐标带到世界空间

translate to world position 
translate to view position 
divide by W (Copy of Z) to get projection coordinates 
ScreenX = Px * ScreenWidth/2 + ScreenWidth/2 
ScreenY = -Py * ScreenWidth/2 + ScreenWidth/2

答案 1 :(得分:1)

以下是在拼写

中翻译和调用列表的示例
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, SCREEN_WIDTH, SCREEN_HEIGHT, 0.0, -1.0, 1.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(336.0f, 196.0f, 0.0f);
glColor4f(1.0f, 0.0f, 0.0f, 1.0f); //Red
glCallList(877); //Or whatever list you wish to call

此时,您可能希望将下一个字符的宽度写入,并简单地翻译值以将文本直接放在其右侧,

顺便说一句,有一个很好的免费使用名为FreeType 2的库,暴雪将它用于游戏,以及我自己,前者使它具有良好的可信度。

如果我仍然没有回答你的问题,请务必告诉我

相关问题