drawing sprite back to front

This commit is contained in:
Antoine
2021-05-20 15:52:20 +02:00
parent 7a79c19c98
commit 8506065de0
8 changed files with 31 additions and 9 deletions

View File

@ -6,6 +6,8 @@ import engine.graphics.Shader;
import engine.math.Matrix4f;
import engine.math.Vector3f;
import java.util.Comparator;
/**
*
*/
@ -18,6 +20,8 @@ public class ObjectGl {
public static Matrix4f projection;
public static Matrix4f view;
public float zPos;
public ObjectGl(){
}
@ -26,6 +30,7 @@ public class ObjectGl {
this.vertexArray = new VertexArray(Primitive.createRectangle(x, y, z, h, w), Primitive.rectangle_indices, null, null);
this.transform = Matrix4f.identity();
this.shader = new Shader("shaders/ObjectGl/vert.glsl","shaders/ObjectGl/frag.glsl");
this.zPos = z;
}
public void resetTransform(){
@ -34,6 +39,7 @@ public class ObjectGl {
public void translate(Vector3f vec){
this.transform = this.transform.multiply(Matrix4f.translate(vec));
this.zPos += vec.z;
}
public void scale(Vector3f vec){

View File

@ -11,5 +11,6 @@ public class ObjectGlColor extends ObjectGl{
this.vertexArray = new VertexArray(Primitive.createRectangle(x, y, z, h, w), Primitive.rectangle_indices, color, null);
this.transform = Matrix4f.identity();
this.shader = new Shader("shaders/ObjectGlColor/vert.glsl","shaders/ObjectGlColor/frag.glsl");
this.zPos = z;
}
}

View File

@ -22,6 +22,7 @@ public class ObjectGlTex extends ObjectGl{
this.vertexArray = new VertexArray(Primitive.createRectangle(x, y, z, h, w), Primitive.rectangle_indices, null, texCoord);
this.transform = Matrix4f.identity();
this.shader = new Shader("shaders/ObjectGlTex/vert.glsl","shaders/ObjectGlTex/frag.glsl");
this.zPos = z;
this.textures = new ArrayList<>();
int count = 0;

View File

@ -16,6 +16,7 @@ public class ObjectGlTexColor extends ObjectGlTex{
this.vertexArray = new VertexArray(Primitive.createRectangle(x, y, z, h, w), Primitive.rectangle_indices, color, texCoord);
this.transform = Matrix4f.identity();
this.shader = new Shader("shaders/ObjectGlTexColor/vert.glsl","shaders/ObjectGlTexColor/frag.glsl");
this.zPos = z;
this.textures = new ArrayList<>();
int count = 0;

View File

@ -0,0 +1,11 @@
package engine.object;
import java.util.Comparator;
public class SortZ implements Comparator<ObjectGl>
{
public int compare(ObjectGl a, ObjectGl b)
{
return (int) (a.zPos - b.zPos);
}
}