Jump to content

Get texture outside the assets folder


sep87x

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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