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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Yeah idk how to shut this down but it had something to do with parchment. It works now, I think I may have had the wrong version or something?
    • Recently while playing offline due to internet outages Malwarebytes identified Javaw.exe as malware, not thinking too much of it i deleted the file causing this error.  Unable to start Java. Error details: The requested operation requires elevation. Filename on disk: javaw.exe Path: C:\Users\---\curseforge\minecraft\Install\runtime\java-runtime-gamma\windows-x64\java-runtime-gamma\bin\javaw.exe Exists: File I reinstalled the file, same error occurred. I deleted CurseForge, over wolf and Minecraft and reinstalled them. Same error occurring. I have read starting Minecraft in administrator mode will help. I attempted to launch Minecraft through CurseForge in administrative mode this did not help.  I updated and downloaded the newest version of java, again receiving the same error. I updated Malwarebytes authorizing settings to allow for Javaw.exe through the pathway C:\Users\jacob\curseforge\minecraft\Install\runtime\java-runtime-gamma\windows-x64\java-runtime-gamma\bin\javaw.exe this did not assist either.  I am unsure of what to try next or what i am missing, i am not an expert with the complexities of these systems but any help to teach me or assist in problem solving would help. I also cannot find any debug logs or crash logs based on this specific circumstance.  The only thing that pops up when I search debug through the files is https://pastebin.com/WqMEvEn6.    
    • I have been trying my hardest to find the method to detect if the player is on the ground. I looked it up and people just say it like onGround always works, or isOnGround always works. Nothing shows up for me and the wording is red. I tried looking up an import but it doesn't seem to exist. I had to same issue with hasGlint, which turned out to be in the Item class and was isFoil instead. I even found the checkfalldamage method in the Living Entity class (I found this through looking at isFallFlying method and looking at usages) but it  uses its own variable to see if the player is on the ground, and I have NO idea where it gets that from! (It is called pOnGround) I am using Intellij, SDk 21, Language level 17, and the Forge version is 1.20.1-47.1.0. I Don't know where to look anymore and I feel like im going crazy.
    • I have been trying my hardest to find the method to detect if the player is on the ground. I looked it up and people just say it like onGround always works, or isOnGround always works. Nothing shows up for me and the wording is red. I tried looking up an import but it doesn't seem to exist. I had to same issue with hasGlint, which turned out to be in the Item class and was isFoil instead. I even found the checkfalldamage method in the Living Entity class (I found this through looking at isFallFlying method and looking at usages) but it  uses its own variable to see if the player is on the ground, and I have NO idea where it gets that from! (It is called pOnGround) I am using Intellij, SDk 21, Language level 17, and the Forge version is 1.20.1-47.1.0. I Don't know where to look anymore and I feel like im going crazy.
  • Topics

×
×
  • Create New...

Important Information

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