1
幾天前,我開始了一個與opengl 1.1(我知道它非常過時)的小體素遊戲。我使用sfml庫來創建一個opengl上下文。我認爲問題出在紋理座標上,但我不確定。渲染代碼:OpenGL紋理立方體沒有正確映射
glPushMatrix();
glBegin(GL_QUADS);
glColor3f(0.5, 0.5, 0.5);
//front
glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
glTexCoord2f(1, 0); glVertex3f(0, 1, 0);
glTexCoord2f(1, 1); glVertex3f(1, 1, 0);
glTexCoord2f(1, 0); glVertex3f(1, 0, 0);
//back
glTexCoord2f(0, 0); glVertex3f(0, 0, 1);
glTexCoord2f(1, 0); glVertex3f(0, 1, 1);
glTexCoord2f(1, 1); glVertex3f(1, 1, 1);
glTexCoord2f(1, 0); glVertex3f(1, 0, 1);
glColor3f(0.6, 0.6, 0.6);
//top
glTexCoord2f(0, 0); glVertex3f(0, 1, 0);
glTexCoord2f(1, 0); glVertex3f(0, 1, 1);
glTexCoord2f(1, 1); glVertex3f(1, 1, 1);
glTexCoord2f(1, 0); glVertex3f(1, 1, 0);
//bottom
glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
glTexCoord2f(1, 0); glVertex3f(0, 0, 1);
glTexCoord2f(1, 1); glVertex3f(1, 0, 1);
glTexCoord2f(1, 0); glVertex3f(1, 0, 0);
glColor3f(0.7, 0.7, 0.7);
//left
glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
glTexCoord2f(1, 0); glVertex3f(0, 1, 0);
glTexCoord2f(1, 1); glVertex3f(0, 1, 1);
glTexCoord2f(1, 0); glVertex3f(0, 0, 1);
//right
glTexCoord2f(0, 0); glVertex3f(1, 0, 0);
glTexCoord2f(1, 0); glVertex3f(1, 1, 0);
glTexCoord2f(1, 1); glVertex3f(1, 1, 1);
glTexCoord2f(1, 0); glVertex3f(1, 0, 1);
glEnd();
glPopMatrix();
這是在遊戲中的木紋理的一個:
這是木材紋理的圖片:
它被映射在真古怪。哪裏不對?有人可以發佈一個普通紋理立方體的例子嗎?
謝謝,我會試試 –
哦,我覺得很愚蠢!我爲什麼這樣做?無論如何,非常感謝你!我可以繼續我的體素遊戲! –