Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions src/main/java/cam72cam/mod/render/SpriteSheet.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cam72cam.mod.render;

import cam72cam.mod.render.opengl.DirectDraw;
import cam72cam.mod.render.opengl.RenderContext;
import cam72cam.mod.render.opengl.RenderState;
import cam72cam.mod.render.opengl.Texture;
Expand Down Expand Up @@ -50,7 +51,7 @@ private void allocateSheet() {
/** Allocate a slot in the sheet and write pixels to it */
public void setSprite(Identifier id, ByteBuffer pixels) {
if (!sprites.containsKey(id)) {
if (unallocated.size() == 0) {
if (unallocated.isEmpty()) {
allocateSheet();
}
sprites.put(id, unallocated.remove(0));
Expand All @@ -72,19 +73,12 @@ public void renderSprite(Identifier id) {
.texture(Texture.wrap(sprite.texID))
.rotate(180, 1, 0, 0)
.translate(0, -1, 0);
try (With ctx = RenderContext.apply(state)) {
GL11.glBegin(GL11.GL_QUADS);
GL11.glColor4f(1, 1, 1, 1);
GL11.glTexCoord2f(sprite.uMin, sprite.vMin);
GL11.glVertex3f(0, 0, 0);
GL11.glTexCoord2f(sprite.uMin, sprite.vMax);
GL11.glVertex3f(0, 1, 0);
GL11.glTexCoord2f(sprite.uMax, sprite.vMax);
GL11.glVertex3f(1, 1, 0);
GL11.glTexCoord2f(sprite.uMax, sprite.vMin);
GL11.glVertex3f(1, 0, 0);
GL11.glEnd();
};
DirectDraw buffer = new DirectDraw();
buffer.vertex(0, 0, 0).color(1, 1, 1, 1).uv(sprite.uMin, sprite.vMin);
buffer.vertex(0, 1, 0).color(1, 1, 1, 1).uv(sprite.uMin, sprite.vMax);
buffer.vertex(1, 1, 0).color(1, 1, 1, 1).uv(sprite.uMax, sprite.vMax);
buffer.vertex(1, 0, 0).color(1, 1, 1, 1).uv(sprite.uMax, sprite.vMin);
buffer.draw(state);
}

/** Remove a sprite from the sheet (does not reduce used GPU memory yet) */
Expand Down