1
0
Fork 0
This commit is contained in:
Florian Richer (MrDev023) 2016-03-12 18:01:40 +01:00
parent b1e5605a64
commit 4abf461bf6
8 changed files with 110 additions and 31 deletions

View file

@ -10,8 +10,6 @@ uniform vec4 diffuse_light_color;
uniform vec4 ambient_light; uniform vec4 ambient_light;
out vec4 frag_color;
void main(){ void main(){
vec3 lightDir; vec3 lightDir;
float lightIntensity; float lightIntensity;
@ -34,5 +32,5 @@ void main(){
// Clamp the final light color. // Clamp the final light color.
color1 = clamp(color1, 0.0f, 1.0f); color1 = clamp(color1, 0.0f, 1.0f);
frag_color = color1 * texture2D(myTexture,out_coord_texture); gl_FragColor = color1 * texture2D(myTexture,out_coord_texture);
} }

View file

@ -52,7 +52,7 @@ public class GameEngine {
System.out.println("---------------------------- Load Audio File -----------------------------------------"); System.out.println("---------------------------- Load Audio File -----------------------------------------");
try { try {
a = new Audio("res/audio/test.wav"); a = new Audio("res/audio/test.wav");
a.playSound(); // a.playSound();
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -93,7 +93,6 @@ public class GameEngine {
TICKS = 0; TICKS = 0;
Timer.setValue("info", Timer.getNanoTime("info") - 1000000000); Timer.setValue("info", Timer.getNanoTime("info") - 1000000000);
} }
} }
destroy(); destroy();
} }

View file

@ -3,7 +3,7 @@ package mrdev023.gamestate;
import java.util.ArrayList; import java.util.ArrayList;
import org.lwjgl.glfw.*; import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
import mrdev023.entity.*; import mrdev023.entity.*;
import mrdev023.gameengine.*; import mrdev023.gameengine.*;
@ -17,10 +17,10 @@ import mrdev023.utils.*;
public class MainMenu extends Game implements IGameState{ public class MainMenu extends Game implements IGameState{
public VAO vao,cube;
public int time = 0; public int time = 0;
public static final float speed = 1.0f; public static final float speed = 1.0f;
public ArrayList<Light> lights; public ArrayList<Light> lights;
public ArrayList<Mesh> meshs;
public TextFont text; public TextFont text;
public void update() { public void update() {
@ -66,37 +66,37 @@ public class MainMenu extends Game implements IGameState{
} }
public void init() { public void init() {
//Ajout de la lumiere sur la scene
lights = new ArrayList<Light>(); lights = new ArrayList<Light>();
lights.add(new AmbientLight(new Vector3f(100,100,100),Color4f.WHITE,Color4f.mul(Color4f.WHITE,1.0f))); lights.add(new AmbientLight(new Vector3f(100,100,100),Color4f.WHITE,Color4f.WHITE));
vao = MeshBuilder.createFloor(400, Color4f.WHITE,Texture.FLOOR); // lights.add(new AmbientLight(new Vector3f(100,100,100),Color4f.WHITE,Color4f.WHITE));
cube = MeshBuilder.createCube(100, Color4f.WHITE,Texture.WOOD); //Ajout des Objets sur la scene
meshs = new ArrayList<Mesh>();
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); text = new TextFont("Test", 10, 10, 16, Color4f.WHITE);
} }
public void render2D() { public void render2D() {
text.drawText();
} }
public void render3D() { public void render3D() {
for(Light light : lights){ for(Light light : lights){
light.drawLight(); for(Mesh mesh : meshs){
Matrix4f mvp = new Matrix4f(); light.drawLight();
mvp.loadIdentity(); Shader.MAIN.uniform("transform", mesh.getTransform());
Shader.MAIN.uniform("transform", mvp); mesh.getVao().render3D();
vao.render3D(); }
mvp.tranlate(0, 200, 0);
Shader.MAIN.uniform("transform", mvp);
cube.render3D();
} }
} }
public void renderGUI() { public void renderGUI() {
text.drawText();
} }
public void destroy() { public void destroy() {
vao.destroy(); for(Mesh mesh : meshs)mesh.getVao().destroy();
cube.destroy();
} }
} }

View file

@ -27,8 +27,40 @@ public class Color4f {
return new Color4f(a.r * b,a.g * b,a.b * b,a.a * b); return new Color4f(a.r * b,a.g * b,a.b * b,a.a * b);
} }
public static Color4f mul (Color4f a, Color4f b){ public static Color4f mul (float o,Color4f... a){
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); 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() { public Color4f() {

View file

@ -22,13 +22,14 @@ public class Matrix4f {
this.m = m; this.m = m;
} }
public void loadIdentity(){ public Matrix4f loadIdentity(){
m = new float[][]{ m = new float[][]{
{1,0,0,0}, {1,0,0,0},
{0,1,0,0}, {0,1,0,0},
{0,0,1,0}, {0,0,1,0},
{0,0,0,1} {0,0,0,1}
}; };
return this;
} }
public void rotate(Quaternion q){ public void rotate(Quaternion q){
@ -76,7 +77,7 @@ public class Matrix4f {
return mat; 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[][]{ Matrix4f mat = new Matrix4f(new float[][]{
{1,0,0,x}, {1,0,0,x},
{0,1,0,y}, {0,1,0,y},
@ -84,6 +85,7 @@ public class Matrix4f {
{0,0,0,1} {0,0,0,1}
}); });
m = mul(mat).getM(); m = mul(mat).getM();
return this;
} }
public void scale(float x,float y,float z){ public void scale(float x,float y,float z){

View file

@ -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;
}
}

View file

@ -37,6 +37,8 @@ public class DisplayManager {
glCullFace(GL_BACK); glCullFace(GL_BACK);
glEnable(GL_CULL_FACE); glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glEnable (GL_BLEND);
glBlendFunc (GL_ONE, GL_ONE);
} }
public static void preRenderGUI(){ public static void preRenderGUI(){

View file

@ -55,6 +55,23 @@ public class VAO {
glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, buffer, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0); 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); glBindVertexArray(0);
size = data.size(); size = data.size();
} }
@ -69,11 +86,6 @@ public class VAO {
glEnableVertexAttribArray(2); glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3); 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)); glDrawArrays(GL_QUADS, 0, size/(2 + 3 + 4 + 2));
glDisableVertexAttribArray(0); glDisableVertexAttribArray(0);