diff --git a/src/engine/object/HorizontalProgressBar.java b/src/engine/object/HorizontalProgressBar.java index 5648628..2ff24aa 100644 --- a/src/engine/object/HorizontalProgressBar.java +++ b/src/engine/object/HorizontalProgressBar.java @@ -4,7 +4,7 @@ import engine.math.Vector3f; import static org.lwjgl.glfw.GLFW.glfwGetTime; -public class HorizontalProgressBar extends ObjectGl{ +public class HorizontalProgressBar extends ObjectGl { private float max; private float current; @@ -18,24 +18,18 @@ public class HorizontalProgressBar extends ObjectGl{ this.setShader("shaders/StylishShaders/BasicNoTexVert.glsl", "shaders/StylishShaders/HorizontalProgressBar.glsl"); } - public void setCurrent(float newCurrent){ + public void setCurrent(float newCurrent) { this.current = newCurrent; } - public void setMax(float newMax){ + public void setMax(float newMax) { this.max = newMax; } - /** - * Do shader binding, texture binding and vertexArray drawing - */ - public void render(){ - - this.shader.enable(); - + protected void uniformInjection() { if (this.useTime) this.shader.setUniform1f("time", (float) glfwGetTime()); - if (this.leftToRight == 1){ + if (this.leftToRight == 1) { this.shader.setUniform1f("fill", (this.current / this.max) * this.getWidth()); } else { this.shader.setUniform1f("fill", Math.abs(((this.current / this.max) * this.getWidth()) - this.getWidth())); @@ -46,9 +40,5 @@ public class HorizontalProgressBar extends ObjectGl{ this.shader.setUniformMat4f("projection", projection); this.shader.setUniformMat4f("view", view); this.shader.setUniformMat4f("transform", this.transform); - - this.vertexArray.render(); - - this.shader.disable(); } } diff --git a/src/engine/object/Letter.java b/src/engine/object/Letter.java index d69819e..330c0d9 100644 --- a/src/engine/object/Letter.java +++ b/src/engine/object/Letter.java @@ -19,21 +19,13 @@ public class Letter extends ObjectGl { this.indexBasedShader = b; } - public void render(){ - - this.shader.enable(); - if (this.texture != null) this.texture.bind(); - + protected void uniformInjection(){ if (this.useTime) this.shader.setUniform1f("time", (float) glfwGetTime()); if (this.indexBasedShader) this.shader.setUniform1i("index",this.index); this.shader.setUniformMat4f("projection", projection); this.shader.setUniformMat4f("view", view); this.shader.setUniformMat4f("transform", this.transform); - - this.vertexArray.render(); - - if (this.texture != null) this.texture.unbind(); - this.shader.disable(); } + } diff --git a/src/engine/object/ObjectGl.java b/src/engine/object/ObjectGl.java index b50a919..994169c 100644 --- a/src/engine/object/ObjectGl.java +++ b/src/engine/object/ObjectGl.java @@ -265,6 +265,14 @@ public class ObjectGl { return scalingFactor; } + protected void uniformInjection(){ + if (this.useTime) this.shader.setUniform1f("time", (float) glfwGetTime()); + + this.shader.setUniformMat4f("projection", projection); + this.shader.setUniformMat4f("view", view); + this.shader.setUniformMat4f("transform", this.transform); + } + /** * Do shader binding, texture binding and vertexArray drawing */ @@ -273,11 +281,7 @@ public class ObjectGl { this.shader.enable(); if (this.texture != null) this.texture.bind(); - if (this.useTime) this.shader.setUniform1f("time", (float) glfwGetTime()); - - this.shader.setUniformMat4f("projection", projection); - this.shader.setUniformMat4f("view", view); - this.shader.setUniformMat4f("transform", this.transform); + this.uniformInjection(); this.vertexArray.render();