setTexture added
This commit is contained in:
parent
282a8b0283
commit
859344b131
@ -9,7 +9,6 @@ import org.lwjgl.glfw.GLFWVidMode;
|
||||
import org.lwjgl.opengl.GL;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
@ -53,7 +52,7 @@ public class Engine {
|
||||
int width = 1280;
|
||||
int height = 720;
|
||||
this.setWindow(glfwCreateWindow(width, height, "Boulevard Combattant", NULL, NULL));
|
||||
assert this.getWindow() != NULL;
|
||||
assert getWindow() != NULL;
|
||||
|
||||
boolean present = glfwJoystickPresent(GLFW_JOYSTICK_1);
|
||||
System.out.println(present);
|
||||
@ -63,14 +62,14 @@ public class Engine {
|
||||
assert vidmode != null;
|
||||
|
||||
// On met la fenêtre au centre de l'écran principale
|
||||
glfwSetWindowPos(this.getWindow(), (vidmode.width() - width)/2, (vidmode.height() - height)/2);
|
||||
glfwSetWindowPos(getWindow(), (vidmode.width() - width)/2, (vidmode.height() - height)/2);
|
||||
|
||||
glfwSetKeyCallback(getWindow(), new Input());
|
||||
glfwSetInputMode(getWindow(), GLFW_STICKY_KEYS, GLFW_TRUE);
|
||||
|
||||
// Contexte = zone cible des rendus
|
||||
glfwMakeContextCurrent(this.getWindow());
|
||||
glfwShowWindow(this.getWindow());
|
||||
glfwMakeContextCurrent(getWindow());
|
||||
glfwShowWindow(getWindow());
|
||||
GL.createCapabilities();
|
||||
|
||||
glfwSetFramebufferSizeCallback(getWindow(), resizeWindow);
|
||||
@ -100,13 +99,9 @@ public class Engine {
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
objectsGl.sort(new SortZ());
|
||||
// TODO trié en fonction de la distance z sinon bug d'affichage
|
||||
for (ObjectGl objectGl : objectsGl) {
|
||||
objectGl.render();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int error = glGetError();
|
||||
if (error != GL_NO_ERROR) System.out.println(error);
|
||||
@ -133,6 +128,14 @@ public class Engine {
|
||||
return glfwWindowShouldClose(getWindow());
|
||||
}
|
||||
|
||||
public static long getWindow() {
|
||||
return window;
|
||||
}
|
||||
|
||||
public void setWindow(long window) {
|
||||
Engine.window = 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
|
||||
@ -153,11 +156,14 @@ public class Engine {
|
||||
List<String> path = new ArrayList<>();
|
||||
path.add("textures/zangief_sprite.png");
|
||||
|
||||
ObjectGl smiley = new ObjectGlTex(-200.5f,200.5f,0.0f,320.0f*6,578.0f*6, path, Primitive.stdTexWrap);
|
||||
List<String> path2 = new ArrayList<>();
|
||||
path2.add("textures/awesomeface.png");
|
||||
|
||||
ObjectGlTex smiley = new ObjectGlTex(-200.5f,200.5f,0.0f,320.0f*6,578.0f*6, path, Primitive.stdTexWrap);
|
||||
engine.add_objectGl(smiley);
|
||||
smiley.translate(new Vector3f(-600.0f,0.0f,9.0f));
|
||||
|
||||
ObjectGl smiley2 = new ObjectGlTex(-0.5f,0.5f,0.0f,500.0f,500.0f, path, Primitive.stdTexWrap);
|
||||
ObjectGlTex smiley2 = new ObjectGlTex(-0.5f,0.5f,0.0f,500.0f,500.0f, path2, Primitive.stdTexWrap);
|
||||
engine.add_objectGl(smiley2);
|
||||
smiley2.translate(new Vector3f(0.0f,0.0f,5.0f));
|
||||
|
||||
@ -167,18 +173,11 @@ public class Engine {
|
||||
boolean nextFrame = false;
|
||||
|
||||
while(engine.isRunning()){
|
||||
// Game logic should fit here
|
||||
double time = glfwGetTime();
|
||||
lastFrame = System.currentTimeMillis();
|
||||
|
||||
smiley.translate(new Vector3f( (float) Math.sin(time)*5, (float) Math.cos(time)*5, 0.0f));
|
||||
|
||||
smiley2.rotateZ(0.8f);
|
||||
// Game logic should fit here
|
||||
|
||||
input(smiley, speed);
|
||||
input(smiley2, speed);
|
||||
|
||||
|
||||
input(smiley, speed);
|
||||
// input(smiley2, speed);
|
||||
|
||||
//essential part v
|
||||
engine.update();
|
||||
@ -202,18 +201,10 @@ public class Engine {
|
||||
}
|
||||
|
||||
public static void input(ObjectGl token, int speed) {
|
||||
if (Input.isKeyDown(GLFW.GLFW_KEY_W))token.translate(new Vector3f ( 0.0f, speed * 5.0f, 0.0f));
|
||||
if (Input.isKeyDown(GLFW.GLFW_KEY_A))token.translate(new Vector3f (speed *-5.0f, 0.0f, 0.0f));
|
||||
if (Input.isKeyDown(GLFW.GLFW_KEY_S))token.translate(new Vector3f ( 0.0f,speed * -5.0f, 0.0f));
|
||||
if (Input.isKeyDown(GLFW.GLFW_KEY_D))token.translate(new Vector3f (speed * 5.0f, 0.0f, 0.0f));
|
||||
if (Input.isKeyDown(GLFW.GLFW_KEY_W))token.translate(new Vector3f ( 0.0f, speed * 5.0f, 0.0f));
|
||||
if (Input.isKeyDown(GLFW.GLFW_KEY_A))token.translate(new Vector3f (speed *-5.0f, 0.0f, 0.0f));
|
||||
if (Input.isKeyDown(GLFW.GLFW_KEY_S))token.translate(new Vector3f ( 0.0f,speed * -5.0f, 0.0f));
|
||||
if (Input.isKeyDown(GLFW.GLFW_KEY_D))token.translate(new Vector3f (speed * 5.0f, 0.0f, 0.0f));
|
||||
}
|
||||
|
||||
public static long getWindow() {
|
||||
return window;
|
||||
}
|
||||
|
||||
public void setWindow(long window) {
|
||||
this.window = window;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,7 +23,10 @@ public class ObjectGlTex extends ObjectGl{
|
||||
this.transform = Matrix4f.identity();
|
||||
this.shader = new Shader("shaders/ObjectGlTex/vert.glsl","shaders/ObjectGlTex/frag.glsl");
|
||||
this.zPos = z;
|
||||
this.setTexture(texPath);
|
||||
}
|
||||
|
||||
public void setTexture(List<String> texPath){
|
||||
this.textures = new ArrayList<>();
|
||||
int count = 0;
|
||||
for (String path : texPath){
|
||||
|
@ -17,12 +17,6 @@ public class ObjectGlTexColor extends ObjectGlTex{
|
||||
this.transform = Matrix4f.identity();
|
||||
this.shader = new Shader("shaders/ObjectGlTexColor/vert.glsl","shaders/ObjectGlTexColor/frag.glsl");
|
||||
this.zPos = z;
|
||||
|
||||
this.textures = new ArrayList<>();
|
||||
int count = 0;
|
||||
for (String path : texPath){
|
||||
textures.add(new Texture(path, count));
|
||||
count++;
|
||||
}
|
||||
this.setTexture(texPath);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user