1
我想要製作一個方法來繪製一個具有指定大小和紋理的立方體。問題是,當我調整立方體的大小時,紋理不會隨着它一起調整大小。例如,如果我以大小.5F繪製,則只有8x8像素的16x16紋理繪製。我究竟做錯了什麼?OpenGL LWJGL可調整大小的紋理立方體
static void drawCube(float size, Texture tex, int x, int y, int z) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTranslatef(x, y, z);
tex.bind();
glPolygonMode(GL_FRONT, GL_FILL);
glBegin(GL_QUADS);
glTexCoord2d(0.0f * size, 0.0f * size);
glVertex3f(-1.0f * size, -1.0f * size, 1.0f * size);
glTexCoord2d(1.0f * size, 0.0f * size);
glVertex3f(1.0f * size, -1.0f * size, 1.0f * size);
glTexCoord2d(1.0f * size, 1.0f * size);
glVertex3f(1.0f * size, 1.0f * size, 1.0f * size);
glTexCoord2d(0.0f * size, 1.0f * size);
glVertex3f(-1.0f * size, 1.0f * size, 1.0f * size);
glEnd();
glBegin(GL_QUADS);
glTexCoord2d(1.0f * size, 0.0f * size);
glVertex3f(-1.0f * size, -1.0f * size, -1.0f * size);
glTexCoord2d(1.0f * size, 1.0f * size);
glVertex3f(-1.0f * size, 1.0f * size, -1.0f * size);
glTexCoord2d(0.0f * size, 1.0f * size);
glVertex3f(1.0f * size, 1.0f * size, -1.0f * size);
glTexCoord2d(0.0f * size, 0.0f * size);
glVertex3f(1.0f * size, -1.0f * size, -1.0f * size);
glEnd();
glBegin(GL_QUADS);
glTexCoord2d(0.0f * size, 1.0f * size);
glVertex3f(-1.0f * size, 1.0f * size, -1.0f * size);
glTexCoord2d(0.0f * size, 0.0f * size);
glVertex3f(-1.0f * size, 1.0f * size, 1.0f * size);
glTexCoord2d(1.0f * size, 0.0f * size);
glVertex3f(1.0f * size, 1.0f * size, 1.0f * size);
glTexCoord2d(1.0f * size, 1.0f * size);
glVertex3f(1.0f * size, 1.0f * size, -1.0f * size);
glEnd();
glBegin(GL_QUADS);
glTexCoord2d(1.0f * size, 1.0f * size);
glVertex3f(-1.0f * size, -1.0f * size, -1.0f * size);
glTexCoord2d(0.0f * size, 1.0f * size);
glVertex3f(1.0f * size, -1.0f * size, -1.0f * size);
glTexCoord2d(0.0f * size, 0.0f * size);
glVertex3f(1.0f * size, -1.0f * size, 1.0f * size);
glTexCoord2d(1.0f * size, 0.0f * size);
glVertex3f(-1.0f * size, -1.0f * size, 1.0f * size);
glEnd();
glBegin(GL_QUADS);
glTexCoord2d(1.0f * size, 0.0f * size);
glVertex3f(1.0f * size, -1.0f * size, -1.0f * size);
glTexCoord2d(1.0f * size, 1.0f * size);
glVertex3f(1.0f * size, 1.0f * size, -1.0f * size);
glTexCoord2d(0.0f * size, 1.0f * size);
glVertex3f(1.0f * size, 1.0f * size, 1.0f * size);
glTexCoord2d(0.0f * size, 0.0f * size);
glVertex3f(1.0f * size, -1.0f * size, 1.0f * size);
glEnd();
glBegin(GL_QUADS);
glTexCoord2d(0.0f * size, 0.0f * size);
glVertex3f(-1.0f * size, -1.0f * size, -1.0f * size);
glTexCoord2d(1.0f * size, 0.0f * size);
glVertex3f(-1.0f * size, -1.0f * size, 1.0f * size);
glTexCoord2d(1.0f * size, 1.0f * size);
glVertex3f(-1.0f * size, 1.0f * size, 1.0f * size);
glTexCoord2d(0.0f * size, 1.0f * size);
glVertex3f(-1.0f * size, 1.0f * size, -1.0f * size);
glEnd();
glTranslatef(-x, -y, -z);
}