Jump to content
  • Home
  • Files
  • Docs
Status Updates
  • All Content

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Tammo

Tammo

Members
 View Profile  See their activity
  • Content Count

    1
  • Joined

    July 21, 2020
  • Last visited

    December 16, 2020

Community Reputation

0 Neutral

About Tammo

  • Rank
    Tree Puncher
  1. Tammo

    Render BufferedImage to Gui

    Tammo posted a topic in Modder Support

    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?
    • July 21, 2020
  • All Activity
  • Home
  • Tammo
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community