1
0
Fork 0

Bug Fixes

This commit is contained in:
MrDev023 2017-01-14 17:59:15 +01:00
parent 9124915237
commit 18bb7ab823
13 changed files with 469 additions and 272 deletions

View file

@ -44,14 +44,14 @@ public class Main {
};
// glfwSetErrorCallback(errorCallback);
if(glfwInit())throw new Exception("GLFW not init");
if(!glfwInit())throw new Exception("GLFW not init");
glfwDefaultWindowHints();
glfwWindowHint(GLFW_VISIBLE, GL11.GL_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GL11.GL_FALSE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
// glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
// glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
// glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
windowID = glfwCreateWindow(WIDTH,HEIGHT,TITLE,NULL,NULL);
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(windowID,(vidmode.width()-WIDTH)/2,(vidmode.height()-HEIGHT)/2);
@ -75,7 +75,7 @@ public class Main {
Camera.transform();
//------------------------------------------------------------------------------------
while(glfwWindowShouldClose(windowID)){
while(!glfwWindowShouldClose(windowID)){
if(System.currentTimeMillis() - previousTicks >= 1000/60){//Update TICKS
glfwPollEvents();

View file

@ -10,6 +10,7 @@ import globalgamejam.render.*;
public abstract class Game {
public Game(){
Camera.init();
init();
}

View file

@ -1,32 +1,37 @@
package globalgamejam.game;
import globalgamejam.*;
import globalgamejam.math.*;
import globalgamejam.render.*;
import globalgamejam.tiles.TestTile;
import globalgamejam.tiles.Tile;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
/**
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
*/
public class MainGame extends Game{
private float value = 0;
private ArrayList<Tile> tiles;
@Override
public void init() {
tiles = new ArrayList<Tile>();
TestTile t = new TestTile();
t.getTransform().translate(100,100,0);
t.getTransform().scale(10,10,0);
tiles.add(t);
}
@Override
public void update() {
Camera.update();
Camera.transform();
}
@Override
public void render2D() {
for(Tile t : tiles)t.render();
}
@ -37,7 +42,7 @@ public class MainGame extends Game{
@Override
public void destroy() {
tiles.clear();
}
}

View file

@ -82,7 +82,7 @@ public class Matrix4f {
return mat;
}
public Matrix4f tranlate(float x,float y,float z){
public Matrix4f translate(float x,float y,float z){
Matrix4f mat = new Matrix4f(new float[][]{
{1,0,0,x},
{0,1,0,y},

View file

@ -14,23 +14,19 @@ import globalgamejam.math.*;
public class Camera {
public static Matrix4f matrix = new Matrix4f();
public static final float SPEED = 1.0f;//Speed de base
public static float rot = 0.0f;//rotation de la camera
public static float rotation = 0.0f;//rotation de la camera
public static Vector2f pos = new Vector2f();
public static void update(){
float speed = SPEED * Main.delta;//speed reel par frame en fonction des fps
//class Input pour tous ce qui est entrer et sortis
public static void init(){
matrix = new Matrix4f();
rotation = 0.0f;
pos = new Vector2f();
}
public static void transform(){
matrix.loadIdentity();
matrix.rotate(new Quaternion(new Vector3f(0,0,1),rot));
matrix.tranlate(-pos.x, -pos.y, 0);
matrix.translate(-pos.x,-pos.y,0);
matrix.rotate(new Quaternion(new Vector3f(0,0,1),rotation));
}
}

View file

@ -18,7 +18,7 @@ public class DisplayManager {
public static void preRender2D(){
projection.loadIdentity();
projection.Ortho2D(0, Main.WIDTH, 0, Main.HEIGHT, -1, 1);
projection.Ortho2D(-Main.WIDTH/2.0f, Main.WIDTH/2.0f, -Main.HEIGHT/2.0f, Main.HEIGHT/2.0f, -1, 1);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_BLEND);
@ -28,7 +28,7 @@ public class DisplayManager {
public static void preRenderGUI(){
projection.loadIdentity();
//Permet de centrer la camera au centre de l'ecran
projection.Ortho2D(-Main.WIDTH/2.0f, Main.WIDTH/2.0f, -Main.HEIGHT/2.0f, Main.HEIGHT/2.0f, -1, 1);
projection.Ortho2D(0, Main.WIDTH, 0, Main.HEIGHT, -1, 1);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_BLEND);

View file

@ -0,0 +1,16 @@
package globalgamejam.tiles;
import globalgamejam.math.Color4f;
/**
* Created by MrDev023 on 14/01/2017.
*/
public class TestTile extends Tile {
public TestTile(){
super();
super.setColor(Color4f.RED);
}
}

View file

@ -1,7 +1,11 @@
package globalgamejam.render;
package globalgamejam.tiles;
import globalgamejam.math.Color4f;
import globalgamejam.math.Matrix4f;
import globalgamejam.render.Camera;
import globalgamejam.render.DisplayManager;
import globalgamejam.render.Shaders;
import globalgamejam.render.Texture;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.*;
@ -19,19 +23,15 @@ public abstract class Tile {
private int size;
public Tile(){
this.texture = new Texture(0,0,0);
this.texture = Texture.loadTexture("res/textures/default.png");
this.transform = new Matrix4f();
this.color = Color4f.WHITE;
this.vbo = GL15.glGenBuffers();
load();
}
private void load(){
float[] a = new float[]{
-1.0f,-1.0f, 0.0f,0.0f,
1.0f,-1.0f, 1.0f,0.0f,
1.0f,1.0f, 1.0f,1.0f,
1.0f,-1.0f, 0.0f,1.0f,
-.5f,-.5f, 0.0f,0.0f,
.5f,-.5f, 1.0f,0.0f,
.5f,.5f, 1.0f,1.0f,
-.5f,.5f, 0.0f,1.0f
};
FloatBuffer buffer = BufferUtils.createFloatBuffer(a.length);
buffer.put(a).flip();
@ -49,6 +49,7 @@ public abstract class Tile {
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
}
public void render(){
Shaders.MAIN_SHADERS.bind();
Shaders.MAIN_SHADERS.uniform("camera", Camera.matrix);