
Tammo
Members-
Content Count
1 -
Joined
-
Last visited
Community Reputation
0 NeutralAbout Tammo
-
Rank
Tree Puncher
-
Hey there, i want to render a BufferedImage to a GuiScreen. I have the following code, which works on 1.12, but unfortunately it does'nt work on 1.15. I guess because of the update to lwjgl 3, it doesn't work as i want. Currently, a texture is rendered, but it is very distorted. Colors are the right, but the positions of the pixels are nearly all wrong. I guess the problem is, that the OpenGl does not interpret the buffer right. @Override public int allocateBufferedImage(final BufferedImage image) { int width = image.getWidth(); int height = image.getHeight(); int[] pixels = image.getRGB(0, 0, width, height, null, 0, width); ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * 4); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { int pixel = pixels[y * width + x]; buffer.put((byte) ((pixel >> 16) & 0xFF)); // red buffer.put((byte) ((pixel >> 8) & 0xFF)); // green buffer.put((byte) (pixel & 0xFF)); // blue buffer.put((byte) ((pixel >> 24) & 0xFF)); // alpha } } buffer.flip(); int textureID = GL11.glGenTextures(); this.bind(textureID); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL_NEAREST); GL11.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL_NEAREST); GL11.glTexImage2D( GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, width, height, 0, GL11.GL_RGBA, GL_UNSIGNED_BYTE, buffer); this.bind(0); return textureID; } Does anybody know a solution for this maybe?