Hello Guest

SOLVED STBImage does not load my image! CODE IN DESCRIPTION!

  • 2 Replies
  • 1963 Views
SOLVED STBImage does not load my image! CODE IN DESCRIPTION!
« on: November 20, 2016, 22:00:17 »
This is the code I use too load images:

Code: [Select]
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
« Last Edit: November 21, 2016, 11:17:32 by Peilot »

*

Kai

Re: STBImage does not load my image! CODE IN DESCRIPTION!
« Reply #1 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().

Re: STBImage does not load my image! CODE IN DESCRIPTION!
« Reply #2 on: November 21, 2016, 11:16:56 »
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!