58 lines
1.6 KiB
Java
58 lines
1.6 KiB
Java
package io.github.hydos.ginger.engine.render.renderers;
|
|
|
|
import java.util.List;
|
|
|
|
import org.joml.Matrix4f;
|
|
import org.lwjgl.opengl.GL11;
|
|
import org.lwjgl.opengl.GL13;
|
|
import org.lwjgl.opengl.GL20;
|
|
import org.lwjgl.opengl.GL30;
|
|
|
|
import io.github.hydos.ginger.engine.elements.GuiTexture;
|
|
import io.github.hydos.ginger.engine.math.Maths;
|
|
import io.github.hydos.ginger.engine.render.models.RawModel;
|
|
import io.github.hydos.ginger.engine.render.shaders.GuiShader;
|
|
import io.github.hydos.ginger.engine.utils.Loader;
|
|
|
|
public class GuiRenderer
|
|
{
|
|
private final RawModel quad;
|
|
private GuiShader shader;
|
|
|
|
public GuiRenderer(GuiShader shader)
|
|
{
|
|
this.shader = shader;
|
|
float[] positions =
|
|
{
|
|
-1, 1, -1, -1, 1, 1, 1, -1
|
|
};
|
|
quad = Loader.loadToVAO(positions, 2);
|
|
}
|
|
|
|
public void render(List<GuiTexture> guis)
|
|
{
|
|
shader.start();
|
|
GL30.glBindVertexArray(quad.getVaoID());
|
|
GL20.glEnableVertexAttribArray(0);
|
|
GL11.glEnable(GL11.GL_BLEND);
|
|
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
|
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
|
for (GuiTexture gui : guis)
|
|
{
|
|
GL13.glActiveTexture(GL13.GL_TEXTURE0);
|
|
GL11.glBindTexture(GL11.GL_TEXTURE_2D, gui.getTexture());
|
|
Matrix4f matrix = Maths.createTransformationMatrix(gui.getPosition(), gui.getScale());
|
|
shader.loadTransformation(matrix);
|
|
GL11.glDrawArrays(GL11.GL_TRIANGLE_STRIP, 0, quad.getVertexCount());
|
|
}
|
|
GL11.glDisable(GL11.GL_BLEND);
|
|
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
|
GL20.glDisableVertexAttribArray(0);
|
|
GL30.glBindVertexArray(0);
|
|
shader.stop();
|
|
}
|
|
|
|
public void cleanUp()
|
|
{ shader.cleanUp(); }
|
|
}
|