这是我制作立方体贴图的尝试。
glDisable(GL_TEXTURE_2D);
glEnable(GL_TEXTURE_CUBE_MAP);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
PNGDecoder pngDecoder = new PNGDecoder(ResourceLoader.getResourceAsStream("C:/desert_skymap_sample.png"));
ByteBuffer temp = ByteBuffer.allocateDirect(4*pngDecoder.getWidth() * pngDecoder.getHeight());
pngDecoder.decode(temp, pngDecoder.getWidth()*4, PNGDecoder.Format.RGBA);
temp.flip();
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X,0,GL_RGBA,pngDecoder.getWidth(), pngDecoder.getHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,temp);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X,0,GL_RGBA,pngDecoder.getWidth(), pngDecoder.getHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,temp);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y,0,GL_RGBA,pngDecoder.getWidth(), pngDecoder.getHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,temp);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,0,GL_RGBA,pngDecoder.getWidth(), pngDecoder.getHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,temp);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z,0,GL_RGBA,pngDecoder.getWidth(), pngDecoder.getHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,temp);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,0,GL_RGBA,pngDecoder.getWidth(), pngDecoder.getHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,temp);
gluLookAt(0,0,0, xtrans+xpos,ytrans+walkbias,ztrans+zpos, 0,1,0);
glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_DEPTH_TEST);
glColor4f(1,1,1,1);
glBindTexture(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_CUBE_MAP_POSITIVE_X);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex3f(1f, -1f, -1f);
glTexCoord2f(1, 0);
glVertex3f(-1f, -1f, -1f);
glTexCoord2f(1, 1);
glVertex3f(-1f, 1f, -1f);
glTexCoord2f(0, 1);
glVertex3f(1f, 1f, -1f);
glEnd();
glBindTexture(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_CUBE_MAP_NEGETIVE_X);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex3f(1f, -1f, 1f);
glTexCoord2f(1, 0);
glVertex3f(1f, -1f, -1f);
glTexCoord2f(1, 1);
glVertex3f(1f, 1f, -1f);
glTexCoord2f(0, 1);
glVertex3f(1f, 1f, 1f);
glEnd();
我正在使用 TWL 的 PngDecoder。问题是我不知道如何获取纹理 id/retreve TexImage2D 或者我是否正确执行。
如何在 LWJGL 中制作立方体贴图?