Hi, I’m trying to make shaders in my Program, I have this code that loads a simple vertex Shader from his name to find it in the resources
folder :
public void init() throws FileNotFoundException {
try {
Registry.register(getShader("fragment"), "basic");
} catch (Exception e) {
e.printStackTrace();
}
}
public PShader getShader(String fragName) throws FileNotFoundException {
String path = "src\\main\\resources\\shaders\\" + fragName + ".glsl";
File file = new File(path);
if (file.exists()) {
Logger.info("Fragment Shader " + file.getAbsolutePath() + " found.", "ShaderMapping");
return sketch.loadShader(file.getAbsolutePath());
} else {
throw new FileNotFoundException("File " + file.getAbsolutePath() + " not found.");
}
}
It register it into my Registry, all this happens in the setting
function.
In the draw
function at a point I do this :
Registry.getShaders().forEach((name, shader) -> {
sketch.shader(shader);
});
To draw them.
BUT
In my loading part (in my setting
function), where it loads the shader, I get this error :
java.lang.NullPointerException
at processing.core.PApplet.loadShader(PApplet.java:11729)
at main.java.fr.ayfri.Minecraft.utils.ShaderManager.getShader(ShaderManager.java:30)
at main.java.fr.ayfri.Minecraft.utils.ShaderManager.init(ShaderManager.java:18)
at main.java.fr.ayfri.Minecraft.Minecraft.<init>(Minecraft.java:28)
at main.java.fr.ayfri.Minecraft.Main.settings(Main.java:27)
at processing.core.PApplet.handleSettings(PApplet.java:978)
at processing.core.PApplet.runSketch(PApplet.java:10897)
at main.java.fr.ayfri.Minecraft.Main.main(Main.java:16)
What I think that is oddly is that the Logger says it FINDS the shaders, without errors, it’s just where it load these that it send the error.
Look at my screen for proof. http://prntscr.com/s44ti5