我正在尝试创建使用stb纹理加载的openGl(lwjgl)应用程序。在使用纹理之前,我已通过stbi_load()函数加载了此纹理。窗口中没有显示我的PNG(sRGB,4通道)图像。即使我使用了PNG文件,函数stbi_failure_reason()也会返回“ Corrupt JPEG”。绑定纹理段之后,GL11.glGetError()返回1281(错误值)。我检查了ByteBuffer-有时会出现负值。有人知道怎么了吗?
int w;
int h;
int id;
IntBuffer wx = BufferUtils.createIntBuffer(1);
IntBuffer hx = BufferUtils.createIntBuffer(1);
IntBuffer cx = BufferUtils.createIntBuffer(1);
ByteBuffer data = stbi_load("./assets/img/gui/logo.png", wx, hx, cx, 4);
if(data == null) {
System.out.println("Failed to load texture");
}
System.out.println(stbi_failure_reason());
System.out.println(cx.get(0));
id = GL11.glGenTextures();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBindTexture(GL_TEXTURE_2D, id);
System.out.println(GL11.glGetError());
w = wx.get();
h = hx.get();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 4, GL_RGBA, GL_UNSIGNED_BYTE, data);
stbi_image_free(data);
glBindTexture(GL_TEXTURE_2D, 0);