LWJGL Forum

Programming => OpenGL => Topic started by: Peilot on November 20, 2016, 22:00:17

Title: SOLVED STBImage does not load my image! CODE IN DESCRIPTION!
Post by: Peilot on November 20, 2016, 22:00:17
This is the code I use too load images:

package Libraries;

import java.nio.ByteBuffer;
import java.nio.IntBuffer;

import org.lwjgl.BufferUtils;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.stb.STBImage.*;

public class Texture {
private int width;
private int height;
private int id;

public Texture(String filename) {
IntBuffer width = BufferUtils.createIntBuffer(1);
IntBuffer height = BufferUtils.createIntBuffer(1);
IntBuffer comp = BufferUtils.createIntBuffer(1);

ByteBuffer data = stbi_load("./Assets/" + filename, width, height, comp, 4);

id = glGenTextures();
this.width = width.get();
this.height = height.get();

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, this.width, this.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
stbi_image_free(data);
}

public void bind() {
glBindTexture(GL_TEXTURE_2D, id);
}

public void unbind() {
glBindTexture(GL_TEXTURE_2D, 0);
}
}


All help is appreciated!
/Marcus
Title: Re: STBImage does not load my image! CODE IN DESCRIPTION!
Post by: Kai on November 21, 2016, 09:34:37
STB does load your image. You are just not binding the texture after glGenTextures() so that further texture modifications affect it.
You should be getting OpenGL errors, too. Check GL11.glGetErrors().
Title: Re: STBImage does not load my image! CODE IN DESCRIPTION!
Post by: Peilot on November 21, 2016, 11:16:56
Quote from: Kai on November 21, 2016, 09:34:37
STB does load your image. You are just not binding the texture after glGenTextures() so that further texture modifications affect it.
You should be getting OpenGL errors, too. Check GL11.glGetErrors().

Thanks alot!
I'll try it as fast as i get home!