LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: Peilot on November 21, 2016, 10:50:01

Title: STBImage does not load images! CODE IN DESCRIPTION!
Post by: Peilot on November 21, 2016, 10:50:01
This is the code I use too load images, it used to work. Also I've changed the name of my project too.


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 images! CODE IN DESCRIPTION!
Post by: Kai on November 21, 2016, 11:09:52
DOUBLE-POST
See: http://forum.lwjgl.org/index.php?topic=6375.msg33962#msg33962