这是我尝试制作cube map。
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中制作立方体贴图?
答案 0 :(得分:1)
我认为您希望在开头某处进行gluLookAt
通话,以便正确设置相机转换。
看看:
上面示例中的camera->x, camera->y, camera->z
元素应替换为描述相机方向的矢量。
答案 1 :(得分:1)
您需要在代码中添加一些内容才能使其正常工作:
关于使用opengl进行硬件多维数据集映射的相当广泛的文章(这是一个多供应商扩展):http://www.nvidia.com/object/cube_map_ogl_tutorial.html