Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hey there, sep87x with another problem,

 

so for my (quiet huge) project I need to download image and place them in a cropped size (128x128) into a cache folder (located at .minecraft/sol-cache). After that, I need to render them to a GUI screen. As far as I know I can't use the ResourceLocation class because it only gets contents from the assets folder, but is it possible in some other way to retrieve the image from the cache with a ResourceLocation or do I need to do some "hardcore texture binding"?

 

... and no, I won't use slick-util.

 

Greets from Germany

~sep87x

 

Edit: okay, I will use the slick-util library if none of this works ... which would make me really sad.

  • Author

So I kinda did something ... but it's not correct. I read through the whole thread and made the method fit my conditions. (That's the only example I found)

 

    private void bindBufferedImage(BufferedImage image) {
    	image = image.getSubimage((image.getWidth() - 128) / 2, (image.getHeight() - 128) / 2, 128, 128);
    	
    	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() * 4);
    	
    	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));
    		}
    	}
    	
    	buffer.flip();
    	
    	int textureID = GL11.glGenTextures();
    	GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
        
        //GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
    }

 

Now I want to draw the image, but only a white box shows up.

 

			        // fyi, the variable tag stores some information about a compound in a xml file. tag.tagType is an enum. the file name is correct. i verified that
		        try {
					bindBufferedImage(ImageIO.read(new File("pmcol-cache/tag_" + tag.tagType.getStringForTag().toLowerCase() + "_" + (showcaseIndex % 3) + ".jpg")));
					this.drawTexturedModalRect(0, 0, 0, 0, 256, 256);
				} catch (IOException e) {
					e.printStackTrace();
				}

 

IMO, there are only two possible causes. One: the integer array "pixels" is not fed with right information. Two: the format of the file is not correct. Can anyone help me? I've coded for several weeks now and don't want to get stuck on that tiny problem.

 

Edit: And yes I know ... a jpg doesn't have an alpha level ... me dumb. Ignore that.

  • Author

Ah okay. I forgot the following:

 

// Setup wrap mode
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);

// Setup texture scaling filtering
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);

 

And I figured out that I'm able to save the images with PNG (+alpha) without any conversions, so anything went better than expected. Thanks a lot man

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.