drawing sprite back to front
This commit is contained in:
parent
7a79c19c98
commit
8506065de0
@ -8,5 +8,5 @@ uniform sampler2D texture1;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = texture(texture1, vec2(texCoord.y, -texCoord.x));
|
||||
FragColor = texture(texture1, vec2(-texCoord.y, -texCoord.x));
|
||||
}
|
@ -9,5 +9,5 @@ uniform sampler2D texture1;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = texture(texture1, vec2(texCoord.y, -texCoord.x)) * color;
|
||||
FragColor = texture(texture1, vec2(-texCoord.y, -texCoord.x)) * color;
|
||||
}
|
@ -7,6 +7,7 @@ import org.lwjgl.glfw.GLFWVidMode;
|
||||
import org.lwjgl.opengl.GL;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
@ -93,6 +94,8 @@ public class Engine {
|
||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
objectsGl.sort(new SortZ());
|
||||
// TODO trié en fonction de la distance z sinon bug d'affichage
|
||||
for (ObjectGl objectGl : objectsGl) {
|
||||
objectGl.render();
|
||||
}
|
||||
@ -104,7 +107,6 @@ public class Engine {
|
||||
|
||||
public void add_objectGl(ObjectGl obj){
|
||||
objectsGl.add(obj);
|
||||
// TODO trié en fonction de la distance z sinon bug d'affichage
|
||||
}
|
||||
|
||||
public void remove_objectGl(ObjectGl obj){
|
||||
@ -140,18 +142,18 @@ public class Engine {
|
||||
|
||||
// Add objects to render
|
||||
List<String> path = new ArrayList<>();
|
||||
path.add("textures/awesomeface.png");
|
||||
path.add("textures/zangief_sprite.png");
|
||||
|
||||
ObjectGl smiley = new ObjectGlTex(-0.5f,0.5f,0.0f,500.0f,500.0f, path, Primitive.stdTexWrap);
|
||||
ObjectGl smiley = new ObjectGlTex(-200.5f,200.5f,0.0f,320.0f*6,578.0f*6, path, Primitive.stdTexWrap);
|
||||
engine.add_objectGl(smiley);
|
||||
smiley.translate(new Vector3f(-2.5f,0.0f,0.0f));
|
||||
smiley.translate(new Vector3f(-600.0f,0.0f,9.0f));
|
||||
|
||||
ObjectGl smiley2 = new ObjectGlTex(-0.5f,0.5f,0.0f,500.0f,500.0f, path, Primitive.stdTexWrap);
|
||||
engine.add_objectGl(smiley2);
|
||||
smiley2.translate(new Vector3f(0.0f,0.0f,10.0f));
|
||||
smiley2.translate(new Vector3f(0.0f,0.0f,5.0f));
|
||||
|
||||
long timer = System.currentTimeMillis();
|
||||
long lastFrame = System.currentTimeMillis();
|
||||
long lastFrame;
|
||||
int frame = 0;
|
||||
boolean nextFrame = false;
|
||||
|
||||
@ -160,7 +162,7 @@ public class Engine {
|
||||
double time = glfwGetTime();
|
||||
lastFrame = System.currentTimeMillis();
|
||||
|
||||
smiley.translate(new Vector3f( (float) Math.sin(time), (float) Math.cos(time), 0.0f));
|
||||
smiley.translate(new Vector3f( (float) Math.sin(time)*5, (float) Math.cos(time)*5, 0.0f));
|
||||
|
||||
smiley2.rotateZ(0.8f);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user