0
我曾嘗試使用下面的代碼創建了JOGL一個3D立方體2D紋理:JOGL使用一個3D立方體
/**
* Function used to draw a cube
*/
public void drawCube(GL gl) {
gl.glBegin(gl.GL_QUADS);
//gl.glColor3f(1, 0, 0);
gl.glTexCoord3f(0, 0, 0);
gl.glVertex3f(0, 0, 0);
gl.glTexCoord3f(4, 0, 0);
gl.glVertex3f(1, 0, 0);
gl.glTexCoord3f(4, 4, 0);
gl.glVertex3f(1, 1, 0);
gl.glTexCoord3f(0, 4, 0);
gl.glVertex3f(0, 1, 0);
gl.glEnd();
gl.glBegin(gl.GL_QUADS);
gl.glTexCoord3f(0, 0, 0);
// gl.glColor3f(0, 1, 0);
gl.glVertex3f(0, 0, 0);
gl.glTexCoord3f(0, 4, 0);
gl.glVertex3f(0, 1, 0);
gl.glTexCoord3f(0, 4, 4);
gl.glVertex3f(0, 1, 1);
gl.glTexCoord3f(0, 0, 4);
gl.glVertex3f(0, 0, 1);
gl.glEnd();
gl.glBegin(gl.GL_QUADS);
// gl.glColor3f(0, 0, 1);
gl.glTexCoord3f(0, 4, 0);
gl.glVertex3f(0, 1, 0);
gl.glTexCoord3f(4, 4, 0);
gl.glVertex3f(1, 1, 0);
gl.glTexCoord3f(4, 4, 4);
gl.glVertex3f(1, 1, 1);
gl.glTexCoord3f(0, 4, 4);
gl.glVertex3f(0, 1, 1);
gl.glEnd();
gl.glBegin(gl.GL_QUADS);
// gl.glColor3f(1, 1, 0);
gl.glTexCoord3f(4, 4, 0);
gl.glVertex3f(1, 1, 0);
gl.glTexCoord3f(4, 0, 0);
gl.glVertex3f(1, 0, 0);
gl.glTexCoord3f(4, 0, 4);
gl.glVertex3f(1, 0, 1);
gl.glTexCoord3f(4, 4, 4);
gl.glVertex3f(1, 1, 1);
gl.glEnd();
gl.glBegin(gl.GL_QUADS);
// gl.glColor3f(1, 0, 1);
gl.glTexCoord3f(4, 0, 0);
gl.glVertex3f(1, 0, 0);
gl.glTexCoord3f(0, 0, 0);
gl.glVertex3f(0, 0, 0);
gl.glTexCoord3f(0, 0, 4);
gl.glVertex3f(0, 0, 1);
gl.glTexCoord3f(4, 0, 4);
gl.glVertex3f(1, 0, 1);
gl.glEnd();
gl.glBegin(gl.GL_QUADS);
// gl.glColor3f(0, 1, 1);
gl.glTexCoord3f(0, 4, 4);
gl.glVertex3f(0, 1, 1);
gl.glTexCoord3f(4, 4, 4);
gl.glVertex3f(1, 1, 1);
gl.glTexCoord3f(4, 0, 4);
gl.glVertex3f(1, 0, 1);
gl.glTexCoord3f(0, 0, 4);
gl.glVertex3f(0, 0, 1);
gl.glEnd();
立方體在屏幕上,現在我想將每一個紋理面對這樣的:
public void init(GLAutoDrawable gld) {
//Init the gl
GL gl = gld.getGL();
//Init the glu
GLU glu = new GLU();
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(90, 1.6, 0.6, 30.0);
glu.gluLookAt(0, 0, 10, 0, 0, 0, 0, 2, 0);
gl.glEnable(gl.GL_TEXTURE_2D);
int id_textura = Gen_Textura(gl);
gl.glBindTexture(gl.GL_TEXTURE_2D, id_textura);
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR);
gl.glTexParameteri(gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR);
}
的問題是,紋理顯示了只有在立方體的一面,而不是對所有6
如何使紋理要在的所有面畫立方體?
你有一個2D紋理,你正在使用gl.glTexCoord3f(0,4,4); (它看起來像3D),其次我不確定紋理座標高於1的座標。你能再次檢查那兩個嗎? – guness 2012-04-19 20:04:35
是的,你應該使用'glTexCoord2f',通常紋理座標的範圍是[0,1]' – Torious 2012-04-19 20:05:44
你可以添加一個答案,我可以接受它嗎?如果我使用的glTexCoord2f()的座標範圍爲[0,1],它就起作用了。我不知道什麼原因來降低這個問題.. – Arkde 2012-04-19 20:45:07