new engine
This commit is contained in:
parent
c6181c96fe
commit
e78b680389
@ -10,5 +10,5 @@ uniform sampler2D texture2;
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
FragColor = mix(texture(texture1, TexCoord), texture(texture2, vec2(TexCoord.x, -TexCoord.y)), position.x * position.y);
|
FragColor = mix(texture(texture1, TexCoord), texture(texture2, vec2(TexCoord.x, -TexCoord.y)), position.x * position.y);
|
||||||
}
|
}
|
@ -7,8 +7,8 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import launcher.Launcher;
|
|
||||||
import engine.Engine;
|
import engine.Engine;
|
||||||
|
import launcher.Launcher;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
|
@ -8,10 +8,15 @@
|
|||||||
*/
|
*/
|
||||||
package engine;
|
package engine;
|
||||||
|
|
||||||
|
import engine.object.ObjectGl;
|
||||||
import org.lwjgl.glfw.GLFWFramebufferSizeCallback;
|
import org.lwjgl.glfw.GLFWFramebufferSizeCallback;
|
||||||
import org.lwjgl.glfw.GLFWVidMode;
|
import org.lwjgl.glfw.GLFWVidMode;
|
||||||
import org.lwjgl.opengl.GL;
|
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.glfw.GLFW.*;
|
||||||
import static org.lwjgl.opengl.GL11.*;
|
import static org.lwjgl.opengl.GL11.*;
|
||||||
import static org.lwjgl.system.MemoryUtil.*;
|
import static org.lwjgl.system.MemoryUtil.*;
|
||||||
@ -20,28 +25,35 @@ public class Engine {
|
|||||||
|
|
||||||
private long window;
|
private long window;
|
||||||
|
|
||||||
private Scene scene;
|
private List<ObjectGl> objectsGl;
|
||||||
private Scene scene2;
|
|
||||||
|
|
||||||
private boolean running;
|
private boolean running;
|
||||||
|
|
||||||
public Engine(){
|
/**
|
||||||
|
* Create the engine and initial attributes use .init() to start the engine
|
||||||
|
*/
|
||||||
|
public Engine() {
|
||||||
this.running = false;
|
this.running = false;
|
||||||
|
this.objectsGl = new ArrayList<ObjectGl>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the engine
|
||||||
|
* Create the window
|
||||||
|
*/
|
||||||
private void init() {
|
private void init() {
|
||||||
if(!glfwInit()){
|
glfwInit();
|
||||||
// TODO Erreur d'initialisation
|
|
||||||
}
|
|
||||||
this.running = true;
|
this.running = true;
|
||||||
|
|
||||||
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
|
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); //On utilise la version 3.3 d'openGL
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); //On utilise la version 3.3 d'openGL
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
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 = 800;
|
int width = 1280;
|
||||||
int height = 600;
|
int height = 720;
|
||||||
this.window = glfwCreateWindow(width, height, "Boulevard Combattant", NULL, NULL);
|
this.window = glfwCreateWindow(width, height, "Boulevard Combattant", NULL, NULL);
|
||||||
assert this.window != NULL;
|
assert this.window != NULL;
|
||||||
|
|
||||||
@ -49,6 +61,7 @@ public class Engine {
|
|||||||
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
|
||||||
assert vidmode != null;
|
assert vidmode != null;
|
||||||
|
|
||||||
|
// On met la fenêtre au centre de l'écran principale
|
||||||
glfwSetWindowPos(this.window, (vidmode.width() - width)/2, (vidmode.height() - height)/2);
|
glfwSetWindowPos(this.window, (vidmode.width() - width)/2, (vidmode.height() - height)/2);
|
||||||
|
|
||||||
glfwSetKeyCallback(window, new Input());
|
glfwSetKeyCallback(window, new Input());
|
||||||
@ -64,38 +77,54 @@ public class Engine {
|
|||||||
glEnable(GL_DEPTH_TEST); // Z-Buffer
|
glEnable(GL_DEPTH_TEST); // Z-Buffer
|
||||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||||
System.out.println("OpenGL: " + glGetString(GL_VERSION));
|
System.out.println("OpenGL: " + glGetString(GL_VERSION));
|
||||||
|
|
||||||
this.scene = new Scene("shaders/vert.vert", "shaders/frag.frag", Primitive.rectangle, Primitive.rectangle_indices, Primitive.rectangle_color, Primitive.rectangle_texture);
|
|
||||||
this.scene2 = new Scene("shaders/vert.glsl", "shaders/frag.frag", Primitive.triangle, Primitive.triangle_indices);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
private void update(){
|
private void update(){
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
private void render(){
|
private void render(){
|
||||||
|
|
||||||
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //SWAP avec le precedent
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
scene.render();
|
|
||||||
scene2.render();
|
for (ObjectGl objectGl : objectsGl) {
|
||||||
|
objectGl.render();
|
||||||
|
}
|
||||||
|
|
||||||
int error = glGetError();
|
int error = glGetError();
|
||||||
if (error != GL_NO_ERROR) System.out.println(error);
|
if (error != GL_NO_ERROR) System.out.println(error);
|
||||||
glfwSwapBuffers(window); //Envoie le buffer vers le moniteur
|
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(){
|
public void run(){
|
||||||
init();
|
while(running){
|
||||||
while(running){
|
update();
|
||||||
update();
|
render();
|
||||||
render();
|
if(glfwWindowShouldClose(window)) running = false;
|
||||||
if(glfwWindowShouldClose(window)) running = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
public void add_objectGl(ObjectGl obj){
|
||||||
Est appelé à chaque modification de la taille de la fenêtre, et modifie la taille de la zone de rendu
|
objectsGl.add(obj);
|
||||||
pour quelle corresponde à la taille de la fenêtre
|
}
|
||||||
|
|
||||||
|
public void remove_objectGl(ObjectGl obj){
|
||||||
|
objectsGl.remove(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
*/
|
*/
|
||||||
private static final GLFWFramebufferSizeCallback resizeWindow = new GLFWFramebufferSizeCallback(){
|
private static final GLFWFramebufferSizeCallback resizeWindow = new GLFWFramebufferSizeCallback(){
|
||||||
@Override
|
@Override
|
||||||
@ -106,6 +135,12 @@ public class Engine {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Engine engine = new Engine();
|
Engine engine = new Engine();
|
||||||
|
engine.init();
|
||||||
|
// Add objects to render
|
||||||
|
ObjectGl cube = new ObjectGl(-0.2f,-0.2f,0.0f,1.0f,1.0f);
|
||||||
|
engine.add_objectGl(cube);
|
||||||
|
// engine.remove_objectGl(cube);
|
||||||
|
|
||||||
engine.run();
|
engine.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,99 +0,0 @@
|
|||||||
package engine;
|
|
||||||
|
|
||||||
import engine.math.Vector3f;
|
|
||||||
|
|
||||||
public class Primitive {
|
|
||||||
|
|
||||||
public float[] vertices;
|
|
||||||
public byte[] indices;
|
|
||||||
|
|
||||||
public Primitive(Vector3f vertex1, Vector3f vertex2, Vector3f vertex3){
|
|
||||||
vertices = new float[]{
|
|
||||||
vertex1.x, vertex1.y, vertex1.z,
|
|
||||||
vertex2.x, vertex2.y, vertex2.z,
|
|
||||||
vertex3.x, vertex3.y, vertex3.z
|
|
||||||
};
|
|
||||||
indices = new byte[]{
|
|
||||||
0, 1, 2
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public Primitive(Vector3f vertex1, Vector3f vertex2, Vector3f vertex3, Vector3f vertex4){
|
|
||||||
vertices = new float[]{
|
|
||||||
vertex1.x, vertex1.y, vertex1.z,
|
|
||||||
vertex2.x, vertex2.y, vertex2.z,
|
|
||||||
vertex3.x, vertex3.y, vertex3.z,
|
|
||||||
vertex4.x, vertex4.y, vertex4.z
|
|
||||||
};
|
|
||||||
indices = new byte[]{
|
|
||||||
0, 1, 2,
|
|
||||||
1, 2, 3
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float[] createRectangle(float x, float y, float z, float w, float h){
|
|
||||||
return new float[] {
|
|
||||||
x , y , z,
|
|
||||||
x + h, y , z,
|
|
||||||
x + h, y + w, z,
|
|
||||||
x , y + w, z
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float[] triangle = new float[] {
|
|
||||||
0.0f, 0.5f, 0.0f,
|
|
||||||
0.5f, -0.5f, 0.0f,
|
|
||||||
-0.5f, -0.5f, 0.0f,
|
|
||||||
};
|
|
||||||
|
|
||||||
public static float[] triangle_couleur = new float[] {
|
|
||||||
1.0f, 0.0f, 0.0f,
|
|
||||||
0.0f, 1.0f, 0.0f,
|
|
||||||
0.0f, 0.0f, 1.0f
|
|
||||||
};
|
|
||||||
|
|
||||||
public static byte[] triangle_indices = new byte[]{
|
|
||||||
0, 1, 2
|
|
||||||
};
|
|
||||||
|
|
||||||
public static float[] two_triangle = new float[] {
|
|
||||||
0.0f, 0.5f, 0.0f,
|
|
||||||
0.5f, -0.5f, 0.0f,
|
|
||||||
-0.5f, -0.5f, 0.0f,
|
|
||||||
-0.8f, -0.8f, 0.0f,
|
|
||||||
0.8f, -0.8f, 0.0f,
|
|
||||||
0.8f, -0.9f, 0.0f,
|
|
||||||
};
|
|
||||||
|
|
||||||
public static byte[] two_triangle_indices = new byte[]{
|
|
||||||
0, 1, 2,
|
|
||||||
3, 4, 5
|
|
||||||
};
|
|
||||||
|
|
||||||
public static float[] rectangle = new float[] {
|
|
||||||
0.5f, 0.5f, 0.0f, // top right
|
|
||||||
0.5f, -0.5f, 0.0f, // bottom right
|
|
||||||
-0.5f, -0.5f, 0.0f, // bottom left
|
|
||||||
-0.5f, 0.5f, 0.0f // top left
|
|
||||||
};
|
|
||||||
|
|
||||||
public static float[] rectangle_color = new float[]{
|
|
||||||
1.0f, 0.0f, 0.0f, // top right
|
|
||||||
0.0f, 1.0f, 0.0f, // bottom right
|
|
||||||
0.0f, 0.0f, 1.0f, // bottom left
|
|
||||||
1.0f, 1.0f, 0.0f, // top left
|
|
||||||
};
|
|
||||||
|
|
||||||
public static float[] rectangle_texture = new float[]{
|
|
||||||
2.0f, 2.0f,
|
|
||||||
2.0f, 0.0f,
|
|
||||||
0.0f, 0.0f,
|
|
||||||
0.0f, 2.0f
|
|
||||||
};
|
|
||||||
|
|
||||||
public static byte[] rectangle_indices = new byte[] {
|
|
||||||
0, 1, 3,
|
|
||||||
1, 2, 3
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
28
src/engine/math/Primitive.java
Normal file
28
src/engine/math/Primitive.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package engine.math;
|
||||||
|
|
||||||
|
import engine.math.Vector3f;
|
||||||
|
|
||||||
|
public class Primitive {
|
||||||
|
|
||||||
|
public static float[] createRectangle(float x, float y, float z, float w, float h){
|
||||||
|
return new float[] {
|
||||||
|
x , y , z,
|
||||||
|
x + w, y , z,
|
||||||
|
x + w, y - h, z,
|
||||||
|
x , y - h, z
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float[] stdTexWrap = new float[] {
|
||||||
|
1.0f, 1.0f,
|
||||||
|
1.0f, 0.0f,
|
||||||
|
0.0f, 0.0f,
|
||||||
|
0.0f, 1.0f
|
||||||
|
};
|
||||||
|
|
||||||
|
public static byte[] rectangle_indices = new byte[] {
|
||||||
|
0, 1, 3,
|
||||||
|
1, 2, 3
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package engine.object;
|
package engine.object;
|
||||||
|
|
||||||
import engine.Primitive;
|
import engine.math.Primitive;
|
||||||
import engine.graphics.VertexArray;
|
import engine.graphics.VertexArray;
|
||||||
import engine.graphics.Shader;
|
import engine.graphics.Shader;
|
||||||
import engine.math.Matrix4f;
|
import engine.math.Matrix4f;
|
||||||
@ -15,6 +15,10 @@ public class ObjectGl {
|
|||||||
protected Shader shader;
|
protected Shader shader;
|
||||||
protected Matrix4f transform;
|
protected Matrix4f transform;
|
||||||
|
|
||||||
|
public ObjectGl(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public ObjectGl(float x, float y, float z, float h, float w){
|
public ObjectGl(float x, float y, float z, float h, float w){
|
||||||
this.vertexArray = new VertexArray(Primitive.createRectangle(x, y, z, h, w), Primitive.rectangle_indices, null, null);
|
this.vertexArray = new VertexArray(Primitive.createRectangle(x, y, z, h, w), Primitive.rectangle_indices, null, null);
|
||||||
this.transform = Matrix4f.identity();
|
this.transform = Matrix4f.identity();
|
||||||
|
@ -1,11 +1,16 @@
|
|||||||
package engine.object;
|
package engine.object;
|
||||||
|
|
||||||
|
import engine.math.Primitive;
|
||||||
import engine.graphics.Shader;
|
import engine.graphics.Shader;
|
||||||
|
import engine.graphics.VertexArray;
|
||||||
|
import engine.math.Matrix4f;
|
||||||
|
|
||||||
public class ObjectGlColor extends ObjectGl{
|
public class ObjectGlColor extends ObjectGl{
|
||||||
|
|
||||||
public ObjectGlColor(float x, float y, float h, float w, float[] color) {
|
public ObjectGlColor(float x, float y, float z, float h, float w, float[] color) {
|
||||||
super(x, y, h, w);
|
super();
|
||||||
|
this.vertexArray = new VertexArray(Primitive.createRectangle(x, y, z, h, w), Primitive.rectangle_indices, color, null);
|
||||||
|
this.transform = Matrix4f.identity();
|
||||||
this.shader = new Shader("shaders/ObjectGlColor/vert.glsl","shaders/ObjectGlColor/frag.glsl");
|
this.shader = new Shader("shaders/ObjectGlColor/vert.glsl","shaders/ObjectGlColor/frag.glsl");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +1,28 @@
|
|||||||
package engine.object;
|
package engine.object;
|
||||||
|
|
||||||
|
import engine.math.Primitive;
|
||||||
import engine.graphics.Shader;
|
import engine.graphics.Shader;
|
||||||
|
import engine.graphics.Texture;
|
||||||
|
import engine.graphics.VertexArray;
|
||||||
|
import engine.math.Matrix4f;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ObjectGlTex extends ObjectGl{
|
public class ObjectGlTex extends ObjectGl{
|
||||||
|
|
||||||
public ObjectGlTex(float x, float y, float h, float w, float[] texCoord) {
|
List<Texture> textures;
|
||||||
super(x, y, h, w);
|
|
||||||
|
public ObjectGlTex(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectGlTex(float x, float y, float z, float h, float w, List<String> texPath, float[] texCoord) {
|
||||||
|
super();
|
||||||
|
this.vertexArray = new VertexArray(Primitive.createRectangle(x, y, z, h, w), Primitive.rectangle_indices, null, texCoord);
|
||||||
|
this.transform = Matrix4f.identity();
|
||||||
this.shader = new Shader("shaders/ObjectGlTex/vert.glsl","shaders/ObjectGlTex/frag.glsl");
|
this.shader = new Shader("shaders/ObjectGlTex/vert.glsl","shaders/ObjectGlTex/frag.glsl");
|
||||||
|
|
||||||
|
// TODO tex
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
20
src/engine/object/ObjectGlTexColor.java
Normal file
20
src/engine/object/ObjectGlTexColor.java
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package engine.object;
|
||||||
|
|
||||||
|
import engine.math.Primitive;
|
||||||
|
import engine.graphics.Shader;
|
||||||
|
import engine.graphics.VertexArray;
|
||||||
|
import engine.math.Matrix4f;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ObjectGlTexColor extends ObjectGlTex{
|
||||||
|
|
||||||
|
public ObjectGlTexColor(float x, float y, float z, float h, float w, List<String> texPath, float[] texCoord, float[] color) {
|
||||||
|
super();
|
||||||
|
this.vertexArray = new VertexArray(Primitive.createRectangle(x, y, z, h, w), Primitive.rectangle_indices, color, texCoord);
|
||||||
|
this.transform = Matrix4f.identity();
|
||||||
|
this.shader = new Shader("shaders/ObjectGlTexColor/vert.glsl","shaders/ObjectGlTexColor/frag.glsl");
|
||||||
|
|
||||||
|
// TODO Create texture
|
||||||
|
}
|
||||||
|
}
|
BIN
textures/zangief_sprite.png
Normal file
BIN
textures/zangief_sprite.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
Loading…
x
Reference in New Issue
Block a user