Modification du constructeur d'Engine ajout de la largeur et la hauteur de la fenêtre ainsi que l'aspect ratio

This commit is contained in:
Antoine 2021-05-28 13:02:48 +02:00
parent d57696c30d
commit 9612db9b49
2 changed files with 14 additions and 10 deletions

View File

@ -18,14 +18,14 @@ void main()
vec2 fragCoordTemp = fragCoord; vec2 fragCoordTemp = fragCoord;
fragCoordTemp = 8. * fragCoordTemp / fragCoordTemp.y-vec2(7,4); fragCoordTemp = 8. * fragCoordTemp / fragCoordTemp.y-vec2(7,4);
perlinNoise = sin(perlinNoise + time); perlinNoise = sin(perlinNoise + time*15);
perlinNoise = mix(perlinNoise,color,0.5f); perlinNoise = mix(perlinNoise,color,0.5f);
vec4 tex = texture(texture1, texCoord); vec4 tex = texture(texture1, texCoord);
if (tex.a == 0.0){ if (tex.a == 0.0){
FragColor = tex; FragColor = tex;
} else{ } else{
FragColor = mix(tex, perlinNoise, 0.5); FragColor = mix(tex, perlinNoise, 0.5f);
FragColor.a = 1.0f; FragColor.a = 1.0f;
} }
} }

View File

@ -27,14 +27,18 @@ public class Engine {
private boolean running; private boolean running;
private final int width;
private final int height;
/** /**
* Create the engine and initial attributes use .init() to start the engine * Create the engine and initial attributes use .init() to start the engine
*/ */
public Engine() { public Engine(int width, int height, float aspectRatio) {
this.running = false; this.running = false;
this.objectsGl = new ArrayList<>(); this.objectsGl = new ArrayList<>();
float width = 1280.0f; this.width = width;
ObjectGl.projection = Matrix4f.orthographic(-width, width, -width * 9.0f / 16.0f, width * 9.0f / 16.0f, 0.1f, 100.0f); this.height = height;
ObjectGl.projection = Matrix4f.orthographic(-width, width, -width * aspectRatio, width * aspectRatio, 0.1f, 100.0f);
ObjectGl.view = Matrix4f.translate(new Vector3f(0.0f,0.0f,1.0f)); ObjectGl.view = Matrix4f.translate(new Vector3f(0.0f,0.0f,1.0f));
} }
@ -54,8 +58,8 @@ public class Engine {
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); //Compatible MAC glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); //Compatible MAC
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //Le core profile est l'interface 'avancé' d'openGL glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //Le core profile est l'interface 'avancé' d'openGL
int width = 1280; int width = this.width;
int height = 720; int height = this.height;
this.setWindow(glfwCreateWindow(width, height, "Boulevard Combattant", NULL, NULL)); this.setWindow(glfwCreateWindow(width, height, "Boulevard Combattant", NULL, NULL));
assert getWindow() != NULL; assert getWindow() != NULL;
@ -115,7 +119,7 @@ public class Engine {
/** /**
* Add obj to the render queue * Add obj to the render queue
* @param obj * @param obj ObjectGl to render
*/ */
public void add_objectGl(ObjectGl obj){ public void add_objectGl(ObjectGl obj){
objectsGl.add(obj); objectsGl.add(obj);
@ -157,7 +161,7 @@ public class Engine {
}; };
public static void main(String[] args) { public static void main(String[] args) {
Engine engine = new Engine(); Engine engine = new Engine(1280, 720, 9.0f/16.0f);
int speed = 10 ; //vitesse déplacement Object int speed = 10 ; //vitesse déplacement Object
engine.init(); engine.init();
@ -170,7 +174,7 @@ public class Engine {
zangief.setTextureWrap(58,0,62,84, ObjectGl.STICK_TOP); zangief.setTextureWrap(58,0,62,84, ObjectGl.STICK_TOP);
engine.add_objectGl(zangief); engine.add_objectGl(zangief);
zangief.translate(new Vector3f(-5000.0f,500.0f,10.0f)); zangief.translate(new Vector3f(-5000.0f,500.0f,10.0f));
zangief.setColor(new Vector3f(0.0f, 0.0f, 1.0f)); zangief.setColor(new Vector3f(1.0f, 1.0f, 1.0f));
zangief.useTime = true; zangief.useTime = true;
zangief.setShader("shaders/StylishShaders/BasicVert.glsl","shaders/StylishShaders/PerlinNoise.glsl"); zangief.setShader("shaders/StylishShaders/BasicVert.glsl","shaders/StylishShaders/PerlinNoise.glsl");