Organisation

This commit is contained in:
Antoine 2021-05-17 05:39:23 +02:00
parent 5d93325b3d
commit 202c141e4d
13 changed files with 51 additions and 18 deletions

View File

@ -3,10 +3,12 @@ out vec4 FragColor;
in vec3 ourColor;
in vec2 TexCoord;
in vec4 position;
uniform sampler2D ourTexture;
uniform sampler2D texture1;
uniform sampler2D texture2;
void main()
{
FragColor = texture(ourTexture, TexCoord) * vec4(ourColor, 1.0f);
FragColor = mix(texture(texture1, TexCoord), texture(texture2, vec2(TexCoord.x, -TexCoord.y)), position.x * position.y);
}

View File

@ -5,10 +5,12 @@ layout (location = 2) in vec2 aTexCoord;
out vec3 ourColor;
out vec2 TexCoord;
out vec4 position;
void main()
{
gl_Position = vec4(aPos, 1.0);
ourColor = aColor;
TexCoord = aTexCoord;
position = gl_Position;
}

View File

@ -1,5 +1,7 @@
package engine;
import engine.math.Vector3f;
public class Primitive {
public float[] vertices;
@ -74,10 +76,10 @@ public class Primitive {
};
public static float[] rectangle_texture = new float[]{
1.0f, 1.0f,
1.0f, 0.0f,
2.0f, 2.0f,
2.0f, 0.0f,
0.0f, 0.0f,
0.0f, 1.0f
0.0f, 2.0f
};
public static byte[] rectangle_indices = new byte[] {

View File

@ -1,13 +1,17 @@
package engine;
import static org.lwjgl.opengl.GL11.*;
import engine.graphics.Shader;
import engine.graphics.Texture;
import engine.graphics.VertexArray;
public class Scene {
float[] vertices;
float[] color;
float[] texture;
float[] texture2;
Texture texture_map;
Texture texture_map2;
byte[] indices;
VertexArray vertexArray;
@ -25,15 +29,21 @@ public class Scene {
this.indices = indices;
this.color = color;
this.shader = new Shader(vertPath, fragPath);
this.texture_map = new Texture("textures/container.jpg");
this.texture_map = new Texture("textures/container.jpg", 0);
this.texture = texture;
this.texture_map2 = new Texture("textures/awesomeface.png", 1);
this.texture2 = texture;
this.vertexArray = new VertexArray(this.vertices, this.indices, this.color, this.texture);
shader.setUniform1i("texture1", 0);
shader.setUniform1i("texture2", 1);
}
public void render(){
this.shader.enable();
this.texture_map.bind();
this.texture_map2.bind();
this.vertexArray.render();
this.texture_map2.unbind();
this.texture_map.unbind();
this.shader.disable();
}

View File

@ -1,4 +1,8 @@
package engine;
package engine.graphics;
import engine.math.Matrix4f;
import engine.utils.ShaderUtils;
import engine.math.Vector3f;
import java.util.HashMap;
import java.util.Map;

View File

@ -1,4 +1,7 @@
package engine;
package engine.graphics;
import engine.utils.BufferUtils;
import org.lwjgl.opengl.GL11;
import java.awt.image.BufferedImage;
import java.io.FileInputStream;
@ -13,8 +16,10 @@ public class Texture {
private int width, height;
private int texture;
private int index;
public Texture(String path) {
public Texture(String path, int index) {
this.index = index;
texture = load(path);
}
@ -44,13 +49,14 @@ public class Texture {
glBindTexture(GL_TEXTURE_2D, result);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, BufferUtils.createIntBuffer(data));
GL11.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, BufferUtils.createIntBuffer(data));
glGenerateMipmap(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
return result;
}
public void bind() {
glActiveTexture(GL_TEXTURE0 + this.index);
glBindTexture(GL_TEXTURE_2D, texture);
}

View File

@ -1,4 +1,7 @@
package engine;
package engine.graphics;
import engine.utils.BufferUtils;
import org.lwjgl.opengl.GL15;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL15.*;
@ -20,7 +23,7 @@ public class VertexArray {
EBO = glGenBuffers();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, BufferUtils.createByteBuffer(indices), GL_STATIC_DRAW);
GL15.glBufferData(GL_ELEMENT_ARRAY_BUFFER, BufferUtils.createByteBuffer(indices), GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);

View File

@ -1,4 +1,6 @@
package engine;
package engine.math;
import engine.utils.BufferUtils;
import java.nio.FloatBuffer;

View File

@ -1,4 +1,4 @@
package engine;
package engine.math;
public class Vector3f {

View File

@ -1,4 +1,4 @@
package engine;
package engine.utils;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

View File

@ -1,4 +1,4 @@
package engine;
package engine.utils;
import java.io.BufferedReader;
import java.io.FileNotFoundException;

View File

@ -1,4 +1,6 @@
package engine;
package engine.utils;
import engine.utils.FileUtils;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL20.*;

BIN
textures/awesomeface.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB