cleanup Engine.java
This commit is contained in:
parent
e78b680389
commit
58e94314cc
@ -2,7 +2,9 @@
|
||||
|
||||
layout (location = 0) in vec3 aPos;
|
||||
|
||||
uniform mat4 transform;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = vec4(aPos, 1.0);
|
||||
gl_Position = transform * vec4(aPos, 1.0);
|
||||
}
|
@ -1,13 +1,6 @@
|
||||
/**
|
||||
* CLASS ENGINE
|
||||
*
|
||||
* Classe principale du moteur de jeu
|
||||
*
|
||||
* @author François Autin
|
||||
*
|
||||
*/
|
||||
package engine;
|
||||
|
||||
import engine.math.Vector3f;
|
||||
import engine.object.ObjectGl;
|
||||
import org.lwjgl.glfw.GLFWFramebufferSizeCallback;
|
||||
import org.lwjgl.glfw.GLFWVidMode;
|
||||
@ -15,17 +8,16 @@ import org.lwjgl.opengl.GL;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.system.MemoryUtil.*;
|
||||
import static org.lwjgl.system.MemoryUtil.NULL;
|
||||
|
||||
public class Engine {
|
||||
|
||||
private long window;
|
||||
|
||||
private List<ObjectGl> objectsGl;
|
||||
private final List<ObjectGl> objectsGl;
|
||||
|
||||
private boolean running;
|
||||
|
||||
@ -34,14 +26,14 @@ public class Engine {
|
||||
*/
|
||||
public Engine() {
|
||||
this.running = false;
|
||||
this.objectsGl = new ArrayList<ObjectGl>();
|
||||
this.objectsGl = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the engine
|
||||
* Create the window
|
||||
*/
|
||||
private void init() {
|
||||
public void init() {
|
||||
glfwInit();
|
||||
|
||||
this.running = true;
|
||||
@ -82,14 +74,14 @@ public class Engine {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void update(){
|
||||
public void update(){
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void render(){
|
||||
public void render(){
|
||||
|
||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
@ -103,17 +95,6 @@ public class Engine {
|
||||
glfwSwapBuffers(window); //Envoie le buffer vers le moniteur
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO la boucle de rendu doit être inscrite dans la boucle de gameplay: cette methode doit disparaitre
|
||||
*/
|
||||
public void run(){
|
||||
while(running){
|
||||
update();
|
||||
render();
|
||||
if(glfwWindowShouldClose(window)) running = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void add_objectGl(ObjectGl obj){
|
||||
objectsGl.add(obj);
|
||||
}
|
||||
@ -122,6 +103,18 @@ public class Engine {
|
||||
objectsGl.remove(obj);
|
||||
}
|
||||
|
||||
public boolean isRunning(){
|
||||
return running;
|
||||
}
|
||||
|
||||
public void setRunning(boolean b){
|
||||
running = b;
|
||||
}
|
||||
|
||||
public boolean shouldClose(){
|
||||
return glfwWindowShouldClose(window);
|
||||
}
|
||||
|
||||
/**
|
||||
* Est appelé à chaque modification de la taille de la fenêtre, et modifie la taille de la zone de rendu
|
||||
* pour quelle corresponde à la taille de la fenêtre
|
||||
@ -136,12 +129,22 @@ public class Engine {
|
||||
public static void main(String[] args) {
|
||||
Engine engine = new Engine();
|
||||
engine.init();
|
||||
|
||||
// Add objects to render
|
||||
ObjectGl cube = new ObjectGl(-0.2f,-0.2f,0.0f,1.0f,1.0f);
|
||||
ObjectGl cube = new ObjectGl(-0.5f,0.5f,0.0f,1.0f,1.0f);
|
||||
engine.add_objectGl(cube);
|
||||
// engine.remove_objectGl(cube);
|
||||
|
||||
engine.run();
|
||||
while(engine.isRunning()){
|
||||
|
||||
// Game logic should fit here
|
||||
cube.rotateZ(1.0f);
|
||||
cube.translate(new Vector3f(0.01f, 0.0f, 0.0f));
|
||||
|
||||
//essential part v
|
||||
engine.update();
|
||||
engine.render();
|
||||
if(engine.shouldClose()) engine.setRunning(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ public class ObjectGl {
|
||||
|
||||
public void render(){
|
||||
this.shader.enable();
|
||||
this.shader.setUniformMat4f("transform", this.transform);
|
||||
this.vertexArray.render();
|
||||
this.shader.disable();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user