May 6, 201510 yr comment_157049 [lmgtfy=minecraft forge buffered image in gui]Google for the win![/lmgtfy] Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
May 6, 201510 yr Author comment_157054 I have googled it already. but everything is outdated and should be done different with the current version (the methods are changed). so how to do it with the current forge?
May 6, 201510 yr comment_157057 Where do you get the BufferedImage from? If it is a static image, you might be able to use a ResourceLocation with a custom IResourcePack implementation. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
May 6, 201510 yr comment_157060 Again: where do you get the BufferedImage from? Eg. BufferedImage img = ?; Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
May 6, 201510 yr Author comment_157075 Again, it's an dynamic generated image: BufferedImage.createGraphics()
May 7, 201510 yr comment_157159 Use DynamicTexture. You can easily construct a DynamicTexture with BufferedImage, and get its ResourceLocation from TextureManager#getDynamicTextureLocation(String key, BufferedImage img); I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
May 7, 201510 yr Author comment_157175 How can I edit the texture and update the dynamic texture? When I reinitialized the texture with getDynamicTextureLocation() in drawscreen() of my gui I get an memory overflow error.
May 7, 201510 yr comment_157177 How can I edit the texture and update the dynamic texture? When I reinitialized the texture with getDynamicTextureLocation() in drawscreen() of my gui I get an memory overflow error. That means your texture is too big. How big is it? I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
May 7, 201510 yr Author comment_157178 The image is 600 X 600 px. It crashes in about 10 seconds after the gui was opened. crash: java.lang.OutOfMemoryError: Java heap space at net.minecraft.client.renderer.texture.DynamicTexture.<init>(DynamicTexture.java:28) at net.minecraft.client.renderer.texture.DynamicTexture.<init>(DynamicTexture.java:19) at com.superbas11.modcontrol.client.Gui.TestGUI.drawScreen(GuiBasic.java:230) at net.minecraftforge.client.ForgeHooksClient.drawScreen(ForgeHooksClient.java:427) at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1078) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1048) at net.minecraft.client.Minecraft.run(Minecraft.java:345) at net.minecraft.client.main.Main.main(Main.java:117) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source) at GradleStart.main(Unknown Source)
May 7, 201510 yr comment_157180 my guess: you're allocating a new one every tick and not discarding the old ones. -TGG
May 7, 201510 yr Author comment_157182 this does not work: Dynamic.deleteGlTexture(); Dynamic = null; Dynamic = new DynamicTexture(Image); Texturelocation = this.mc.getTextureManager().getDynamicTextureLocation("ModControl.Graph",Dynamic); How should the texture be discarded?
May 7, 201510 yr comment_157184 600x600? Thats huge. Thats bigger than default texturemap... I'd suggest you calculate the image once per tick. Not every frame and reuse that image in rendering instead of recalculating it every frame. The image itself takes up roughly 1.3 mb in ram. Not to mention variables used in the calculation process. If you run this every frame your heap space gets full really fast. By calculation once per tick or several ticks you give the garbage collector time to catch up. How much wood could a woodchuck chuck if a wood chuck could chuck wood - Guybrush Treepwood I wrote my own mod ish... still a few bugs to fix. http://thaumcraft.duckdns.org/downloads/MagicCookies-1.0.6.4.jar
May 7, 201510 yr comment_157186 This should work public static void loadBind(BufferedImage image) { int[] pixels = new int[image.getWidth() * image.getHeight()]; image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth()); ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * BYTES_PER_PIXEL); for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { int pixel = pixels[y * image.getWidth() + x]; buffer.put((byte) ((pixel >> 16) & 0xFF)); buffer.put((byte) ((pixel >> & 0xFF)); buffer.put((byte) (pixel & 0xFF)); buffer.put((byte) ((pixel >> 24) & 0xFF)); } } glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, (ByteBuffer) buffer.flip()); }
May 7, 201510 yr Author comment_157189 600x600? Thats huge. Thats bigger than default texturemap... I'd suggest you calculate the image once per tick. Not every frame and reuse that image in rendering instead of recalculating it every frame. The image itself takes up roughly 1.3 mb in ram. Not to mention variables used in the calculation process. If you run this every frame your heap space gets full really fast. By calculation once per tick or several ticks you give the garbage collector time to catch up. thanks that worked! One last question: How to set the scale of the image? got this: this.mc.getTextureManager().bindTexture(Texturelocation); drawTexturedModalRect(150, 50, 0, 0, 600, 600); Now it renders the image small and multiple times on the screen but I want it to render on a big part of the screen, ones.
May 7, 201510 yr comment_157191 Look on this topic: http://www.minecraftforge.net/forum/index.php/topic,25161.msg127886.html#msg127886
May 7, 201510 yr comment_157200 o_O You render a big ass image of 600x600 and then you cut it up into a smaller image? Why not render it into a smaller image? saves spaces on bandwidth to graphics card. Please post of a screenshot of what you have... and what you want it to look because I have the feeling I don't understand what you want How much wood could a woodchuck chuck if a wood chuck could chuck wood - Guybrush Treepwood I wrote my own mod ish... still a few bugs to fix. http://thaumcraft.duckdns.org/downloads/MagicCookies-1.0.6.4.jar
May 7, 201510 yr Author comment_157203 got this: I want something like this: don't mind the graph, its some old test code.
May 8, 201510 yr comment_157283 That's simply size problem. Please post the rendering code. I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
May 8, 201510 yr Author comment_157316 code: public TestGui(){ ... Image = new BufferedImage(600, 600, BufferedImage.TYPE_INT_ARGB); ... } @Override public void drawScreen(int mouseX, int mouseY, float par3) { ... this.mc.getTextureManager().bindTexture(Texturelocation); drawTexturedModalRect(150, 120, 0, 0, 600, 600); RenderHelper.enableGUIStandardItemLighting();RenderHelper.disableStandardItemLighting(); super.drawScreen(mouseX, mouseY, par3); RenderHelper.enableStandardItemLighting(); } Subscribed to the game tick with some checks to prevent executing when it's not needed: DrawGraph(Image); Dynamic = new DynamicTexture(Image); Texturelocation = this.mc.getTextureManager().getDynamicTextureLocation("ModControl.Graph",Dynamic);
May 9, 201510 yr comment_157479 Do not use drawTexturedModalRect. It has several problems with texture size, etc. Make your custom implementation replacing that. (Texture u,v should be 0,1 -> 1,1 -> 1,0 -> 0,0) I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP) II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.
May 9, 201510 yr Author comment_157517 Problem solved! used drawModalRectWithCustomSizedTexture() to make custom sized texture.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.