I am creating a new 2d game engine in lwjgl 3 using OpenGL to try out lwjgl 3 as this is the first project I'm using lwjgl 3 in all my other projects have had lwjgl 2. But when I render an image using that new engine all the colors change and some don't even show up.
Code for loading textures
public Texture(String filename){
IntBuffer width = BufferUtils.createIntBuffer(1);
IntBuffer height = BufferUtils.createIntBuffer(1);
IntBuffer comp = BufferUtils.createIntBuffer(1);
ByteBuffer data = stbi_load(filename, width, height, comp, 4);
id = glGenTextures();
this.width = width.get();
this.height = height.get();
glBindTexture(GL_TEXTURE_2D, id);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, this.width, this.height, 0, GL_RGBA, GL_BYTE, data);
stbi_image_free(data);
}
If you know how i could this prevent from happening please let me know.
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, this.width, this.height, 0, GL_RGBA, GL_BYTE, data); ^^^^^^^
GL_BYTE
is a signed 8 Bit integer type, so all your values > 127 will end up being interpreted as negative values (assuming your platform uses standard two's complement representation at least) and be clamped to 0.
Just use GL_UNSIGNED_BYTE
.