Oh okay, well than it has to be a bug on my end. i'm working with lwjgl 3.2.3
Here is how i load textures.
internalFormat = GL_RGB
format = GL_RGB
type = GL_UNSIGNED_BYTE
min_filter = mag_filter = GL_NEAREST
wrap_s = wrap_t = GL_WRAP_TO_EDGE
samplers = 1
target = GL_TEXTURE_2D
ID = glGenTextures();
gfx.bind(this); -> glBindTexture
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, min_filter);
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, mag_filter);
glTexParameteri(target, GL_TEXTURE_WRAP_S, wrap_s);
glTexParameteri(target, GL_TEXTURE_WRAP_T, wrap_t);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
if (target == GL_TEXTURE_2D_MULTISAMPLE) {
if (pixels == null) {
glTexImage2DMultisample(target, samples, internal_format,
width, height, true);
} else {
throw new UnsupportedOperationException("can't create multisampled textures based on pixel data");
}
} else {
glTexImage2D(target, 0, internal_format, width, height,
0, format, type, pixels);
}
gfx.unbind(this); -> glBindTexture(0)
And here is the code how i load the ByteBuffer pixels.
This is probably a bit much because i copied it mostly from a lwjgl demo.
public static PixelBuffer loadTexture(Class accessClass, String resourcePath) {
ByteBuffer imageBuffer;
try {
imageBuffer = ioResourceToByteBuffer(accessClass, resourcePath);
} catch (IOException e) {
throw new RuntimeException("could not read file : " + resourcePath);
}
ByteBuffer image;
int width;
int height;
int channels;
try (MemoryStack stack = stackPush()) {
IntBuffer w = stack.mallocInt(1);
IntBuffer h = stack.mallocInt(1);
IntBuffer c = stack.mallocInt(1);
stbi_set_flip_vertically_on_load(true);
image = stbi_load_from_memory(imageBuffer, w, h, c, 0);
if (image == null) {
throw new RuntimeException("Failed to load image : " + stbi_failure_reason());
}
width = w.get(0);
height = h.get(0);
channels = c.get(0);
}
return new PixelBuffer(image, width, height, channels);
}
private static ByteBuffer ioResourceToByteBuffer(Class accessClass, String resource) throws IOException {
ByteBuffer buffer;
Path path = Paths.get(resource);
if (Files.isReadable(path)) {
try (SeekableByteChannel fc = Files.newByteChannel(path)) {
buffer = createByteBuffer((int) fc.size() + 1);
while (fc.read(buffer) != -1) ;
}
} else {
try (InputStream source = accessClass.getClassLoader().getResourceAsStream(resource);
ReadableByteChannel rbc = Channels.newChannel(source)) {
buffer = createByteBuffer(8 * 1024);
while (true) {
int bytes = rbc.read(buffer);
if (bytes == -1) break;
if (buffer.remaining() == 0) buffer = resizeBuffer(buffer, buffer.capacity() * 3 / 2);
}
}
}
buffer.flip();
return memSlice(buffer);
}
private static ByteBuffer resizeBuffer(ByteBuffer buffer, int newCapacity) {
ByteBuffer newBuffer = BufferUtils.createByteBuffer(newCapacity);
buffer.flip();
newBuffer.put(buffer);
return newBuffer;
}
attached is a screenshot what i get when i run it. the image that i load is a 16*19 png with 3 channels that is just plain yellow.
Nope for some reason can't attach screenshots [Server Error] any way its a gliched yellow quad in the middle of the window first 16*19 pixels from the bottom right are yellow rest is random rgb. I'm currently working on an older laptop with integrated graphics havn't though of that, maybe thats the problem because iam running integrated graphics.
One more question about rgb -> rgba convertion. how does it work
is format the format of the byteBuffer we put in or is internal_format that format. which is which?