drawing sprite back to front
This commit is contained in:
@ -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){
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
11
src/engine/object/SortZ.java
Normal file
11
src/engine/object/SortZ.java
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user