Jump to content

Custom Class Binding Textures with GL vs. Using Minecraft's resource loader/manager


Recommended Posts

Posted

I've been looking at various source code on github to self-teach myself the various approaches to the custom special effects that mods such as Betweenlands, Astral Sorcery, etc. have that allow fading in and out particles, and one thing I noticed was that sometimes the modder makes their own class to bind the textures using a GL11 method:

Spoiler

package com.ninja3659.explorationexpansion.client.particle.util;

import org.lwjgl.opengl.GL11;

import com.ninja3659.explorationexpansion.util.Utils;

import akka.japi.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.SimpleTexture;
import net.minecraft.client.renderer.texture.TextureUtil;
import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

/**
 * Purpose of the Class: to bind the png texture id to a variable so that we can call the resource location. Essentially we are making our own Resource location handler
 * @author JEHan
 * 
 * {@link IResourceManagerReloadListener}
 *
 */

@SideOnly(Side.CLIENT)
public class BindableResource {
	//we need an ITO to load the texture
	private ITextureObject resource = null;//we set the ITO as null so that we initialize it and can use it
	private String path;//where it is located
	
	public BindableResource(String path) {
		this.path = path;
	}
	
	public String getPath() {
		return path;
	}
	
	public boolean isInitialized() {
		return resource != null;
	}
	
	public ITextureObject getResource() {
		return resource;
	}
	
	public void allocateGlId() {
		if (resource != null) return; //if the resource is already full, we don't need another
		resource = new SimpleTexture(new ResourceLocation(path));//establishes the resource
		try {
			resource.loadTexture(Minecraft.getMinecraft().getResourceManager());
		} catch (Exception e) {
			Utils.getLogger().error("EE Failed to load texture " + path);
			e.printStackTrace();//prits out error
			resource = TextureUtil.MISSING_TEXTURE;//sets texture to missing texture
			return;//finished
		}
	}
	
	public void bind() {
		if (resource == null) {
			allocateGlId();
		}
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, resource.getGlTextureId());
	}
}

I inputted the comments to help better understand the function of everything in the class

My question is what benefit does creating your own Resource-Binding class in terms of sprites and sprite sheets compared to using what is already built in to the game? Sorry if there isn't enough information or if this is in the wrong place, this is my first time attempting something more involved than the basic mob, block, etc. If this sorta thing requires understanding GL, is there anywhere I can learn about it?

Posted

You could do your own implementation, but what would be the advantage?

Minecraft does the same thing for you when you call 'TextureManager::bindTexture':


Personal I see no reasonable benefit from doing like it. It's just a: "I don't like how Minecraft it does" thing.

But correct me if someone think this is better.

Posted

One reason for it could be that sometimes the forge guys like to “mix things up a bit” and change the way things load, making updating a Royal pain, so by setting up your own implementation you sidestep that so you don’t have to worry about depreciated methods and completely revamped elements. I’d be willing to tempt it if I had the java experience and the time

Posted (edited)

That's a good point, but I don't thing the forge team make things worse, they try to optimize things.

I think only in 1.13 the loading could change, but more from the reason that minecraft updates to lwjgl 3. So you have to change it in your code anyways.

 

At the end it's up to you, if you know what you do, it's fine. :)

