1
我有我的窗口坐标,我需要在这里绘制文本。如何将窗口坐标转换为标准化的设备坐标?
我用这个函数:
void displayText(std::string const& text, float x, float y)
{
int j = text.size();
glColor3f(1, 1, 1);
// std::cout << x << " " << y << std::endl;
// std::cout << (x/900) * (2.0 - 1.0) <<" " <<(y/900) * (2.0 - 1.0) << std::endl;
x = x/(float)900; //900 is my window size
y = y/(float)900;
x-=0.5f;
y-=0.5f;// std::cout << x << " "<<y << std::endl;
glRasterPos2f(x, y);
for(int i = 0; i < j; i++)
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, text[i]);
}
,但它在错误的绘制文本协调,上下颠倒,有什么想法?
什么是“错误坐标”?它与你期望的有什么不同? – Carcigenicate
我有多个文字绘制,位于窗口周围,但所有文字都绘制在同一个点上。 –