diff --git a/res/shaders/main.frag b/res/shaders/main.frag index 78afc2d..bf504cb 100644 --- a/res/shaders/main.frag +++ b/res/shaders/main.frag @@ -10,8 +10,6 @@ uniform vec4 diffuse_light_color; uniform vec4 ambient_light; -out vec4 frag_color; - void main(){ vec3 lightDir; float lightIntensity; @@ -34,5 +32,5 @@ void main(){ // Clamp the final light color. color1 = clamp(color1, 0.0f, 1.0f); - frag_color = color1 * texture2D(myTexture,out_coord_texture); + gl_FragColor = color1 * texture2D(myTexture,out_coord_texture); } \ No newline at end of file diff --git a/src/mrdev023/gameengine/GameEngine.java b/src/mrdev023/gameengine/GameEngine.java index 4dbf32c..b9f7558 100644 --- a/src/mrdev023/gameengine/GameEngine.java +++ b/src/mrdev023/gameengine/GameEngine.java @@ -52,7 +52,7 @@ public class GameEngine { System.out.println("---------------------------- Load Audio File -----------------------------------------"); try { a = new Audio("res/audio/test.wav"); - a.playSound(); +// a.playSound(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -93,7 +93,6 @@ public class GameEngine { TICKS = 0; Timer.setValue("info", Timer.getNanoTime("info") - 1000000000); } - } destroy(); } diff --git a/src/mrdev023/gamestate/MainMenu.java b/src/mrdev023/gamestate/MainMenu.java index 140cc99..ee9906f 100644 --- a/src/mrdev023/gamestate/MainMenu.java +++ b/src/mrdev023/gamestate/MainMenu.java @@ -3,7 +3,7 @@ package mrdev023.gamestate; import java.util.ArrayList; import org.lwjgl.glfw.*; - +import org.lwjgl.opengl.*; import mrdev023.entity.*; import mrdev023.gameengine.*; @@ -17,10 +17,10 @@ import mrdev023.utils.*; public class MainMenu extends Game implements IGameState{ - public VAO vao,cube; public int time = 0; public static final float speed = 1.0f; public ArrayList lights; + public ArrayList meshs; public TextFont text; public void update() { @@ -66,37 +66,37 @@ public class MainMenu extends Game implements IGameState{ } public void init() { + //Ajout de la lumiere sur la scene lights = new ArrayList(); - lights.add(new AmbientLight(new Vector3f(100,100,100),Color4f.WHITE,Color4f.mul(Color4f.WHITE,1.0f))); - vao = MeshBuilder.createFloor(400, Color4f.WHITE,Texture.FLOOR); - cube = MeshBuilder.createCube(100, Color4f.WHITE,Texture.WOOD); + lights.add(new AmbientLight(new Vector3f(100,100,100),Color4f.WHITE,Color4f.WHITE)); +// lights.add(new AmbientLight(new Vector3f(100,100,100),Color4f.WHITE,Color4f.WHITE)); + //Ajout des Objets sur la scene + meshs = new ArrayList(); + meshs.add(new Mesh(MeshBuilder.createFloor(400, Color4f.WHITE,Texture.FLOOR),(new Matrix4f()).loadIdentity())); + meshs.add(new Mesh(MeshBuilder.createCube(100, Color4f.WHITE,Texture.WOOD),(new Matrix4f()).loadIdentity().tranlate(0, 200, 0))); text = new TextFont("Test", 10, 10, 16, Color4f.WHITE); } public void render2D() { - text.drawText(); + } public void render3D() { for(Light light : lights){ - light.drawLight(); - Matrix4f mvp = new Matrix4f(); - mvp.loadIdentity(); - Shader.MAIN.uniform("transform", mvp); - vao.render3D(); - mvp.tranlate(0, 200, 0); - Shader.MAIN.uniform("transform", mvp); - cube.render3D(); + for(Mesh mesh : meshs){ + light.drawLight(); + Shader.MAIN.uniform("transform", mesh.getTransform()); + mesh.getVao().render3D(); + } } } public void renderGUI() { - + text.drawText(); } public void destroy() { - vao.destroy(); - cube.destroy(); + for(Mesh mesh : meshs)mesh.getVao().destroy(); } } diff --git a/src/mrdev023/math/Color4f.java b/src/mrdev023/math/Color4f.java index 401fa47..6a91dac 100644 --- a/src/mrdev023/math/Color4f.java +++ b/src/mrdev023/math/Color4f.java @@ -27,8 +27,40 @@ public class Color4f { return new Color4f(a.r * b,a.g * b,a.b * b,a.a * b); } - public static Color4f mul (Color4f a, Color4f b){ - return new Color4f((a.r + b.r)/2.0f,(a.g + b.g)/2.0f,(a.b + b.b)/2.0f,(a.a + b.a)/2.0f); + public static Color4f mul (float o,Color4f... a){ + float r = 0; + float b = 0; + float g = 0; + float al = 0; + for(Color4f c : a){ + r += c.r; + g += c.g; + b += c.b; + al += c.a; + } + r /= a.length; + g /= a.length; + b /= a.length; + al /= a.length; + return new Color4f(r * o,g * o,b * o,al * o); + } + + public static Color4f mul (Color4f... a){ + float r = 0; + float b = 0; + float g = 0; + float al = 0; + for(Color4f c : a){ + r += c.r; + g += c.g; + b += c.b; + al += c.a; + } + r /= a.length; + g /= a.length; + b /= a.length; + al /= a.length; + return new Color4f(r,g,b,al); } public Color4f() { diff --git a/src/mrdev023/math/Matrix4f.java b/src/mrdev023/math/Matrix4f.java index 27fc464..f7b192d 100644 --- a/src/mrdev023/math/Matrix4f.java +++ b/src/mrdev023/math/Matrix4f.java @@ -22,13 +22,14 @@ public class Matrix4f { this.m = m; } - public void loadIdentity(){ + public Matrix4f loadIdentity(){ m = new float[][]{ {1,0,0,0}, {0,1,0,0}, {0,0,1,0}, {0,0,0,1} }; + return this; } public void rotate(Quaternion q){ @@ -76,7 +77,7 @@ public class Matrix4f { return mat; } - public void tranlate(float x,float y,float z){ + public Matrix4f tranlate(float x,float y,float z){ Matrix4f mat = new Matrix4f(new float[][]{ {1,0,0,x}, {0,1,0,y}, @@ -84,6 +85,7 @@ public class Matrix4f { {0,0,0,1} }); m = mul(mat).getM(); + return this; } public void scale(float x,float y,float z){ diff --git a/src/mrdev023/model/Mesh.java b/src/mrdev023/model/Mesh.java new file mode 100644 index 0000000..cf691c1 --- /dev/null +++ b/src/mrdev023/model/Mesh.java @@ -0,0 +1,34 @@ +package mrdev023.model; + +import mrdev023.math.*; +import mrdev023.rendering.*; + +public class Mesh { + + private VAO vao; + private Matrix4f transform; + + public Mesh(VAO vao,Matrix4f mat){ + this.vao = vao; + this.transform = mat; + } + + public VAO getVao() { + return vao; + } + + public void setVao(VAO vao) { + this.vao = vao; + } + + public Matrix4f getTransform() { + return transform; + } + + public void setTransform(Matrix4f transform) { + this.transform = transform; + } + + + +} diff --git a/src/mrdev023/opengl/DisplayManager.java b/src/mrdev023/opengl/DisplayManager.java index 133f70f..c2ce6a6 100644 --- a/src/mrdev023/opengl/DisplayManager.java +++ b/src/mrdev023/opengl/DisplayManager.java @@ -37,6 +37,8 @@ public class DisplayManager { glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); + glEnable (GL_BLEND); + glBlendFunc (GL_ONE, GL_ONE); } public static void preRenderGUI(){ diff --git a/src/mrdev023/rendering/VAO.java b/src/mrdev023/rendering/VAO.java index 4e1662d..c266914 100644 --- a/src/mrdev023/rendering/VAO.java +++ b/src/mrdev023/rendering/VAO.java @@ -55,6 +55,23 @@ public class VAO { glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 2, GL_FLOAT, false, (2 + 3 + 4 + 2) * SIZE_OF_FLOAT, 0); + + glEnableVertexAttribArray(3); + glVertexAttribPointer(3, 3, GL_FLOAT, false, (2 + 3 + 4 + 2) * SIZE_OF_FLOAT, 2 * SIZE_OF_FLOAT); + + glEnableVertexAttribArray(1); + glVertexAttribPointer(1, 4, GL_FLOAT, false, (2 + 3 + 4 + 2) * SIZE_OF_FLOAT, (2 + 3) * SIZE_OF_FLOAT); + + glEnableVertexAttribArray(2); + glVertexAttribPointer(2, 2, GL_FLOAT, false, (2 + 3 + 4 + 2) * SIZE_OF_FLOAT, (2 + 3 + 4) * SIZE_OF_FLOAT); + + glDisableVertexAttribArray(0); + glDisableVertexAttribArray(1); + glDisableVertexAttribArray(2); + glDisableVertexAttribArray(3); + glBindVertexArray(0); size = data.size(); } @@ -69,11 +86,6 @@ public class VAO { glEnableVertexAttribArray(2); glEnableVertexAttribArray(3); - glVertexAttribPointer(0, 2, GL_FLOAT, false, (2 + 3 + 4 + 2) * SIZE_OF_FLOAT, 0); - glVertexAttribPointer(3, 3, GL_FLOAT, false, (2 + 3 + 4 + 2) * SIZE_OF_FLOAT, 2 * SIZE_OF_FLOAT); - glVertexAttribPointer(1, 4, GL_FLOAT, false, (2 + 3 + 4 + 2) * SIZE_OF_FLOAT, (2 + 3) * SIZE_OF_FLOAT); - glVertexAttribPointer(2, 2, GL_FLOAT, false, (2 + 3 + 4 + 2) * SIZE_OF_FLOAT, (2 + 3 + 4) * SIZE_OF_FLOAT); - glDrawArrays(GL_QUADS, 0, size/(2 + 3 + 4 + 2)); glDisableVertexAttribArray(0);