Edited by Lhykos

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

    • UPDATE: this seems to be an Arch-specific issue. Switching to Ubuntu server fixed EVERYTHING.
    • Yes, Attapoll offers a $20 Sign-up bonus for new users using a code (AOVCQ). Enter the Attapoll Referral Code “AOVCQ” and submit. Yes, Attapoll offers $20 Referral Code {AOVCQ} For New Customers. If you are who wish to join Attapoll, then you should use this exclusive Attapoll referral code $20 Signup Bonus Use this Code (AOVCQ) and get $20 Welcome Bonus. You can get a $20 Signup bonus use this referral code {AOVCQ}. You can get a $20 Attpoll Referral Code {AOVCQ}. This Attapoll $20 Referral code is specifically for existing customers and can be redeemed to receive a $20. Enter $20 Attapoll Referral Code {AOVCQ} at checkout. Enjoy $20Welcome Bonus. Use the best Attapoll referral code $20 (AOVCQ) to get up to $20 first time survey as a new user. Complete the survey and get $20 credited on your Attapoll account. Plus, refer your friend to earn 10% commission on their earning If you're on the hunt for a little extra cash or some cool rewards without too much hassle, you've landed in the right place. Today, we're diving into the world of Attapoll referral codes, a nifty way to boost your earnings while taking surveys. Use this Attapoll Referral Link or code {{AOVCQ}} to get a $20 sign up bonus.
    • Yes, Attapoll offers a $20 Sign-up bonus for new users using a code (AOVCQ). Enter the Attapoll Referral Code “AOVCQ” and submit. Yes, Attapoll offers $20 Referral Code {AOVCQ} For New Customers. If you are who wish to join Attapoll, then you should use this exclusive Attapoll referral code $20 Signup Bonus Use this Code (AOVCQ) and get $20 Welcome Bonus. You can get a $20 Signup bonus use this referral code {AOVCQ}. You can get a $20 Attpoll Referral Code {AOVCQ}. This Attapoll $20 Referral code is specifically for existing customers and can be redeemed to receive a $20. Enter $20 Attapoll Referral Code {AOVCQ} at checkout. Enjoy $20Welcome Bonus. Use the best Attapoll referral code $20 (AOVCQ) to get up to $20 first time survey as a new user. Complete the survey and get $20 credited on your Attapoll account. Plus, refer your friend to earn 10% commission on their earning If you're on the hunt for a little extra cash or some cool rewards without too much hassle, you've landed in the right place. Today, we're diving into the world of Attapoll referral codes, a nifty way to boost your earnings while taking surveys. Use this Attapoll Referral Link or code {{AOVCQ}} to get a $20 sign up bonus.
    • Yes, Attapoll offers a $20 Sign-up bonus for new users using a code (AOVCQ). Enter the Attapoll Referral Code “AOVCQ” and submit. Yes, Attapoll offers $20 Referral Code {AOVCQ} For New Customers. If you are who wish to join Attapoll, then you should use this exclusive Attapoll referral code $20 Signup Bonus Use this Code (AOVCQ) and get $20 Welcome Bonus. You can get a $20 Signup bonus use this referral code {AOVCQ}. You can get a $20 Attpoll Referral Code {AOVCQ}. This Attapoll $20 Referral code is specifically for existing customers and can be redeemed to receive a $20. Enter $20 Attapoll Referral Code {AOVCQ} at checkout. Enjoy $20Welcome Bonus. Use the best Attapoll referral code $20 (AOVCQ) to get up to $20 first time survey as a new user. Complete the survey and get $20 credited on your Attapoll account. Plus, refer your friend to earn 10% commission on their earning If you're on the hunt for a little extra cash or some cool rewards without too much hassle, you've landed in the right place. Today, we're diving into the world of Attapoll referral codes, a nifty way to boost your earnings while taking surveys. Use this Attapoll Referral Link or code {{AOVCQ}} to get a $20 sign up bonus.
    • Yes, Attapoll offers a $20 Sign-up bonus for new users using a code (AOVCQ). Enter the Attapoll Referral Code “AOVCQ” and submit. Yes, Attapoll offers $20 Referral Code {AOVCQ} For New Customers. If you are who wish to join Attapoll, then you should use this exclusive Attapoll referral code $20 Signup Bonus Use this Code (AOVCQ) and get $20 Welcome Bonus. You can get a $20 Signup bonus use this referral code {AOVCQ}. You can get a $20 Attpoll Referral Code {AOVCQ}. This Attapoll $20 Referral code is specifically for existing customers and can be redeemed to receive a $20. Enter $20 Attapoll Referral Code {AOVCQ} at checkout. Enjoy $20Welcome Bonus. Use the best Attapoll referral code $20 (AOVCQ) to get up to $20 first time survey as a new user. Complete the survey and get $20 credited on your Attapoll account. Plus, refer your friend to earn 10% commission on their earning If you're on the hunt for a little extra cash or some cool rewards without too much hassle, you've landed in the right place. Today, we're diving into the world of Attapoll referral codes, a nifty way to boost your earnings while taking surveys. Use this Attapoll Referral Link or code {{AOVCQ}} to get a $20 sign up bonus.
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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