hadean/src/main/java/xyz/valnet/engine/graphics/Drawing.java

42 lines
1.4 KiB
Java
Raw Normal View History

2022-05-18 07:46:03 -04:00
package xyz.valnet.engine.graphics;
import static org.lwjgl.opengl.GL20.*;
import xyz.valnet.engine.shaders.SimpleShader;
public class Drawing {
private static Texture bound = null;
public static void drawSprite(Sprite sprite, int x, int y) {
drawSprite(sprite, x, y, sprite.width, sprite.height);
}
2022-05-19 06:27:48 -04:00
private static float layer = 0f;
public static void setLayer(float layer) {
Drawing.layer = layer;
}
2022-05-18 07:46:03 -04:00
public static void drawSprite(Sprite sprite, int x, int y, int width, int height) {
// lazy texture binding
if(bound != sprite.atlas) {
if(bound != null) bound.unbind();
sprite.atlas.bind();
}
glBegin(GL_QUADS);
glVertexAttrib2f(SimpleShader.TEX_COORD, sprite.sourceBoxUV.x, sprite.sourceBoxUV.y);
2022-05-19 06:27:48 -04:00
glVertex3f(x, y, layer);
2022-05-18 07:46:03 -04:00
glVertexAttrib2f(SimpleShader.TEX_COORD, sprite.sourceBoxUV.x + sprite.sourceBoxUV.z, sprite.sourceBoxUV.y);
2022-05-19 06:27:48 -04:00
glVertex3f(x + width, y, layer);
2022-05-18 07:46:03 -04:00
glVertexAttrib2f(SimpleShader.TEX_COORD, sprite.sourceBoxUV.x + sprite.sourceBoxUV.z, sprite.sourceBoxUV.y + sprite.sourceBoxUV.w);
2022-05-19 06:27:48 -04:00
glVertex3f(x + width, y + height, layer);
2022-05-18 07:46:03 -04:00
glVertexAttrib2f(SimpleShader.TEX_COORD, sprite.sourceBoxUV.x, sprite.sourceBoxUV.y + sprite.sourceBoxUV.w);
2022-05-19 06:27:48 -04:00
glVertex3f(x, y + height, layer);
2022-05-18 07:46:03 -04:00
glEnd();
}
}