pooya
pooya

Reputation: 911

cubemap in LWJGL

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

Upvotes: 3

Views: 1527

Answers (1)

Julien
Julien

Reputation: 934

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.

Upvotes: 4

Related Questions