1
我想實現HUD到我的3D應用程序,我所取得的是我在某個位置有矩形,紋理覆蓋它。問題是,無論何時我旋轉或移動相機,紋理縮放或移動相機,看起來都很奇怪。任何想法爲什麼會發生?2D HUD紋理錯誤
這是我做什麼,添加HUD:
glDisable(GL_DEPTH_TEST);
glClear(GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, 1, 0, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glEnable (GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D,4);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glBegin(GL_QUADS);
glColor3f(1.0f, 1.0f, 0.0f);
glTexCoord2f(0,0);
glVertex2f(0.0f, 0.0f);
glTexCoord2f(1,0);
glVertex2f(0.4f, 0.0f);
glTexCoord2f(1,1);
glVertex2f(0.4f, 0.4f);
glTexCoord2f(0,1);
glVertex2f(0.0f,0.4f);
glEnd();
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
您是否試圖在2D或3D中繪製HUD?你能發表你描述的問題的截圖嗎? – Bojangles 2012-04-21 13:09:37
它應該是2d – 2012-04-21 13:15:24
您是在正投影中繪製它,然後使用像素值? – Bojangles 2012-04-21 13:16:47