LWJGL 中的立方体贴图
我尝试将立方体映射添加到我的项目中,但出现一个错误,我不知道如何修复它 当我评论这几行时,每件事都工作正常,但是当它们处于...时,会发生此错误
“线程“主”org.lwjgl.opengl.OpenGLException中的异常:禁用像素解包缓冲区对象时无法使用偏移”
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL13.GL_TEXTURE_CUBE_MAP);
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X,0,GL11.GL_RGBA,20,20,0,GL11.GL_RGBA,GL11.GL_UNSIGNED_BYTE,temp.getTextureID());
GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,0,GL11.GL_RGBA,20,20,0,GL11.GL_RGBA,GL11.GL_UNSIGNED_BYTE,temp.getTextureID());
GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,0,GL11.GL_RGBA,20,20,0,GL11.GL_RGBA,GL11.GL_UNSIGNED_BYTE,temp.getTextureID());
GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,0,GL11.GL_RGBA,20,20,0,GL11.GL_RGBA,GL11.GL_UNSIGNED_BYTE,temp.getTextureID());
GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_Z,0,GL11.GL_RGBA,20,20,0,GL11.GL_RGBA,GL11.GL_UNSIGNED_BYTE,temp.getTextureID());
GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,0,GL11.GL_RGBA,20,20,0,GL11.GL_RGBA,GL11.GL_UNSIGNED_BYTE,temp.getTextureID());
是否有任何错误出了什么问题吗? 我该如何修复这个错误?
谢谢您的宝贵时间
I try to add cube mapping to my project but i get one error that i dont know how to fix it
when i comment these few line every thing work fine but when they are in ...this error occur
"Exception in thread "main" org.lwjgl.opengl.OpenGLException: Cannot use offsets when Pixel Unpack Buffer Object is disabled"
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL13.GL_TEXTURE_CUBE_MAP);
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);
GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_X,0,GL11.GL_RGBA,20,20,0,GL11.GL_RGBA,GL11.GL_UNSIGNED_BYTE,temp.getTextureID());
GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,0,GL11.GL_RGBA,20,20,0,GL11.GL_RGBA,GL11.GL_UNSIGNED_BYTE,temp.getTextureID());
GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,0,GL11.GL_RGBA,20,20,0,GL11.GL_RGBA,GL11.GL_UNSIGNED_BYTE,temp.getTextureID());
GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,0,GL11.GL_RGBA,20,20,0,GL11.GL_RGBA,GL11.GL_UNSIGNED_BYTE,temp.getTextureID());
GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_POSITIVE_Z,0,GL11.GL_RGBA,20,20,0,GL11.GL_RGBA,GL11.GL_UNSIGNED_BYTE,temp.getTextureID());
GL11.glTexImage2D(GL13.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,0,GL11.GL_RGBA,20,20,0,GL11.GL_RGBA,GL11.GL_UNSIGNED_BYTE,temp.getTextureID());
is there any thing wrong?
how can i fix this error?
thank you for your time
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为 glTexImage2D 的最后一个参数应该是包含纹理像素的缓冲区。所以你应该使用LWJGL BufferUtils分配一个20*20的缓冲区,填充它与您的纹理数据,然后将此缓冲区传递给 glTexImage2D 函数。
现在,将 int 传递给 glTexImage2D 仍然可以编译的原因是因为有一个版本接受 long 作为最新参数。它应该表示像素缓冲区对象中的偏移量以从中获取像素数据。由于您没有附加像素缓冲区对象(并且您不需要立方体贴图),LWJGL 抱怨道。
所以基本上,将 temp.getTextureID() 作为最后一个参数会调用 glTexImage2D 的“错误”版本。
This is because the last argument to glTexImage2D should be a buffer containing the pixels for the texture. So you should allocate a 20*20 buffer using LWJGL BufferUtils, fill it with your texture data and then pass this buffer to the glTexImage2D function.
Now, the reason why passing an int to glTexImage2D still compiles is because there is one version that accept a long as the latest argument. And it is supposed to represent an offset in a pixel buffer object to fetch pixel data from. Since you don't have a pixel buffer object attached (and you don't need one for cube maps), LWJGL complains.
So basically, putting temp.getTextureID() as the last argument calls the "wrong" version of glTexImage2D.