1
0
Fork 0
This repository has been archived on 2024-04-23. You can view files and clone it, but cannot push or open issues or pull requests.
Global-Gam-Jam-2017/src/globalgamejam/Main.java

122 lines
4.6 KiB
Java
Raw Normal View History

2017-01-14 13:13:28 +01:00
package globalgamejam;
//http://www.tomdalling.com/blog/modern-opengl/08-even-more-lighting-directional-lights-spotlights-multiple-lights/
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
2017-01-14 20:10:33 +01:00
import static org.lwjgl.opengl.GL13.GL_MULTISAMPLE;
2017-01-14 13:13:28 +01:00
import static org.lwjgl.system.MemoryUtil.*;
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
import globalgamejam.audio.*;
import globalgamejam.game.*;
import globalgamejam.input.*;
import globalgamejam.math.*;
import globalgamejam.render.*;
/**
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
*/
public class Main {
//Valeur de la fenetre
public static final int WIDTH = 800,HEIGHT = 600;
public static final String TITLE = "Test Shader OpenGL";
//Variable pour la gestion de la fenetre
public static long windowID = 0;
public static GLFWErrorCallback errorCallback;
//variable du moteur du jeu
public static float delta = 0;
public static Game game;
public static long previous = System.currentTimeMillis(),previousInfo = System.currentTimeMillis(),previousTicks = System.currentTimeMillis();
public static int FPS = 0,TICKS = 0;
public static void main(String[] args) throws Exception {
//Creation de la fenetre
//------------------------------------------------------------------------------------
errorCallback = new GLFWErrorCallback() {
public void invoke(int error, long description) {
System.err.println("ID : " + error + " | Description :" + description);
}
};
// glfwSetErrorCallback(errorCallback);
2017-01-14 17:59:15 +01:00
if(!glfwInit())throw new Exception("GLFW not init");
2017-01-14 13:13:28 +01:00
glfwDefaultWindowHints();
glfwWindowHint(GLFW_VISIBLE, GL11.GL_FALSE);
glfwWindowHint(GLFW_RESIZABLE, GL11.GL_FALSE);
2017-01-14 20:10:33 +01:00
glfwWindowHint(GLFW_SAMPLES, 4);//Activation du MSAA x4
2017-01-14 17:59:15 +01:00
// 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);
2017-01-14 13:13:28 +01:00
windowID = glfwCreateWindow(WIDTH,HEIGHT,TITLE,NULL,NULL);
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(windowID,(vidmode.width()-WIDTH)/2,(vidmode.height()-HEIGHT)/2);
glfwShowWindow(windowID);
glfwMakeContextCurrent(windowID);
GL.createCapabilities();
System.out.println("OpenGL Version :" + glGetString(GL_VERSION));
System.out.println("GLSL Shader Version :" + glGetString(GL20.GL_SHADING_LANGUAGE_VERSION));
//------------------------------------------------------------------------------------
//Creation du device audio
//------------------------------------------------------------------------------------
Audio.create();
//------------------------------------------------------------------------------------
//initialisation
//------------------------------------------------------------------------------------
2017-01-21 04:57:05 +01:00
//glEnable(GL_MULTISAMPLE);//Activation du MSAA
2017-01-14 13:13:28 +01:00
Input.init();
game = new MainGame();
Camera.transform();
//------------------------------------------------------------------------------------
2017-01-14 17:59:15 +01:00
while(!glfwWindowShouldClose(windowID)){
2017-01-14 13:13:28 +01:00
2017-01-21 15:45:43 +01:00
if(System.currentTimeMillis() - previousTicks >= 1000/120){//Update TICKS
2017-01-14 13:13:28 +01:00
glfwPollEvents();
Input.update();
game.update();
previousTicks = System.currentTimeMillis();
delta = (float)(System.currentTimeMillis() - previous)/1000.0f;
previous = System.currentTimeMillis();
TICKS++;
}else{//Update FPS
DisplayManager.clear();
DisplayManager.preRender2D();
DisplayManager.render2D();
DisplayManager.preRenderGUI();
DisplayManager.renderGUI();
glfwSwapBuffers(windowID);
FPS++;
}
if(System.currentTimeMillis() - previousInfo >= 1000){
glfwSetWindowTitle(windowID, TITLE + " | FPS:" + FPS + " TICKS:" + TICKS);
FPS = 0;
TICKS = 0;
previousInfo = System.currentTimeMillis();
}
}
2017-01-14 20:10:33 +01:00
game.destroy();
2017-01-14 13:13:28 +01:00
Audio.destroy();
glfwDestroyWindow(windowID);
glfwTerminate();
}
2017-01-14 20:10:33 +01:00
public static void changeGame(Game g){
game.destroy();
game = g;
g.init();
}
2017-01-14 13:13:28 +01:00
}