From 56c316fc492484bd78225ec9225b14624abb0577 Mon Sep 17 00:00:00 2001 From: EvilMuffinHa Date: Sun, 10 May 2020 10:51:07 -0400 Subject: [PATCH 1/8] Revert "comment" This reverts commit b2dbf16329c95cd32d7f2d3e09e4a7cbfa4ad227. Moving back to before textures (without errors) --- src/org/hl/engine/graphics/Mesh.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/org/hl/engine/graphics/Mesh.java b/src/org/hl/engine/graphics/Mesh.java index 038a855..f59c735 100644 --- a/src/org/hl/engine/graphics/Mesh.java +++ b/src/org/hl/engine/graphics/Mesh.java @@ -103,16 +103,13 @@ public class Mesh { colorBufferObject = storeData(colorBuffer, 1, 3); - - // Putting texture into the buffer so renderer and shader can read it - FloatBuffer textureBuffer = MemoryUtil.memAllocFloat(vertices.length * 2); float[] textureData = new float[vertices.length * 3]; for (int i = 0; i < vertices.length; i ++ ) { textureData[i * 2] = vertices[i].getTextureCoordinates().getX(); textureData[i * 2 + 1] = vertices[i].getTextureCoordinates().getY(); } - textureBuffer.put(textureData).flip(); + textureBuffer.put(colorData).flip(); textureBufferObject = storeData(textureBuffer, 2, 2); From 8c94a73d70a4af17077eca764ae6965b9730b4c5 Mon Sep 17 00:00:00 2001 From: EvilMuffinHa Date: Sun, 10 May 2020 10:51:37 -0400 Subject: [PATCH 2/8] Revert "adding textures (has errors)" This reverts commit eb6101d2ec2d7828c40bccf4195a2bf3ec13780a. --- src/Test.java | 17 ++++++---- src/org/hl/engine/graphics/Material.java | 5 +-- src/org/hl/engine/graphics/Mesh.java | 29 ++-------------- src/org/hl/engine/graphics/Renderer.java | 6 +--- src/org/hl/engine/graphics/Vertex.java | 11 ++---- src/org/hl/engine/io/Display.java | 6 ++-- .../hl/engine/math/{lalg => }/Vector3f.java | 2 +- src/org/hl/engine/math/lalg/Vector2f.java | 32 ------------------ src/org/hl/engine/utils/TextureLoader.java | 1 + src/resources/shaders/mainFragment.glsl | 7 ++-- src/resources/shaders/mainVertex.glsl | 9 ++--- src/resources/textures/beautiful.png | Bin 5785 -> 0 bytes 12 files changed, 26 insertions(+), 99 deletions(-) rename src/org/hl/engine/math/{lalg => }/Vector3f.java (95%) delete mode 100644 src/org/hl/engine/math/lalg/Vector2f.java delete mode 100644 src/resources/textures/beautiful.png diff --git a/src/Test.java b/src/Test.java index 757a0fe..1c153f3 100644 --- a/src/Test.java +++ b/src/Test.java @@ -1,7 +1,10 @@ -import org.hl.engine.graphics.*; +import org.hl.engine.graphics.Mesh; +import org.hl.engine.graphics.Renderer; +import org.hl.engine.graphics.Shader; +import org.hl.engine.graphics.Vertex; import org.hl.engine.io.Display; import org.hl.engine.io.Input; -import org.hl.engine.math.lalg.*; +import org.hl.engine.math.Vector3f; import org.lwjgl.glfw.GLFW; @@ -15,16 +18,16 @@ public class Test { public Shader shader; public Mesh mesh = new Mesh(new Vertex[] { - new Vertex(new Vector3f(-0.5F, 0.5F, 0.0F), new Vector3f(0, 0, 1.0F), new Vector2f(0, 0)), - new Vertex(new Vector3f(-0.5F, -0.5F, 0.0F), new Vector3f(0, 0, 1.0F), new Vector2f(0, 1)), - new Vertex(new Vector3f(0.5F, -0.5F, 0.0F), new Vector3f(1.0F, 0, 1.0F), new Vector2f(1, 1)), - new Vertex(new Vector3f(0.5F, 0.5F, 0.0F), new Vector3f(1.0F, 0, 1.0F), new Vector2f(1, 0)), + new Vertex(new Vector3f(-0.5F, 0.5F, 0.0F), new Vector3f(0, 0, 1.0F)), + new Vertex(new Vector3f(-0.5F, -0.5F, 0.0F), new Vector3f(0, 0, 1.0F)), + new Vertex(new Vector3f(0.5F, -0.5F, 0.0F), new Vector3f(1.0F, 0, 1.0F)), + new Vertex(new Vector3f(0.5F, 0.5F, 0.0F), new Vector3f(1.0F, 0, 1.0F) ), }, new int[] { 0, 1, 2, 0, 2, 3 - }, new Material("/textures/beautiful.png")); + }); public void run() { init(); diff --git a/src/org/hl/engine/graphics/Material.java b/src/org/hl/engine/graphics/Material.java index 3cfbd8b..becaef4 100644 --- a/src/org/hl/engine/graphics/Material.java +++ b/src/org/hl/engine/graphics/Material.java @@ -14,16 +14,13 @@ public class Material { private int width, height; private int textureID; - private String path; public Material(String path) { - this.path = path; + this.image = TextureLoader.loadImage(path); //The path is inside the jar file } public void create() { - // Loading image on create - this.image = TextureLoader.loadImage(path); //The path is inside the jar file this.width = this.image.getWidth(); this.height = this.image.getHeight(); this.textureID = TextureLoader.loadTexture(image); diff --git a/src/org/hl/engine/graphics/Mesh.java b/src/org/hl/engine/graphics/Mesh.java index f59c735..b6d6194 100644 --- a/src/org/hl/engine/graphics/Mesh.java +++ b/src/org/hl/engine/graphics/Mesh.java @@ -12,14 +12,12 @@ import java.nio.IntBuffer; public class Mesh { private Vertex[] vertices; private int[] indices; - private Material material; - private int vertexArrayObject, positionBufferObject, indicesBufferObject, colorBufferObject, textureBufferObject; + private int vertexArrayObject, positionBufferObject, indicesBufferObject, colorBufferObject; // A group of vertices combined based on the indexes - public Mesh(Vertex[] vertices, int[] indices, Material material) { + public Mesh(Vertex[] vertices, int[] indices) { this.vertices = vertices; this.indices = indices; - this.material = material; } // Destroy the mesh @@ -27,8 +25,6 @@ public class Mesh { GL15.glDeleteBuffers(positionBufferObject); GL15.glDeleteBuffers(indicesBufferObject); GL15.glDeleteBuffers(colorBufferObject); - GL15.glDeleteBuffers(textureBufferObject); - material.destroy(); GL30.glDeleteVertexArrays(vertexArrayObject); } @@ -59,19 +55,8 @@ public class Mesh { return colorBufferObject; } - public int getTextureBufferObject() { - return textureBufferObject; - } - - public Material getMaterial() { - return material; - } - public void create() { - // Create the material - material.create(); - // Creates the mesh by formatting the vertices and indices and inputting them to OpenGL vertexArrayObject = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vertexArrayObject); @@ -103,16 +88,6 @@ public class Mesh { colorBufferObject = storeData(colorBuffer, 1, 3); - FloatBuffer textureBuffer = MemoryUtil.memAllocFloat(vertices.length * 2); - float[] textureData = new float[vertices.length * 3]; - for (int i = 0; i < vertices.length; i ++ ) { - textureData[i * 2] = vertices[i].getTextureCoordinates().getX(); - textureData[i * 2 + 1] = vertices[i].getTextureCoordinates().getY(); - } - textureBuffer.put(colorData).flip(); - - textureBufferObject = storeData(textureBuffer, 2, 2); - IntBuffer indicesBuffer = MemoryUtil.memAllocInt(indices.length); indicesBuffer.put(indices).flip(); diff --git a/src/org/hl/engine/graphics/Renderer.java b/src/org/hl/engine/graphics/Renderer.java index b0e7e31..17f7c53 100644 --- a/src/org/hl/engine/graphics/Renderer.java +++ b/src/org/hl/engine/graphics/Renderer.java @@ -1,7 +1,6 @@ package org.hl.engine.graphics; import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL13; import org.lwjgl.opengl.GL15; import org.lwjgl.opengl.GL30; @@ -20,10 +19,8 @@ public class Renderer { GL30.glBindVertexArray(mesh.getVertexArrayObject()); GL30.glEnableVertexAttribArray(0); GL30.glEnableVertexAttribArray(1); - GL30.glEnableVertexAttribArray(2); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, mesh.getIndicesBufferObject()); - GL13.glActiveTexture(GL13.GL_TEXTURE0); - GL13.glBindTexture(GL11.GL_TEXTURE_2D, mesh.getMaterial().getTextureID()); + shader.bind(); GL11.glDrawElements(GL11.GL_TRIANGLES, mesh.getIndices().length, GL11.GL_UNSIGNED_INT, 0); @@ -31,7 +28,6 @@ public class Renderer { shader.unbind(); GL30.glDisableVertexAttribArray(0); GL30.glDisableVertexAttribArray(1); - GL30.glDisableVertexAttribArray(2); GL30.glBindVertexArray(0); } diff --git a/src/org/hl/engine/graphics/Vertex.java b/src/org/hl/engine/graphics/Vertex.java index 3d81c3c..5e2df5b 100644 --- a/src/org/hl/engine/graphics/Vertex.java +++ b/src/org/hl/engine/graphics/Vertex.java @@ -1,7 +1,6 @@ package org.hl.engine.graphics; -import org.hl.engine.math.lalg.Vector2f; -import org.hl.engine.math.lalg.Vector3f; +import org.hl.engine.math.Vector3f; public class Vertex { @@ -9,22 +8,16 @@ public class Vertex { private Vector3f position; private Vector3f color; - private Vector2f textureCoordinates; - public Vertex (Vector3f position, Vector3f color, Vector2f textureCoordinates) { + public Vertex (Vector3f position, Vector3f color) { this.position = position; this.color = color; - this.textureCoordinates = textureCoordinates; } public Vector3f getPosition() { return position; } - public Vector2f getTextureCoordinates() { - return textureCoordinates; - } - public Vector3f getColor() { return color; } diff --git a/src/org/hl/engine/io/Display.java b/src/org/hl/engine/io/Display.java index d9126f7..0c0c5ec 100644 --- a/src/org/hl/engine/io/Display.java +++ b/src/org/hl/engine/io/Display.java @@ -1,5 +1,5 @@ package org.hl.engine.io; -import org.hl.engine.math.lalg.Vector3f; +import org.hl.engine.math.Vector3f; import org.lwjgl.glfw.GLFWVidMode; import org.lwjgl.glfw.GLFWWindowSizeCallback; import org.lwjgl.opengl.GL; @@ -102,8 +102,8 @@ public class Display { System.exit(1); } - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL11.GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); diff --git a/src/org/hl/engine/math/lalg/Vector3f.java b/src/org/hl/engine/math/Vector3f.java similarity index 95% rename from src/org/hl/engine/math/lalg/Vector3f.java rename to src/org/hl/engine/math/Vector3f.java index b2a87f0..fa1da5e 100644 --- a/src/org/hl/engine/math/lalg/Vector3f.java +++ b/src/org/hl/engine/math/Vector3f.java @@ -1,4 +1,4 @@ -package org.hl.engine.math.lalg; +package org.hl.engine.math; public class Vector3f { private float x; diff --git a/src/org/hl/engine/math/lalg/Vector2f.java b/src/org/hl/engine/math/lalg/Vector2f.java deleted file mode 100644 index 7b385cd..0000000 --- a/src/org/hl/engine/math/lalg/Vector2f.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.hl.engine.math.lalg; - -public class Vector2f { - private float x, y; - - // Just a vector if you know what I mean - public Vector2f (float x, float y) { - this.x = x; - this.y = y; - } - - public float getX() { - return x; - } - - public void setX(float x) { - this.x = x; - } - - public float getY() { - return y; - } - - public void setY(float y) { - this.y = y; - } - - public void setVector(float x, float y) { - this.x = x; - this.y = y; - } -} diff --git a/src/org/hl/engine/utils/TextureLoader.java b/src/org/hl/engine/utils/TextureLoader.java index 32ce01f..7f3e0b7 100644 --- a/src/org/hl/engine/utils/TextureLoader.java +++ b/src/org/hl/engine/utils/TextureLoader.java @@ -1,5 +1,6 @@ package org.hl.engine.utils; +// Original TextureLoader by Krythic (replaces SlickUtils texture loader) import java.awt.image.BufferedImage; import java.io.IOException; diff --git a/src/resources/shaders/mainFragment.glsl b/src/resources/shaders/mainFragment.glsl index 647b0dc..85d4098 100644 --- a/src/resources/shaders/mainFragment.glsl +++ b/src/resources/shaders/mainFragment.glsl @@ -1,12 +1,9 @@ -#version 460 core +#version 330 core in vec3 passColor; -in vec3 passTextureCoord; out vec4 outColor; -uniform sampler2D tex; - void main() { - outColor = texture(tex, passTextureCoord); + outColor = vec4(passColor, 1.0); } diff --git a/src/resources/shaders/mainVertex.glsl b/src/resources/shaders/mainVertex.glsl index 78ba706..9ae1698 100644 --- a/src/resources/shaders/mainVertex.glsl +++ b/src/resources/shaders/mainVertex.glsl @@ -1,14 +1,11 @@ -#version 460 core +#version 330 core -in vec3 position; -in vec3 color; -in vec2 textureCoordinates; +layout(location = 0) in vec3 position; +layout(location = 1) in vec3 color; out vec3 passColor; -out vec2 passTextureCoord; void main() { gl_Position = vec4(position, 1.0); passColor = color; - passTextureCoord = textureCoordinates; } \ No newline at end of file diff --git a/src/resources/textures/beautiful.png b/src/resources/textures/beautiful.png deleted file mode 100644 index ffe963ef4dd2c0a504e694b733c8f1f274fe07cb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5785 zcmdsbXH*m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b9730b4c5. removing textureloader --- src/Test.java | 17 ++++------ src/org/hl/engine/graphics/Material.java | 5 ++- src/org/hl/engine/graphics/Mesh.java | 29 ++++++++++++++-- src/org/hl/engine/graphics/Renderer.java | 6 +++- src/org/hl/engine/graphics/Vertex.java | 11 ++++-- src/org/hl/engine/io/Display.java | 6 ++-- src/org/hl/engine/math/lalg/Vector2f.java | 32 ++++++++++++++++++ .../hl/engine/math/{ => lalg}/Vector3f.java | 2 +- src/org/hl/engine/utils/TextureLoader.java | 1 - src/resources/shaders/mainFragment.glsl | 7 ++-- src/resources/shaders/mainVertex.glsl | 9 +++-- src/resources/textures/beautiful.png | Bin 0 -> 5785 bytes 12 files changed, 99 insertions(+), 26 deletions(-) create mode 100644 src/org/hl/engine/math/lalg/Vector2f.java rename src/org/hl/engine/math/{ => lalg}/Vector3f.java (95%) create mode 100644 src/resources/textures/beautiful.png diff --git a/src/Test.java b/src/Test.java index 1c153f3..757a0fe 100644 --- a/src/Test.java +++ b/src/Test.java @@ -1,10 +1,7 @@ -import org.hl.engine.graphics.Mesh; -import org.hl.engine.graphics.Renderer; -import org.hl.engine.graphics.Shader; -import org.hl.engine.graphics.Vertex; +import org.hl.engine.graphics.*; import org.hl.engine.io.Display; import org.hl.engine.io.Input; -import org.hl.engine.math.Vector3f; +import org.hl.engine.math.lalg.*; import org.lwjgl.glfw.GLFW; @@ -18,16 +15,16 @@ public class Test { public Shader shader; public Mesh mesh = new Mesh(new Vertex[] { - new Vertex(new Vector3f(-0.5F, 0.5F, 0.0F), new Vector3f(0, 0, 1.0F)), - new Vertex(new Vector3f(-0.5F, -0.5F, 0.0F), new Vector3f(0, 0, 1.0F)), - new Vertex(new Vector3f(0.5F, -0.5F, 0.0F), new Vector3f(1.0F, 0, 1.0F)), - new Vertex(new Vector3f(0.5F, 0.5F, 0.0F), new Vector3f(1.0F, 0, 1.0F) ), + new Vertex(new Vector3f(-0.5F, 0.5F, 0.0F), new Vector3f(0, 0, 1.0F), new Vector2f(0, 0)), + new Vertex(new Vector3f(-0.5F, -0.5F, 0.0F), new Vector3f(0, 0, 1.0F), new Vector2f(0, 1)), + new Vertex(new Vector3f(0.5F, -0.5F, 0.0F), new Vector3f(1.0F, 0, 1.0F), new Vector2f(1, 1)), + new Vertex(new Vector3f(0.5F, 0.5F, 0.0F), new Vector3f(1.0F, 0, 1.0F), new Vector2f(1, 0)), }, new int[] { 0, 1, 2, 0, 2, 3 - }); + }, new Material("/textures/beautiful.png")); public void run() { init(); diff --git a/src/org/hl/engine/graphics/Material.java b/src/org/hl/engine/graphics/Material.java index becaef4..3cfbd8b 100644 --- a/src/org/hl/engine/graphics/Material.java +++ b/src/org/hl/engine/graphics/Material.java @@ -14,13 +14,16 @@ public class Material { private int width, height; private int textureID; + private String path; public Material(String path) { - this.image = TextureLoader.loadImage(path); //The path is inside the jar file + this.path = path; } public void create() { + // Loading image on create + this.image = TextureLoader.loadImage(path); //The path is inside the jar file this.width = this.image.getWidth(); this.height = this.image.getHeight(); this.textureID = TextureLoader.loadTexture(image); diff --git a/src/org/hl/engine/graphics/Mesh.java b/src/org/hl/engine/graphics/Mesh.java index b6d6194..f59c735 100644 --- a/src/org/hl/engine/graphics/Mesh.java +++ b/src/org/hl/engine/graphics/Mesh.java @@ -12,12 +12,14 @@ import java.nio.IntBuffer; public class Mesh { private Vertex[] vertices; private int[] indices; - private int vertexArrayObject, positionBufferObject, indicesBufferObject, colorBufferObject; + private Material material; + private int vertexArrayObject, positionBufferObject, indicesBufferObject, colorBufferObject, textureBufferObject; // A group of vertices combined based on the indexes - public Mesh(Vertex[] vertices, int[] indices) { + public Mesh(Vertex[] vertices, int[] indices, Material material) { this.vertices = vertices; this.indices = indices; + this.material = material; } // Destroy the mesh @@ -25,6 +27,8 @@ public class Mesh { GL15.glDeleteBuffers(positionBufferObject); GL15.glDeleteBuffers(indicesBufferObject); GL15.glDeleteBuffers(colorBufferObject); + GL15.glDeleteBuffers(textureBufferObject); + material.destroy(); GL30.glDeleteVertexArrays(vertexArrayObject); } @@ -55,8 +59,19 @@ public class Mesh { return colorBufferObject; } + public int getTextureBufferObject() { + return textureBufferObject; + } + + public Material getMaterial() { + return material; + } + public void create() { + // Create the material + material.create(); + // Creates the mesh by formatting the vertices and indices and inputting them to OpenGL vertexArrayObject = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vertexArrayObject); @@ -88,6 +103,16 @@ public class Mesh { colorBufferObject = storeData(colorBuffer, 1, 3); + FloatBuffer textureBuffer = MemoryUtil.memAllocFloat(vertices.length * 2); + float[] textureData = new float[vertices.length * 3]; + for (int i = 0; i < vertices.length; i ++ ) { + textureData[i * 2] = vertices[i].getTextureCoordinates().getX(); + textureData[i * 2 + 1] = vertices[i].getTextureCoordinates().getY(); + } + textureBuffer.put(colorData).flip(); + + textureBufferObject = storeData(textureBuffer, 2, 2); + IntBuffer indicesBuffer = MemoryUtil.memAllocInt(indices.length); indicesBuffer.put(indices).flip(); diff --git a/src/org/hl/engine/graphics/Renderer.java b/src/org/hl/engine/graphics/Renderer.java index 17f7c53..b0e7e31 100644 --- a/src/org/hl/engine/graphics/Renderer.java +++ b/src/org/hl/engine/graphics/Renderer.java @@ -1,6 +1,7 @@ package org.hl.engine.graphics; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL13; import org.lwjgl.opengl.GL15; import org.lwjgl.opengl.GL30; @@ -19,8 +20,10 @@ public class Renderer { GL30.glBindVertexArray(mesh.getVertexArrayObject()); GL30.glEnableVertexAttribArray(0); GL30.glEnableVertexAttribArray(1); + GL30.glEnableVertexAttribArray(2); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, mesh.getIndicesBufferObject()); - + GL13.glActiveTexture(GL13.GL_TEXTURE0); + GL13.glBindTexture(GL11.GL_TEXTURE_2D, mesh.getMaterial().getTextureID()); shader.bind(); GL11.glDrawElements(GL11.GL_TRIANGLES, mesh.getIndices().length, GL11.GL_UNSIGNED_INT, 0); @@ -28,6 +31,7 @@ public class Renderer { shader.unbind(); GL30.glDisableVertexAttribArray(0); GL30.glDisableVertexAttribArray(1); + GL30.glDisableVertexAttribArray(2); GL30.glBindVertexArray(0); } diff --git a/src/org/hl/engine/graphics/Vertex.java b/src/org/hl/engine/graphics/Vertex.java index 5e2df5b..3d81c3c 100644 --- a/src/org/hl/engine/graphics/Vertex.java +++ b/src/org/hl/engine/graphics/Vertex.java @@ -1,6 +1,7 @@ package org.hl.engine.graphics; -import org.hl.engine.math.Vector3f; +import org.hl.engine.math.lalg.Vector2f; +import org.hl.engine.math.lalg.Vector3f; public class Vertex { @@ -8,16 +9,22 @@ public class Vertex { private Vector3f position; private Vector3f color; + private Vector2f textureCoordinates; - public Vertex (Vector3f position, Vector3f color) { + public Vertex (Vector3f position, Vector3f color, Vector2f textureCoordinates) { this.position = position; this.color = color; + this.textureCoordinates = textureCoordinates; } public Vector3f getPosition() { return position; } + public Vector2f getTextureCoordinates() { + return textureCoordinates; + } + public Vector3f getColor() { return color; } diff --git a/src/org/hl/engine/io/Display.java b/src/org/hl/engine/io/Display.java index 0c0c5ec..d9126f7 100644 --- a/src/org/hl/engine/io/Display.java +++ b/src/org/hl/engine/io/Display.java @@ -1,5 +1,5 @@ package org.hl.engine.io; -import org.hl.engine.math.Vector3f; +import org.hl.engine.math.lalg.Vector3f; import org.lwjgl.glfw.GLFWVidMode; import org.lwjgl.glfw.GLFWWindowSizeCallback; import org.lwjgl.opengl.GL; @@ -102,8 +102,8 @@ public class Display { System.exit(1); } - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL11.GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); diff --git a/src/org/hl/engine/math/lalg/Vector2f.java b/src/org/hl/engine/math/lalg/Vector2f.java new file mode 100644 index 0000000..7b385cd --- /dev/null +++ b/src/org/hl/engine/math/lalg/Vector2f.java @@ -0,0 +1,32 @@ +package org.hl.engine.math.lalg; + +public class Vector2f { + private float x, y; + + // Just a vector if you know what I mean + public Vector2f (float x, float y) { + this.x = x; + this.y = y; + } + + public float getX() { + return x; + } + + public void setX(float x) { + this.x = x; + } + + public float getY() { + return y; + } + + public void setY(float y) { + this.y = y; + } + + public void setVector(float x, float y) { + this.x = x; + this.y = y; + } +} diff --git a/src/org/hl/engine/math/Vector3f.java b/src/org/hl/engine/math/lalg/Vector3f.java similarity index 95% rename from src/org/hl/engine/math/Vector3f.java rename to src/org/hl/engine/math/lalg/Vector3f.java index fa1da5e..b2a87f0 100644 --- a/src/org/hl/engine/math/Vector3f.java +++ b/src/org/hl/engine/math/lalg/Vector3f.java @@ -1,4 +1,4 @@ -package org.hl.engine.math; +package org.hl.engine.math.lalg; public class Vector3f { private float x; diff --git a/src/org/hl/engine/utils/TextureLoader.java b/src/org/hl/engine/utils/TextureLoader.java index 7f3e0b7..32ce01f 100644 --- a/src/org/hl/engine/utils/TextureLoader.java +++ b/src/org/hl/engine/utils/TextureLoader.java @@ -1,6 +1,5 @@ package org.hl.engine.utils; -// Original TextureLoader by Krythic (replaces SlickUtils texture loader) import java.awt.image.BufferedImage; import java.io.IOException; diff --git a/src/resources/shaders/mainFragment.glsl b/src/resources/shaders/mainFragment.glsl index 85d4098..647b0dc 100644 --- a/src/resources/shaders/mainFragment.glsl +++ b/src/resources/shaders/mainFragment.glsl @@ -1,9 +1,12 @@ -#version 330 core +#version 460 core in vec3 passColor; +in vec3 passTextureCoord; out vec4 outColor; +uniform sampler2D tex; + void main() { - outColor = vec4(passColor, 1.0); + outColor = texture(tex, passTextureCoord); } diff --git a/src/resources/shaders/mainVertex.glsl b/src/resources/shaders/mainVertex.glsl index 9ae1698..78ba706 100644 --- a/src/resources/shaders/mainVertex.glsl +++ b/src/resources/shaders/mainVertex.glsl @@ -1,11 +1,14 @@ -#version 330 core +#version 460 core -layout(location = 0) in vec3 position; -layout(location = 1) in vec3 color; +in vec3 position; +in vec3 color; +in vec2 textureCoordinates; out vec3 passColor; +out vec2 passTextureCoord; void main() { gl_Position = vec4(position, 1.0); passColor = color; + passTextureCoord = textureCoordinates; } \ No newline at end of file diff --git a/src/resources/textures/beautiful.png b/src/resources/textures/beautiful.png new file mode 100644 index 0000000000000000000000000000000000000000..ffe963ef4dd2c0a504e694b733c8f1f274fe07cb GIT binary patch literal 5785 zcmdsbXH*m2_jN+(5JC|UPy@J!kK;&zYHf@4B(quNi?^1z7I4Ar$(k7G-VC-~pZ0in`da`K(Nr>FB+|&Y!!V;*%-xYiL^M2H+AvPqupnIco>Jh; z3jZH6HiNyTvT zmw@)i4y}i#T1qem;y^PD0TE_!VY{vRr$74yR=M(s2t)p^(3}YQ{m{5$GW?rasGBB`eo=$`Okx$h}q$uF&-L4 zj^7-a|8($-{m$TcMimQ8nY?i5d`k6)DC`hv(SX$?8Z|_R4w7G6w8Yj&JGg{ zKI832m8h}JU;GL}N3YNAbxc8g{grq?vS>{EA4lp+>t1f?&(p?DGg;OwW3LPNuxZ{$ zRxw9%lyUPxO%g281w;pB32l~Lb_S{P~pfIqJAFm0`+E92_TCp zN^9CmSSbZuIw~tp|FRXA&k>paBT$R}2g#+-lH&;+#_gV}L7G1U_gToTU;}6eTYOkw zUf(Vs=}1UizsApiWzmTzMgws=Ot()VU48q>A3YT>0iTN8D@rwLTDG_?KuqpTJ(P?t5WhhhYkMfeztkJft4Y?OZ!vHE!%BG#=ZJZ{JG zmFVNZ#UGBSOEkTXZi<)XRG4Mhk#X`37tpE~pCb!3+0qOWaw(k!>6d?wqJ(i=185^! z3|BPWG|EAcWO)0s-T{b&aCO;=ob$NfThrid& zg%oIT!ozvXn&o+lAaf=6qUsfcEFZ4OdDwHDgPr1>-QheHZ9+huT_n0zJM&3^YLbT& zb-7wH{SMC;+~koB_c<&XwvKPLqOOuk{B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>xPc3BAk`JH#w#57@Fa7b%7sUy(9SD#3PVv7Oe`jqowTKFX(-<^JUz$ zGq1wvX5`ELnLNQPUm#~c9~-)+n=b!dH9*os8t_H%|0~mRR+~%(vI0KFqh}I&XvfI_ N6T@o;6?%5z{|D3YR%`$O literal 0 HcmV?d00001 From d2b8e7015ad284de2556d3ee1fc306a6a5e598fd Mon Sep 17 00:00:00 2001 From: EvilMuffinHa Date: Sun, 10 May 2020 10:56:40 -0400 Subject: [PATCH 4/8] Revert "adding textures (has errors)" This reverts commit eb6101d2ec2d7828c40bccf4195a2bf3ec13780a. reverting textures --- src/Test.java | 17 ++++++---- src/org/hl/engine/graphics/Material.java | 5 +-- src/org/hl/engine/graphics/Mesh.java | 29 ++-------------- src/org/hl/engine/graphics/Renderer.java | 6 +--- src/org/hl/engine/graphics/Vertex.java | 11 ++---- src/org/hl/engine/io/Display.java | 6 ++-- .../hl/engine/math/{lalg => }/Vector3f.java | 2 +- src/org/hl/engine/math/lalg/Vector2f.java | 32 ------------------ src/org/hl/engine/utils/TextureLoader.java | 1 + src/resources/shaders/mainFragment.glsl | 7 ++-- src/resources/shaders/mainVertex.glsl | 9 ++--- src/resources/textures/beautiful.png | Bin 5785 -> 0 bytes 12 files changed, 26 insertions(+), 99 deletions(-) rename src/org/hl/engine/math/{lalg => }/Vector3f.java (95%) delete mode 100644 src/org/hl/engine/math/lalg/Vector2f.java delete mode 100644 src/resources/textures/beautiful.png diff --git a/src/Test.java b/src/Test.java index 757a0fe..1c153f3 100644 --- a/src/Test.java +++ b/src/Test.java @@ -1,7 +1,10 @@ -import org.hl.engine.graphics.*; +import org.hl.engine.graphics.Mesh; +import org.hl.engine.graphics.Renderer; +import org.hl.engine.graphics.Shader; +import org.hl.engine.graphics.Vertex; import org.hl.engine.io.Display; import org.hl.engine.io.Input; -import org.hl.engine.math.lalg.*; +import org.hl.engine.math.Vector3f; import org.lwjgl.glfw.GLFW; @@ -15,16 +18,16 @@ public class Test { public Shader shader; public Mesh mesh = new Mesh(new Vertex[] { - new Vertex(new Vector3f(-0.5F, 0.5F, 0.0F), new Vector3f(0, 0, 1.0F), new Vector2f(0, 0)), - new Vertex(new Vector3f(-0.5F, -0.5F, 0.0F), new Vector3f(0, 0, 1.0F), new Vector2f(0, 1)), - new Vertex(new Vector3f(0.5F, -0.5F, 0.0F), new Vector3f(1.0F, 0, 1.0F), new Vector2f(1, 1)), - new Vertex(new Vector3f(0.5F, 0.5F, 0.0F), new Vector3f(1.0F, 0, 1.0F), new Vector2f(1, 0)), + new Vertex(new Vector3f(-0.5F, 0.5F, 0.0F), new Vector3f(0, 0, 1.0F)), + new Vertex(new Vector3f(-0.5F, -0.5F, 0.0F), new Vector3f(0, 0, 1.0F)), + new Vertex(new Vector3f(0.5F, -0.5F, 0.0F), new Vector3f(1.0F, 0, 1.0F)), + new Vertex(new Vector3f(0.5F, 0.5F, 0.0F), new Vector3f(1.0F, 0, 1.0F) ), }, new int[] { 0, 1, 2, 0, 2, 3 - }, new Material("/textures/beautiful.png")); + }); public void run() { init(); diff --git a/src/org/hl/engine/graphics/Material.java b/src/org/hl/engine/graphics/Material.java index 3cfbd8b..becaef4 100644 --- a/src/org/hl/engine/graphics/Material.java +++ b/src/org/hl/engine/graphics/Material.java @@ -14,16 +14,13 @@ public class Material { private int width, height; private int textureID; - private String path; public Material(String path) { - this.path = path; + this.image = TextureLoader.loadImage(path); //The path is inside the jar file } public void create() { - // Loading image on create - this.image = TextureLoader.loadImage(path); //The path is inside the jar file this.width = this.image.getWidth(); this.height = this.image.getHeight(); this.textureID = TextureLoader.loadTexture(image); diff --git a/src/org/hl/engine/graphics/Mesh.java b/src/org/hl/engine/graphics/Mesh.java index f59c735..b6d6194 100644 --- a/src/org/hl/engine/graphics/Mesh.java +++ b/src/org/hl/engine/graphics/Mesh.java @@ -12,14 +12,12 @@ import java.nio.IntBuffer; public class Mesh { private Vertex[] vertices; private int[] indices; - private Material material; - private int vertexArrayObject, positionBufferObject, indicesBufferObject, colorBufferObject, textureBufferObject; + private int vertexArrayObject, positionBufferObject, indicesBufferObject, colorBufferObject; // A group of vertices combined based on the indexes - public Mesh(Vertex[] vertices, int[] indices, Material material) { + public Mesh(Vertex[] vertices, int[] indices) { this.vertices = vertices; this.indices = indices; - this.material = material; } // Destroy the mesh @@ -27,8 +25,6 @@ public class Mesh { GL15.glDeleteBuffers(positionBufferObject); GL15.glDeleteBuffers(indicesBufferObject); GL15.glDeleteBuffers(colorBufferObject); - GL15.glDeleteBuffers(textureBufferObject); - material.destroy(); GL30.glDeleteVertexArrays(vertexArrayObject); } @@ -59,19 +55,8 @@ public class Mesh { return colorBufferObject; } - public int getTextureBufferObject() { - return textureBufferObject; - } - - public Material getMaterial() { - return material; - } - public void create() { - // Create the material - material.create(); - // Creates the mesh by formatting the vertices and indices and inputting them to OpenGL vertexArrayObject = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vertexArrayObject); @@ -103,16 +88,6 @@ public class Mesh { colorBufferObject = storeData(colorBuffer, 1, 3); - FloatBuffer textureBuffer = MemoryUtil.memAllocFloat(vertices.length * 2); - float[] textureData = new float[vertices.length * 3]; - for (int i = 0; i < vertices.length; i ++ ) { - textureData[i * 2] = vertices[i].getTextureCoordinates().getX(); - textureData[i * 2 + 1] = vertices[i].getTextureCoordinates().getY(); - } - textureBuffer.put(colorData).flip(); - - textureBufferObject = storeData(textureBuffer, 2, 2); - IntBuffer indicesBuffer = MemoryUtil.memAllocInt(indices.length); indicesBuffer.put(indices).flip(); diff --git a/src/org/hl/engine/graphics/Renderer.java b/src/org/hl/engine/graphics/Renderer.java index b0e7e31..17f7c53 100644 --- a/src/org/hl/engine/graphics/Renderer.java +++ b/src/org/hl/engine/graphics/Renderer.java @@ -1,7 +1,6 @@ package org.hl.engine.graphics; import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL13; import org.lwjgl.opengl.GL15; import org.lwjgl.opengl.GL30; @@ -20,10 +19,8 @@ public class Renderer { GL30.glBindVertexArray(mesh.getVertexArrayObject()); GL30.glEnableVertexAttribArray(0); GL30.glEnableVertexAttribArray(1); - GL30.glEnableVertexAttribArray(2); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, mesh.getIndicesBufferObject()); - GL13.glActiveTexture(GL13.GL_TEXTURE0); - GL13.glBindTexture(GL11.GL_TEXTURE_2D, mesh.getMaterial().getTextureID()); + shader.bind(); GL11.glDrawElements(GL11.GL_TRIANGLES, mesh.getIndices().length, GL11.GL_UNSIGNED_INT, 0); @@ -31,7 +28,6 @@ public class Renderer { shader.unbind(); GL30.glDisableVertexAttribArray(0); GL30.glDisableVertexAttribArray(1); - GL30.glDisableVertexAttribArray(2); GL30.glBindVertexArray(0); } diff --git a/src/org/hl/engine/graphics/Vertex.java b/src/org/hl/engine/graphics/Vertex.java index 3d81c3c..5e2df5b 100644 --- a/src/org/hl/engine/graphics/Vertex.java +++ b/src/org/hl/engine/graphics/Vertex.java @@ -1,7 +1,6 @@ package org.hl.engine.graphics; -import org.hl.engine.math.lalg.Vector2f; -import org.hl.engine.math.lalg.Vector3f; +import org.hl.engine.math.Vector3f; public class Vertex { @@ -9,22 +8,16 @@ public class Vertex { private Vector3f position; private Vector3f color; - private Vector2f textureCoordinates; - public Vertex (Vector3f position, Vector3f color, Vector2f textureCoordinates) { + public Vertex (Vector3f position, Vector3f color) { this.position = position; this.color = color; - this.textureCoordinates = textureCoordinates; } public Vector3f getPosition() { return position; } - public Vector2f getTextureCoordinates() { - return textureCoordinates; - } - public Vector3f getColor() { return color; } diff --git a/src/org/hl/engine/io/Display.java b/src/org/hl/engine/io/Display.java index d9126f7..0c0c5ec 100644 --- a/src/org/hl/engine/io/Display.java +++ b/src/org/hl/engine/io/Display.java @@ -1,5 +1,5 @@ package org.hl.engine.io; -import org.hl.engine.math.lalg.Vector3f; +import org.hl.engine.math.Vector3f; import org.lwjgl.glfw.GLFWVidMode; import org.lwjgl.glfw.GLFWWindowSizeCallback; import org.lwjgl.opengl.GL; @@ -102,8 +102,8 @@ public class Display { System.exit(1); } - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL11.GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); diff --git a/src/org/hl/engine/math/lalg/Vector3f.java b/src/org/hl/engine/math/Vector3f.java similarity index 95% rename from src/org/hl/engine/math/lalg/Vector3f.java rename to src/org/hl/engine/math/Vector3f.java index b2a87f0..fa1da5e 100644 --- a/src/org/hl/engine/math/lalg/Vector3f.java +++ b/src/org/hl/engine/math/Vector3f.java @@ -1,4 +1,4 @@ -package org.hl.engine.math.lalg; +package org.hl.engine.math; public class Vector3f { private float x; diff --git a/src/org/hl/engine/math/lalg/Vector2f.java b/src/org/hl/engine/math/lalg/Vector2f.java deleted file mode 100644 index 7b385cd..0000000 --- a/src/org/hl/engine/math/lalg/Vector2f.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.hl.engine.math.lalg; - -public class Vector2f { - private float x, y; - - // Just a vector if you know what I mean - public Vector2f (float x, float y) { - this.x = x; - this.y = y; - } - - public float getX() { - return x; - } - - public void setX(float x) { - this.x = x; - } - - public float getY() { - return y; - } - - public void setY(float y) { - this.y = y; - } - - public void setVector(float x, float y) { - this.x = x; - this.y = y; - } -} diff --git a/src/org/hl/engine/utils/TextureLoader.java b/src/org/hl/engine/utils/TextureLoader.java index 32ce01f..7f3e0b7 100644 --- a/src/org/hl/engine/utils/TextureLoader.java +++ b/src/org/hl/engine/utils/TextureLoader.java @@ -1,5 +1,6 @@ package org.hl.engine.utils; +// Original TextureLoader by Krythic (replaces SlickUtils texture loader) import java.awt.image.BufferedImage; import java.io.IOException; diff --git a/src/resources/shaders/mainFragment.glsl b/src/resources/shaders/mainFragment.glsl index 647b0dc..85d4098 100644 --- a/src/resources/shaders/mainFragment.glsl +++ b/src/resources/shaders/mainFragment.glsl @@ -1,12 +1,9 @@ -#version 460 core +#version 330 core in vec3 passColor; -in vec3 passTextureCoord; out vec4 outColor; -uniform sampler2D tex; - void main() { - outColor = texture(tex, passTextureCoord); + outColor = vec4(passColor, 1.0); } diff --git a/src/resources/shaders/mainVertex.glsl b/src/resources/shaders/mainVertex.glsl index 78ba706..9ae1698 100644 --- a/src/resources/shaders/mainVertex.glsl +++ b/src/resources/shaders/mainVertex.glsl @@ -1,14 +1,11 @@ -#version 460 core +#version 330 core -in vec3 position; -in vec3 color; -in vec2 textureCoordinates; +layout(location = 0) in vec3 position; +layout(location = 1) in vec3 color; out vec3 passColor; -out vec2 passTextureCoord; void main() { gl_Position = vec4(position, 1.0); passColor = color; - passTextureCoord = textureCoordinates; } \ No newline at end of file diff --git a/src/resources/textures/beautiful.png b/src/resources/textures/beautiful.png deleted file mode 100644 index ffe963ef4dd2c0a504e694b733c8f1f274fe07cb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5785 zcmdsbXH*m2_jN+(5JC|UPy@J!kK;&zYHf@4B(quNi?^1z7I4Ar$(k7G-VC-~pZ0in`da`K(Nr>FB+|&Y!!V;*%-xYiL^M2H+AvPqupnIco>Jh; z3jZH6HiNyTvT zmw@)i4y}i#T1qem;y^PD0TE_!VY{vRr$74yR=M(s2t)p^(3}YQ{m{5$GW?rasGBB`eo=$`Okx$h}q$uF&-L4 zj^7-a|8($-{m$TcMimQ8nY?i5d`k6)DC`hv(SX$?8Z|_R4w7G6w8Yj&JGg{ zKI832m8h}JU;GL}N3YNAbxc8g{grq?vS>{EA4lp+>t1f?&(p?DGg;OwW3LPNuxZ{$ zRxw9%lyUPxO%g281w;pB32l~Lb_S{P~pfIqJAFm0`+E92_TCp zN^9CmSSbZuIw~tp|FRXA&k>paBT$R}2g#+-lH&;+#_gV}L7G1U_gToTU;}6eTYO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dviiT6v}SdU0Xsw=#Fvm5#G_m z?h)-U$XOjjPGj-NM`?t~NSt|?v}HJg*9Dj0;S#btr)EV3TMOHKV5E;UGTjpH`@9;4)nC4)G4WlRINlp!!D0;<@f3q~jax=kM&ftVr+-RL!gJ`$ldd%F zBlrW~Lo+_~qISOti4EG>qgv|b8|wk5_7QX5o(AOdr3NtRE2Zwwkku}eK5Cyw+!d00u*X)h4_V*jkeAV-&sh)q9QP{d{$Q2Q)AI_oNC6!qp3tMWd)OpF_47%*Z=dX% zO3Q>vReBmaX}KfBzoe1LC?M` zAh_HuaZm4+>xPc3BAk`JH#w#57@Fa7b%7sUy(9SD#3PVv7Oe`jqowTKFX(-<^JUz$ zGq1wvX5`ELnLNQPUm#~c9~-)+n=b!dH9*os8t_H%|0~mRR+~%(vI0KFqh}I&XvfI_ N6T@o;6?%5z{|D3YR%`$O From 4ea7ec4b21fbb0e4662b47e636296138f59a9d00 Mon Sep 17 00:00:00 2001 From: EvilMuffinHa Date: Sun, 10 May 2020 12:56:21 -0400 Subject: [PATCH 5/8] adding textures (to texture branch, split due to errors) --- src/Test.java | 17 ++++----- src/org/hl/engine/graphics/Material.java | 6 +++- src/org/hl/engine/graphics/Mesh.java | 32 +++++++++++++++-- src/org/hl/engine/graphics/Renderer.java | 7 ++++ src/org/hl/engine/graphics/Vertex.java | 9 +++-- src/org/hl/engine/io/Display.java | 6 ++-- src/org/hl/engine/math/lalg/Vector2f.java | 33 ++++++++++++++++++ .../hl/engine/math/{ => lalg}/Vector3f.java | 2 +- src/resources/shaders/mainFragment.glsl | 7 ++-- src/resources/shaders/mainVertex.glsl | 9 +++-- src/resources/textures/testimg.png | Bin 0 -> 5785 bytes 11 files changed, 104 insertions(+), 24 deletions(-) create mode 100644 src/org/hl/engine/math/lalg/Vector2f.java rename src/org/hl/engine/math/{ => lalg}/Vector3f.java (95%) create mode 100644 src/resources/textures/testimg.png diff --git a/src/Test.java b/src/Test.java index 1c153f3..5b2423e 100644 --- a/src/Test.java +++ b/src/Test.java @@ -1,10 +1,7 @@ -import org.hl.engine.graphics.Mesh; -import org.hl.engine.graphics.Renderer; -import org.hl.engine.graphics.Shader; -import org.hl.engine.graphics.Vertex; +import org.hl.engine.graphics.*; import org.hl.engine.io.Display; import org.hl.engine.io.Input; -import org.hl.engine.math.Vector3f; +import org.hl.engine.math.lalg.*; import org.lwjgl.glfw.GLFW; @@ -18,16 +15,16 @@ public class Test { public Shader shader; public Mesh mesh = new Mesh(new Vertex[] { - new Vertex(new Vector3f(-0.5F, 0.5F, 0.0F), new Vector3f(0, 0, 1.0F)), - new Vertex(new Vector3f(-0.5F, -0.5F, 0.0F), new Vector3f(0, 0, 1.0F)), - new Vertex(new Vector3f(0.5F, -0.5F, 0.0F), new Vector3f(1.0F, 0, 1.0F)), - new Vertex(new Vector3f(0.5F, 0.5F, 0.0F), new Vector3f(1.0F, 0, 1.0F) ), + new Vertex(new Vector3f(-0.5F, 0.5F, 0.0F), new Vector3f(0, 0, 1.0F), new Vector2f(0, 0)), + new Vertex(new Vector3f(-0.5F, -0.5F, 0.0F), new Vector3f(0, 0, 1.0F), new Vector2f(0, 1)), + new Vertex(new Vector3f(0.5F, -0.5F, 0.0F), new Vector3f(1.0F, 0, 1.0F), new Vector2f(1, 1)), + new Vertex(new Vector3f(0.5F, 0.5F, 0.0F), new Vector3f(1.0F, 0, 1.0F), new Vector2f(1, 0)), }, new int[] { 0, 1, 2, 0, 2, 3 - }); + }, new Material("/resources/textures/testimg.png")); public void run() { init(); diff --git a/src/org/hl/engine/graphics/Material.java b/src/org/hl/engine/graphics/Material.java index becaef4..52321c5 100644 --- a/src/org/hl/engine/graphics/Material.java +++ b/src/org/hl/engine/graphics/Material.java @@ -10,6 +10,8 @@ public class Material { private Texture texture; + private String path; + private BufferedImage image; private int width, height; @@ -17,10 +19,12 @@ public class Material { public Material(String path) { - this.image = TextureLoader.loadImage(path); //The path is inside the jar file + this.path = path; } public void create() { + + this.image = TextureLoader.loadImage(path); //The path is inside the jar file this.width = this.image.getWidth(); this.height = this.image.getHeight(); this.textureID = TextureLoader.loadTexture(image); diff --git a/src/org/hl/engine/graphics/Mesh.java b/src/org/hl/engine/graphics/Mesh.java index b6d6194..99e4e49 100644 --- a/src/org/hl/engine/graphics/Mesh.java +++ b/src/org/hl/engine/graphics/Mesh.java @@ -12,12 +12,14 @@ import java.nio.IntBuffer; public class Mesh { private Vertex[] vertices; private int[] indices; - private int vertexArrayObject, positionBufferObject, indicesBufferObject, colorBufferObject; + private int vertexArrayObject, positionBufferObject, indicesBufferObject, colorBufferObject, textureBufferObject; + private Material material; // A group of vertices combined based on the indexes - public Mesh(Vertex[] vertices, int[] indices) { + public Mesh(Vertex[] vertices, int[] indices, Material material) { this.vertices = vertices; this.indices = indices; + this.material = material; } // Destroy the mesh @@ -25,8 +27,12 @@ public class Mesh { GL15.glDeleteBuffers(positionBufferObject); GL15.glDeleteBuffers(indicesBufferObject); GL15.glDeleteBuffers(colorBufferObject); + GL30.glDeleteBuffers(textureBufferObject); GL30.glDeleteVertexArrays(vertexArrayObject); + + material.destroy(); + } // getters for the mesh @@ -55,8 +61,18 @@ public class Mesh { return colorBufferObject; } + public int getTextureBufferObject() { + return textureBufferObject; + } + + public Material getMaterial() { + return material; + } + public void create() { + material.create(); + // Creates the mesh by formatting the vertices and indices and inputting them to OpenGL vertexArrayObject = GL30.glGenVertexArrays(); GL30.glBindVertexArray(vertexArrayObject); @@ -88,6 +104,18 @@ public class Mesh { colorBufferObject = storeData(colorBuffer, 1, 3); + // Putting the texture into the buffer so renderer and shader can read it + + FloatBuffer textureBuffer = MemoryUtil.memAllocFloat(vertices.length * 2); + float[] textureData = new float[vertices.length * 2]; + for (int i = 0; i < vertices.length; i ++ ) { + textureData[i * 2] = vertices[i].getTextureCoords().getX(); + textureData[i * 2 + 1] = vertices[i].getTextureCoords().getY(); + } + textureBuffer.put(textureData).flip(); + + textureBufferObject = storeData(textureBuffer, 2, 2); + IntBuffer indicesBuffer = MemoryUtil.memAllocInt(indices.length); indicesBuffer.put(indices).flip(); diff --git a/src/org/hl/engine/graphics/Renderer.java b/src/org/hl/engine/graphics/Renderer.java index 17f7c53..e85fca5 100644 --- a/src/org/hl/engine/graphics/Renderer.java +++ b/src/org/hl/engine/graphics/Renderer.java @@ -1,6 +1,7 @@ package org.hl.engine.graphics; import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL13; import org.lwjgl.opengl.GL15; import org.lwjgl.opengl.GL30; @@ -19,8 +20,13 @@ public class Renderer { GL30.glBindVertexArray(mesh.getVertexArrayObject()); GL30.glEnableVertexAttribArray(0); GL30.glEnableVertexAttribArray(1); + GL30.glEnableVertexAttribArray(2); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, mesh.getIndicesBufferObject()); + GL13.glActiveTexture(GL13.GL_TEXTURE0); + + GL13.glBindTexture(GL11.GL_TEXTURE_2D, mesh.getMaterial().getTextureID()); + shader.bind(); GL11.glDrawElements(GL11.GL_TRIANGLES, mesh.getIndices().length, GL11.GL_UNSIGNED_INT, 0); @@ -28,6 +34,7 @@ public class Renderer { shader.unbind(); GL30.glDisableVertexAttribArray(0); GL30.glDisableVertexAttribArray(1); + GL30.glDisableVertexAttribArray(2); GL30.glBindVertexArray(0); } diff --git a/src/org/hl/engine/graphics/Vertex.java b/src/org/hl/engine/graphics/Vertex.java index 5e2df5b..4a2d4ce 100644 --- a/src/org/hl/engine/graphics/Vertex.java +++ b/src/org/hl/engine/graphics/Vertex.java @@ -1,6 +1,6 @@ package org.hl.engine.graphics; -import org.hl.engine.math.Vector3f; +import org.hl.engine.math.lalg.*; public class Vertex { @@ -8,8 +8,9 @@ public class Vertex { private Vector3f position; private Vector3f color; + private Vector2f textureCoords; - public Vertex (Vector3f position, Vector3f color) { + public Vertex (Vector3f position, Vector3f color, Vector2f texture) { this.position = position; this.color = color; } @@ -21,4 +22,8 @@ public class Vertex { public Vector3f getColor() { return color; } + + public Vector2f getTextureCoords() { + return textureCoords; + } } diff --git a/src/org/hl/engine/io/Display.java b/src/org/hl/engine/io/Display.java index 0c0c5ec..d9126f7 100644 --- a/src/org/hl/engine/io/Display.java +++ b/src/org/hl/engine/io/Display.java @@ -1,5 +1,5 @@ package org.hl.engine.io; -import org.hl.engine.math.Vector3f; +import org.hl.engine.math.lalg.Vector3f; import org.lwjgl.glfw.GLFWVidMode; import org.lwjgl.glfw.GLFWWindowSizeCallback; import org.lwjgl.opengl.GL; @@ -102,8 +102,8 @@ public class Display { System.exit(1); } - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL11.GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); diff --git a/src/org/hl/engine/math/lalg/Vector2f.java b/src/org/hl/engine/math/lalg/Vector2f.java new file mode 100644 index 0000000..e1e990c --- /dev/null +++ b/src/org/hl/engine/math/lalg/Vector2f.java @@ -0,0 +1,33 @@ +package org.hl.engine.math.lalg; + +public class Vector2f { + private float x; + private float y; + + // Just a vector if you know what I mean + public Vector2f (float x, float y) { + this.x = x; + this.y = y; + } + + public void setVector(float x, float y) { + this.x = x; + this.y = y; + } + + public float getX() { + return x; + } + + public void setX(float x) { + this.x = x; + } + + public float getY() { + return y; + } + + public void setY(float y) { + this.y = y; + } +} diff --git a/src/org/hl/engine/math/Vector3f.java b/src/org/hl/engine/math/lalg/Vector3f.java similarity index 95% rename from src/org/hl/engine/math/Vector3f.java rename to src/org/hl/engine/math/lalg/Vector3f.java index fa1da5e..b2a87f0 100644 --- a/src/org/hl/engine/math/Vector3f.java +++ b/src/org/hl/engine/math/lalg/Vector3f.java @@ -1,4 +1,4 @@ -package org.hl.engine.math; +package org.hl.engine.math.lalg; public class Vector3f { private float x; diff --git a/src/resources/shaders/mainFragment.glsl b/src/resources/shaders/mainFragment.glsl index 85d4098..4be6a4c 100644 --- a/src/resources/shaders/mainFragment.glsl +++ b/src/resources/shaders/mainFragment.glsl @@ -1,9 +1,12 @@ -#version 330 core +#version 460 core in vec3 passColor; +in vec2 passTextureCoord; out vec4 outColor; +uniform sampler2D tex; + void main() { - outColor = vec4(passColor, 1.0); + outColor = texture(tex, passTextureCoord); } diff --git a/src/resources/shaders/mainVertex.glsl b/src/resources/shaders/mainVertex.glsl index 9ae1698..013665a 100644 --- a/src/resources/shaders/mainVertex.glsl +++ b/src/resources/shaders/mainVertex.glsl @@ -1,11 +1,14 @@ -#version 330 core +#version 460 core -layout(location = 0) in vec3 position; -layout(location = 1) in vec3 color; +in vec3 position; +in vec3 color; +in vec2 textureCoord; out vec3 passColor; +out vec2 passTextureCoord; void main() { gl_Position = vec4(position, 1.0); passColor = color; + passTextureCoord = textureCoord; } \ No newline at end of file diff --git a/src/resources/textures/testimg.png b/src/resources/textures/testimg.png new file mode 100644 index 0000000000000000000000000000000000000000..ffe963ef4dd2c0a504e694b733c8f1f274fe07cb GIT binary patch literal 5785 zcmdsbXH*m2_jN+(5JC|UPy@J!kK;&zYHf@4B(quNi?^1z7I4Ar$(k7G-VC-~pZ0in`da`K(Nr>FB+|&Y!!V;*%-xYiL^M2H+AvPqupnIco>Jh; z3jZH6HiNyTvT zmw@)i4y}i#T1qem;y^PD0TE_!VY{vRr$74yR=M(s2t)p^(3}YQ{m{5$GW?rasGBB`eo=$`Okx$h}q$uF&-L4 zj^7-a|8($-{m$TcMimQ8nY?i5d`k6)DC`hv(SX$?8Z|_R4w7G6w8Yj&JGg{ zKI832m8h}JU;GL}N3YNAbxc8g{grq?vS>{EA4lp+>t1f?&(p?DGg;OwW3LPNuxZ{$ zRxw9%lyUPxO%g281w;pB32l~Lb_S{P~pfIqJAFm0`+E92_TCp zN^9CmSSbZuIw~tp|FRXA&k>paBT$R}2g#+-lH&;+#_gV}L7G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1ECs6=56_mbCbDhdviiT6v}SdU0Xsw=#Fvm5#G_m z?h)-U$XOjjPGj-NM`?t~NSt|?v}HJg*9Dj0;S#btr)EV3TMOHKV5E;UGTjpH`@9;4)nC4)G4WlRINlp!!D0;<@f3q~jax=kM&ftVr+-RL!gJ`$ldd%F zBlrW~Lo+_~qISOti4EG>qgv|b8|wk5_7QX5o(AOdr3NtRE2Zwwkku}eK5Cyw+!d00u*X)h4_V*jkeAV-&sh)q9QP{d{$Q2Q)AI_oNC6!qp3tMWd)OpF_47%*Z=dX% zO3Q>vReBmaX}KfBzoe1LC?M` zAh_HuaZm4+>xPc3BAk`JH#w#57@Fa7b%7sUy(9SD#3PVv7Oe`jqowTKFX(-<^JUz$ zGq1wvX5`ELnLNQPUm#~c9~-)+n=b!dH9*os8t_H%|0~mRR+~%(vI0KFqh}I&XvfI_ N6T@o;6?%5z{|D3YR%`$O literal 0 HcmV?d00001 From ebf26f18d8768c54f14811eb2290d351ee7cbebb Mon Sep 17 00:00:00 2001 From: EvilMuffinHa Date: Sat, 23 May 2020 17:31:56 -0400 Subject: [PATCH 6/8] without .idea in gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 2533bb5..0edeb44 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ # IntelliJ Idea folders -.idea out From 5fc63b6c73134564d60b02a54445069d2831179a Mon Sep 17 00:00:00 2001 From: EvilMuffinHa Date: Mon, 25 May 2020 12:55:20 -0400 Subject: [PATCH 7/8] trying to add textures and still failing --- resources/textures/testimg.png | Bin 0 -> 5785 bytes src/Test.java | 112 ++++---- src/org/hl/engine/graphics/Material.java | 121 ++++++-- src/org/hl/engine/graphics/Mesh.java | 188 ++++++------ src/org/hl/engine/graphics/Renderer.java | 42 +-- src/org/hl/engine/graphics/Shader.java | 116 ++++---- src/org/hl/engine/graphics/Texture.java | 133 +++++++++ src/org/hl/engine/graphics/Vertex.java | 34 +-- src/org/hl/engine/io/Display.java | 316 +++++++++++---------- src/org/hl/engine/io/Input.java | 164 +++++------ src/org/hl/engine/math/lalg/Vector2f.java | 46 +-- src/org/hl/engine/math/lalg/Vector3f.java | 64 ++--- src/org/hl/engine/math/lalg/Vector4f.java | 55 ++++ src/org/hl/engine/utils/FileUtils.java | 30 +- src/org/hl/engine/utils/TextureLoader.java | 84 +++--- src/resources/shaders/mainFragment.glsl | 2 +- src/resources/shaders/mainVertex.glsl | 2 +- 17 files changed, 882 insertions(+), 627 deletions(-) create mode 100644 resources/textures/testimg.png create mode 100644 src/org/hl/engine/graphics/Texture.java create mode 100644 src/org/hl/engine/math/lalg/Vector4f.java diff --git a/resources/textures/testimg.png b/resources/textures/testimg.png new file mode 100644 index 0000000000000000000000000000000000000000..ffe963ef4dd2c0a504e694b733c8f1f274fe07cb GIT binary patch literal 5785 zcmdsbXH*m2_jN+(5JC|UPy@J!kK;&zYHf@4B(quNi?^1z7I4Ar$(k7G-VC-~pZ0in`da`K(Nr>FB+|&Y!!V;*%-xYiL^M2H+AvPqupnIco>Jh; z3jZH6HiNyTvT zmw@)i4y}i#T1qem;y^PD0TE_!VY{vRr$74yR=M(s2t)p^(3}YQ{m{5$GW?rasGBB`eo=$`Okx$h}q$uF&-L4 zj^7-a|8($-{m$TcMimQ8nY?i5d`k6)DC`hv(SX$?8Z|_R4w7G6w8Yj&JGg{ zKI832m8h}JU;GL}N3YNAbxc8g{grq?vS>{EA4lp+>t1f?&(p?DGg;OwW3LPNuxZ{$ zRxw9%lyUPxO%g281w;pB32l~Lb_S{P~pfIqJAFm0`+E92_TCp zN^9CmSSbZuIw~tp|FRXA&k>paBT$R}2g#+-lH&;+#_gV}L7G1U_gToTU;}6eTYOkw zUf(Vs=}1UizsApiWzmTzMgws=Ot()VU48q>A3YT>0iTN8D@rwLTDG_?KuqpTJ(P?t5WhhhYkMfeztkJft4Y?OZ!vHE!%BG#=ZJZ{JG zmFVNZ#UGBSOEkTXZi<)XRG4Mhk#X`37tpE~pCb!3+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lo+_~qISOti4EG>qgv|b8|wk5_7QX5o(AOdr3NtRE2Zwwkku}eK5Cyw+!d00u*X)h4_V*jkeAV-&sh)q9QP{d{$Q2Q)AI_oNC6!qp3tMWd)OpF_47%*Z=dX% zO3Q>vReBmaX}KfBzoe1LC?M` zAh_HuaZm4+>xPc3BAk`JH#w#57@Fa7b%7sUy(9SD#3PVv7Oe`jqowTKFX(-<^JUz$ zGq1wvX5`ELnLNQPUm#~c9~-)+n=b!dH9*os8t_H%|0~mRR+~%(vI0KFqh}I&XvfI_ N6T@o;6?%5z{|D3YR%`$O literal 0 HcmV?d00001 diff --git a/src/Test.java b/src/Test.java index 5b2423e..45cb36a 100644 --- a/src/Test.java +++ b/src/Test.java @@ -7,70 +7,76 @@ import org.lwjgl.glfw.GLFW; public class Test { - public final static int WIDTH = 640, HEIGHT = 480; - public final String windowName = "Game!"; - public Display display; - public Input i; - public Renderer renderer; - public Shader shader; + public final static int WIDTH = 640, HEIGHT = 480; + public final String windowName = "Game!"; + public Display display; + public Input i; + public Renderer renderer; + public Shader shader; - public Mesh mesh = new Mesh(new Vertex[] { - new Vertex(new Vector3f(-0.5F, 0.5F, 0.0F), new Vector3f(0, 0, 1.0F), new Vector2f(0, 0)), - new Vertex(new Vector3f(-0.5F, -0.5F, 0.0F), new Vector3f(0, 0, 1.0F), new Vector2f(0, 1)), - new Vertex(new Vector3f(0.5F, -0.5F, 0.0F), new Vector3f(1.0F, 0, 1.0F), new Vector2f(1, 1)), - new Vertex(new Vector3f(0.5F, 0.5F, 0.0F), new Vector3f(1.0F, 0, 1.0F), new Vector2f(1, 0)), + public Mesh mesh = new Mesh(new Vertex[] { + new Vertex(new Vector3f(-0.5F, 0.5F, 0.0F), new Vector3f(0, 0, 1.0F), new Vector2f(0, 0)), + new Vertex(new Vector3f(-0.5F, -0.5F, 0.0F), new Vector3f(0, 0, 1.0F), new Vector2f(0, 1)), + new Vertex(new Vector3f(0.5F, -0.5F, 0.0F), new Vector3f(1.0F, 0, 1.0F), new Vector2f(1, 1)), + new Vertex(new Vector3f(0.5F, 0.5F, 0.0F), new Vector3f(1.0F, 0, 1.0F), new Vector2f(1, 0)), - }, new int[] { - 0, 1, 2, - 0, 2, 3 + }, new int[] { + 0, 1, 2, + 0, 2, 3 - }, new Material("/resources/textures/testimg.png")); + }, new Material(new Texture("resources/textures/testimg.png"))); - public void run() { - init(); - i = new Input(display); - while (!(display.shouldClose()) && !i.isKeyDown(GLFW.GLFW_KEY_ESCAPE)) { - update(); - render(); - } + public void run() throws Exception { + setup(); + i = new Input(display); + while (!(display.shouldClose()) && !i.isKeyDown(GLFW.GLFW_KEY_ESCAPE)) { + loop(); + } - close(); + close(); - } - public void init() { - // System.out.println("Initializing Game "); - display = new Display(WIDTH, HEIGHT, windowName); - shader = new Shader("/resources/shaders/mainVertex.glsl", "/resources/shaders/mainFragment.glsl"); - renderer = new Renderer(shader); - display.setBackgroundColor(1F, 0, 0); - display.create(); - mesh.create(); - shader.create(); + } - } - private void update() { - // System.out.println("Updating "); - int frames = display.update(); - display.setWindowName(display.getWindowName().substring(0, 4) + " (Frames : " + frames + ")"); + public void loop() { + update(); + render(); + } - i.reset(); - } + public void setup() throws Exception { + // System.out.println("Initializing Game "); + display = new Display(WIDTH, HEIGHT, windowName); + display.create(); + shader = new Shader("/resources/shaders/mainVertex.glsl", "/resources/shaders/mainFragment.glsl"); + renderer = new Renderer(shader); + display.setBackgroundColor(1F, 0, 0); + mesh.create(); + shader.create(); - private void render() { - // System.out.println("Rendering "); - renderer.renderMesh(mesh); - display.swapBuffers(); + } + private void update() { + // System.out.println("Updating "); + int frames = display.update(); + display.setWindowName(display.getWindowName().substring(0, 4) + " (Frames : " + frames + ")"); - } + i.reset(); - private void close() { - display.destroy(); - mesh.destroy(); - shader.destroy(); - } + } - public static void main(String[] args) { - new Test().run(); - } + private void render() { + // System.out.println("Rendering "); + renderer.renderMesh(mesh); + display.swapBuffers(); + + } + + private void close() { + display.destroy(); + mesh.destroy(); + shader.destroy(); + } + + public static void main(String[] args) throws Exception { + new Test().run(); + } } diff --git a/src/org/hl/engine/graphics/Material.java b/src/org/hl/engine/graphics/Material.java index 52321c5..0436d6a 100644 --- a/src/org/hl/engine/graphics/Material.java +++ b/src/org/hl/engine/graphics/Material.java @@ -1,48 +1,107 @@ package org.hl.engine.graphics; -import org.hl.engine.utils.TextureLoader; -import org.lwjgl.opengl.GL11; -import org.lwjgl.openvr.Texture; - -import java.awt.image.BufferedImage; +import org.hl.engine.math.lalg.Vector4f; public class Material { + private static final Vector4f DEFAULT_COLOR = new Vector4f(1.0f, 1.0f, 1.0f, 1.0f); - private Texture texture; + private Vector4f ambientColor; - private String path; + private Vector4f diffuseColor; - private BufferedImage image; + private Vector4f specularColor; - private int width, height; - private int textureID; + private float reflectance; - public Material(String path) { + private Texture texture; - this.path = path; + private Texture normalMap; - } - public void create() { + public Material() { + this.ambientColor = DEFAULT_COLOR; + this.diffuseColor = DEFAULT_COLOR; + this.specularColor = DEFAULT_COLOR; + this.texture = null; + this.reflectance = 0; + } - this.image = TextureLoader.loadImage(path); //The path is inside the jar file - this.width = this.image.getWidth(); - this.height = this.image.getHeight(); - this.textureID = TextureLoader.loadTexture(image); - } + public Material(Vector4f color, float reflectance) { + this(color, color, color, null, reflectance); + } - public int getWidth() { - return width; - } + public Material(Texture texture) { + this(DEFAULT_COLOR, DEFAULT_COLOR, DEFAULT_COLOR, texture, 0); + } - public int getHeight() { - return height; - } + public Material(Texture texture, float reflectance) { + this(DEFAULT_COLOR, DEFAULT_COLOR, DEFAULT_COLOR, texture, reflectance); + } - public int getTextureID() { - return textureID; - } + public Material(Vector4f ambientColor, Vector4f diffuseColor, Vector4f specularColor, Texture texture, float reflectance) { + this.ambientColor = ambientColor; + this.diffuseColor = diffuseColor; + this.specularColor = specularColor; + this.texture = texture; + this.reflectance = reflectance; + } - public void destroy() { - GL11.glDeleteTextures(textureID); - } + public Vector4f getAmbientColor() { + return ambientColor; + } + + public void setAmbientColor(Vector4f ambientColor) { + this.ambientColor = ambientColor; + } + + public Vector4f getDiffuseColor() { + return diffuseColor; + } + + public void setDiffuseColor(Vector4f diffuseColor) { + this.diffuseColor = diffuseColor; + } + + public Vector4f getSpecularColor() { + return specularColor; + } + + public void setSpecularColor(Vector4f specularColor) { + this.specularColor = specularColor; + } + + public float getReflectance() { + return reflectance; + } + + public void setReflectance(float reflectance) { + this.reflectance = reflectance; + } + + public boolean isTextured() { + return this.texture != null; + } + + public Texture getTexture() { + return texture; + } + + public void setTexture(Texture texture) { + this.texture = texture; + } + + public boolean hasNormalMap() { + return this.normalMap != null; + } + + public Texture getNormalMap() { + return normalMap; + } + + public void setNormalMap(Texture normalMap) { + this.normalMap = normalMap; + } + + public void create() { + texture.create(); + } } diff --git a/src/org/hl/engine/graphics/Mesh.java b/src/org/hl/engine/graphics/Mesh.java index 99e4e49..e447225 100644 --- a/src/org/hl/engine/graphics/Mesh.java +++ b/src/org/hl/engine/graphics/Mesh.java @@ -10,130 +10,130 @@ import java.nio.FloatBuffer; import java.nio.IntBuffer; public class Mesh { - private Vertex[] vertices; - private int[] indices; - private int vertexArrayObject, positionBufferObject, indicesBufferObject, colorBufferObject, textureBufferObject; - private Material material; + private Vertex[] vertices; + private int[] indices; + private int vertexArrayObject, positionBufferObject, indicesBufferObject, colorBufferObject, textureBufferObject; + private Material material; - // A group of vertices combined based on the indexes - public Mesh(Vertex[] vertices, int[] indices, Material material) { - this.vertices = vertices; - this.indices = indices; - this.material = material; - } + // A group of vertices combined based on the indexes + public Mesh(Vertex[] vertices, int[] indices, Material material) { + this.vertices = vertices; + this.indices = indices; + this.material = material; + } - // Destroy the mesh - public void destroy () { - GL15.glDeleteBuffers(positionBufferObject); - GL15.glDeleteBuffers(indicesBufferObject); - GL15.glDeleteBuffers(colorBufferObject); - GL30.glDeleteBuffers(textureBufferObject); + // Destroy the mesh + public void destroy () { + GL15.glDeleteBuffers(positionBufferObject); + GL15.glDeleteBuffers(indicesBufferObject); + GL15.glDeleteBuffers(colorBufferObject); + GL30.glDeleteBuffers(textureBufferObject); - GL30.glDeleteVertexArrays(vertexArrayObject); + GL30.glDeleteVertexArrays(vertexArrayObject); - material.destroy(); + material.getTexture().destroy(); - } + } - // getters for the mesh + // getters for the mesh - public Vertex[] getVertices() { - return vertices; - } + public Vertex[] getVertices() { + return vertices; + } - public int[] getIndices() { - return indices; - } + public int[] getIndices() { + return indices; + } - public int getVertexArrayObject() { - return vertexArrayObject; - } + public int getVertexArrayObject() { + return vertexArrayObject; + } - public int getPositionBufferObject() { - return positionBufferObject; - } + public int getPositionBufferObject() { + return positionBufferObject; + } - public int getIndicesBufferObject() { - return indicesBufferObject; - } + public int getIndicesBufferObject() { + return indicesBufferObject; + } - public int getColorBufferObject() { - return colorBufferObject; - } + public int getColorBufferObject() { + return colorBufferObject; + } - public int getTextureBufferObject() { - return textureBufferObject; - } + public int getTextureBufferObject() { + return textureBufferObject; + } - public Material getMaterial() { - return material; - } + public Material getMaterial() { + return material; + } - public void create() { + public void create() { - material.create(); + material.create(); - // Creates the mesh by formatting the vertices and indices and inputting them to OpenGL - vertexArrayObject = GL30.glGenVertexArrays(); - GL30.glBindVertexArray(vertexArrayObject); + // Creates the mesh by formatting the vertices and indices and inputting them to OpenGL + vertexArrayObject = GL30.glGenVertexArrays(); + GL30.glBindVertexArray(vertexArrayObject); - // Putting the position of the vertex into the buffer so the renderer can read it + // Putting the position of the vertex into the buffer so the renderer can read it - FloatBuffer positionBuffer = MemoryUtil.memAllocFloat(vertices.length * 3); - float[] positionData = new float[vertices.length * 3]; - for (int i = 0; i < vertices.length; i ++ ) { - positionData[i * 3] = vertices[i].getPosition().getX(); - positionData[i * 3 + 1] = vertices[i].getPosition().getY(); - positionData[i * 3 + 2] = vertices[i].getPosition().getZ(); - } - positionBuffer.put(positionData).flip(); + FloatBuffer positionBuffer = MemoryUtil.memAllocFloat(vertices.length * 3); + float[] positionData = new float[vertices.length * 3]; + for (int i = 0; i < vertices.length; i ++ ) { + positionData[i * 3] = vertices[i].getPosition().getX(); + positionData[i * 3 + 1] = vertices[i].getPosition().getY(); + positionData[i * 3 + 2] = vertices[i].getPosition().getZ(); + } + positionBuffer.put(positionData).flip(); - positionBufferObject = storeData(positionBuffer, 0, 3); + positionBufferObject = storeData(positionBuffer, 0, 3); - // Putting the color into the buffer so renderer and shader can read it + // Putting the color into the buffer so renderer and shader can read it - FloatBuffer colorBuffer = MemoryUtil.memAllocFloat(vertices.length * 3); - float[] colorData = new float[vertices.length * 3]; - for (int i = 0; i < vertices.length; i ++ ) { - colorData[i * 3] = vertices[i].getColor().getX(); - colorData[i * 3 + 1] = vertices[i].getColor().getY(); - colorData[i * 3 + 2] = vertices[i].getColor().getZ(); - } - colorBuffer.put(colorData).flip(); + FloatBuffer colorBuffer = MemoryUtil.memAllocFloat(vertices.length * 3); + float[] colorData = new float[vertices.length * 3]; + for (int i = 0; i < vertices.length; i ++ ) { + colorData[i * 3] = vertices[i].getColor().getX(); + colorData[i * 3 + 1] = vertices[i].getColor().getY(); + colorData[i * 3 + 2] = vertices[i].getColor().getZ(); + } + colorBuffer.put(colorData).flip(); - colorBufferObject = storeData(colorBuffer, 1, 3); + colorBufferObject = storeData(colorBuffer, 1, 3); - // Putting the texture into the buffer so renderer and shader can read it + // Putting the texture into the buffer so renderer and shader can read it - FloatBuffer textureBuffer = MemoryUtil.memAllocFloat(vertices.length * 2); - float[] textureData = new float[vertices.length * 2]; - for (int i = 0; i < vertices.length; i ++ ) { - textureData[i * 2] = vertices[i].getTextureCoords().getX(); - textureData[i * 2 + 1] = vertices[i].getTextureCoords().getY(); - } - textureBuffer.put(textureData).flip(); + FloatBuffer textureBuffer = MemoryUtil.memAllocFloat(vertices.length * 2); + float[] textureData = new float[vertices.length * 2]; + for (int i = 0; i < vertices.length; i ++ ) { + textureData[i * 2] = vertices[i].getTextureCoords().getX(); + textureData[i * 2 + 1] = vertices[i].getTextureCoords().getY(); + } + textureBuffer.put(textureData).flip(); - textureBufferObject = storeData(textureBuffer, 2, 2); + textureBufferObject = storeData(textureBuffer, 2, 2); - IntBuffer indicesBuffer = MemoryUtil.memAllocInt(indices.length); - indicesBuffer.put(indices).flip(); + IntBuffer indicesBuffer = MemoryUtil.memAllocInt(indices.length); + indicesBuffer.put(indices).flip(); - indicesBufferObject = GL15.glGenBuffers(); - GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBufferObject); - GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW); - GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); - } + indicesBufferObject = GL15.glGenBuffers(); + GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBufferObject); + GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW); + GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); + } - // Storing data to the buffer at position index (helps with storing color / position) + // Storing data to the buffer at position index (helps with storing color / position) - private int storeData(FloatBuffer buffer, int index, int size) { - int bufferID = GL15.glGenBuffers(); - GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, bufferID); - GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); - GL20.glVertexAttribPointer(index, size, GL11.GL_FLOAT, false, 0, 0); - GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); + private int storeData(FloatBuffer buffer, int index, int size) { + int bufferID = GL15.glGenBuffers(); + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, bufferID); + GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); + GL20.glVertexAttribPointer(index, size, GL11.GL_FLOAT, false, 0, 0); + GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); - return bufferID; - } + return bufferID; + } } diff --git a/src/org/hl/engine/graphics/Renderer.java b/src/org/hl/engine/graphics/Renderer.java index e85fca5..421f5e4 100644 --- a/src/org/hl/engine/graphics/Renderer.java +++ b/src/org/hl/engine/graphics/Renderer.java @@ -7,35 +7,35 @@ import org.lwjgl.opengl.GL30; public class Renderer { - private Shader shader; + private Shader shader; - public Renderer(Shader shader) { - this.shader = shader; - } + public Renderer(Shader shader) { + this.shader = shader; + } - public void renderMesh(Mesh mesh) { + public void renderMesh(Mesh mesh) { - // Renders the mesh by drawing it using triangles (least complicated) - GL30.glBindVertexArray(mesh.getVertexArrayObject()); - GL30.glEnableVertexAttribArray(0); - GL30.glEnableVertexAttribArray(1); - GL30.glEnableVertexAttribArray(2); - GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, mesh.getIndicesBufferObject()); + // Renders the mesh by drawing it using triangles (least complicated) + GL30.glBindVertexArray(mesh.getVertexArrayObject()); + GL30.glEnableVertexAttribArray(0); + GL30.glEnableVertexAttribArray(1); + GL30.glEnableVertexAttribArray(2); + GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, mesh.getIndicesBufferObject()); - GL13.glActiveTexture(GL13.GL_TEXTURE0); + GL13.glActiveTexture(GL13.GL_TEXTURE0); - GL13.glBindTexture(GL11.GL_TEXTURE_2D, mesh.getMaterial().getTextureID()); + GL13.glBindTexture(GL11.GL_TEXTURE_2D, mesh.getMaterial().getTexture().getId()); - shader.bind(); + shader.bind(); - GL11.glDrawElements(GL11.GL_TRIANGLES, mesh.getIndices().length, GL11.GL_UNSIGNED_INT, 0); + GL11.glDrawElements(GL11.GL_TRIANGLES, mesh.getIndices().length, GL11.GL_UNSIGNED_INT, 0); - shader.unbind(); - GL30.glDisableVertexAttribArray(0); - GL30.glDisableVertexAttribArray(1); - GL30.glDisableVertexAttribArray(2); - GL30.glBindVertexArray(0); + shader.unbind(); + GL30.glDisableVertexAttribArray(0); + GL30.glDisableVertexAttribArray(1); + GL30.glDisableVertexAttribArray(2); + GL30.glBindVertexArray(0); - } + } } diff --git a/src/org/hl/engine/graphics/Shader.java b/src/org/hl/engine/graphics/Shader.java index 5a62d04..7e87109 100644 --- a/src/org/hl/engine/graphics/Shader.java +++ b/src/org/hl/engine/graphics/Shader.java @@ -5,84 +5,84 @@ import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL20; public class Shader { - private String vertexFile; - private String fragmentFile; + private String vertexFile; + private String fragmentFile; - private int vertexID, fragmentID, programID; + private int vertexID, fragmentID, programID; - public Shader(String vertexPath, String fragmentPath) { - vertexFile = FileUtils.loadAsString(vertexPath); - fragmentFile = FileUtils.loadAsString(fragmentPath); + public Shader(String vertexPath, String fragmentPath) { + vertexFile = FileUtils.loadAsString(vertexPath); + fragmentFile = FileUtils.loadAsString(fragmentPath); - } + } - public void create() { + public void create() { - // Creates the program - programID = GL20.glCreateProgram(); + // Creates the program + programID = GL20.glCreateProgram(); - // loads the vertex shader - vertexID = GL20.glCreateShader(GL20.GL_VERTEX_SHADER); + // loads the vertex shader + vertexID = GL20.glCreateShader(GL20.GL_VERTEX_SHADER); - GL20.glShaderSource(vertexID, vertexFile); - GL20.glCompileShader(vertexID); + GL20.glShaderSource(vertexID, vertexFile); + GL20.glCompileShader(vertexID); - if (GL20.glGetShaderi(vertexID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) { - System.err.println("Vertex Shader: " + GL20.glGetShaderInfoLog(vertexID)); - System.exit(1); + if (GL20.glGetShaderi(vertexID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) { + System.err.println("Vertex Shader: " + GL20.glGetShaderInfoLog(vertexID)); + System.exit(1); - } + } - // loads the fragment shader - fragmentID = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER); + // loads the fragment shader + fragmentID = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER); - GL20.glShaderSource(fragmentID, fragmentFile); - GL20.glCompileShader(fragmentID); + GL20.glShaderSource(fragmentID, fragmentFile); + GL20.glCompileShader(fragmentID); - if (GL20.glGetShaderi(fragmentID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) { - System.err.println("Fragment Shader: " + GL20.glGetShaderInfoLog(fragmentID)); - System.exit(1); + if (GL20.glGetShaderi(fragmentID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) { + System.err.println("Fragment Shader: " + GL20.glGetShaderInfoLog(fragmentID)); + System.exit(1); - } + } - // Attach shaders to program - GL20.glAttachShader(programID, vertexID); - GL20.glAttachShader(programID, fragmentID); + // Attach shaders to program + GL20.glAttachShader(programID, vertexID); + GL20.glAttachShader(programID, fragmentID); - // Link the program - GL20.glLinkProgram(programID); - if (GL20.glGetProgrami(programID, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) { - System.err.println("Program Linking: " + GL20.glGetProgramInfoLog(programID)); - System.exit(1); - return; - } + // Link the program + GL20.glLinkProgram(programID); + if (GL20.glGetProgrami(programID, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) { + System.err.println("Program Linking: " + GL20.glGetProgramInfoLog(programID)); + System.exit(1); + return; + } - // Validate the program - GL20.glValidateProgram(programID); - if (GL20.glGetProgrami(programID, GL20.GL_VALIDATE_STATUS) == GL11.GL_FALSE) { - System.err.println("Program Validation: " + GL20.glGetProgramInfoLog(programID)); - System.exit(1); - return; - } + // Validate the program + GL20.glValidateProgram(programID); + if (GL20.glGetProgrami(programID, GL20.GL_VALIDATE_STATUS) == GL11.GL_FALSE) { + System.err.println("Program Validation: " + GL20.glGetProgramInfoLog(programID)); + System.exit(1); + return; + } - GL20.glDeleteShader(vertexID); - GL20.glDeleteShader(fragmentID); + GL20.glDeleteShader(vertexID); + GL20.glDeleteShader(fragmentID); - } + } - // Bind so we can use the shader - public void bind() { - GL20.glUseProgram(programID); - } + // Bind so we can use the shader + public void bind() { + GL20.glUseProgram(programID); + } - // Unbind the shader after use - public void unbind() { - GL20.glUseProgram(0); - } + // Unbind the shader after use + public void unbind() { + GL20.glUseProgram(0); + } - // Destroy the program - public void destroy() { - GL20.glDeleteProgram(programID); - } + // Destroy the program + public void destroy() { + GL20.glDeleteProgram(programID); + } } diff --git a/src/org/hl/engine/graphics/Texture.java b/src/org/hl/engine/graphics/Texture.java new file mode 100644 index 0000000..5325ae3 --- /dev/null +++ b/src/org/hl/engine/graphics/Texture.java @@ -0,0 +1,133 @@ +package org.hl.engine.graphics; +import static org.lwjgl.opengl.GL46.*; +import static org.lwjgl.stb.STBImage.*; + +import java.nio.ByteBuffer; +import java.nio.IntBuffer; + +import org.lwjgl.system.MemoryStack; + +public class Texture { + private int id; + + private int width; + + private int height; + + private int type; + + private String fileName; + private ByteBuffer imageBuffer; + + private int pixelFormat; + + + public Texture(int width, int height, int pixelFormat) { + this.type = 0; + this.width = width; + this.height = height; + this.pixelFormat = pixelFormat; + } + + public Texture(String fileName) { + this.type = 1; + this.fileName = fileName; + } + + public Texture(ByteBuffer imageBuffer) { + type = 2; + this.imageBuffer = imageBuffer; + } + + public void create() { + if (this.type == 0) { + this.id = glGenTextures(); + glBindTexture(GL_TEXTURE_2D, this.id); + glTexImage2D(GL_TEXTURE_2D, 0, this.pixelFormat, this.width, this.height, 0, this.pixelFormat, GL_FLOAT, (ByteBuffer) null); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glBindTexture(GL_TEXTURE_2D, 0); + + } else if (this.type == 1) { + ByteBuffer buf; + try(MemoryStack stack = MemoryStack.stackPush()) { + IntBuffer w = stack.mallocInt(1); + IntBuffer h = stack.mallocInt(1); + IntBuffer channels = stack.mallocInt(1); + + buf = stbi_load(this.fileName, w, h, channels, 4); + if(buf == null) { + System.err.println("Image file [" + this.fileName + "] not loaded: " + stbi_failure_reason()); + System.exit(1); + } + + this.width = w.get(); + this.height = h.get(); + } + + this.id = createTexture(buf); + + stbi_image_free(buf); + + } else { + ByteBuffer buf; + try(MemoryStack stack = MemoryStack.stackPush()) { + IntBuffer w = stack.mallocInt(1); + IntBuffer h = stack.mallocInt(1); + IntBuffer channels = stack.mallocInt(1); + + buf = stbi_load_from_memory(this.imageBuffer, w, h, channels, 4); + if(buf == null) { + System.err.println("Image file not loaded: " + stbi_failure_reason()); + System.exit(1); + } + + this.width = w.get(); + this.height = h.get(); + } + + this.id = createTexture(buf); + + stbi_image_free(buf); + + } + + } + + private int createTexture(ByteBuffer buf) { + int textureID = glGenTextures(); + glBindTexture(GL_TEXTURE_2D, textureID); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + 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, buf); + glGenerateMipmap(GL_TEXTURE_2D); + + glBindTexture(GL_TEXTURE_2D, 0); + + return textureID; + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return height; + } + + public int getId() { + return id; + } + + public void destroy() { + glDeleteTextures(id); + } +} + + diff --git a/src/org/hl/engine/graphics/Vertex.java b/src/org/hl/engine/graphics/Vertex.java index 4a2d4ce..3270b27 100644 --- a/src/org/hl/engine/graphics/Vertex.java +++ b/src/org/hl/engine/graphics/Vertex.java @@ -4,26 +4,26 @@ import org.hl.engine.math.lalg.*; public class Vertex { - // Just a vertex + // Just a vertex - private Vector3f position; - private Vector3f color; - private Vector2f textureCoords; + private Vector3f position; + private Vector3f color; + private Vector2f textureCoords; - public Vertex (Vector3f position, Vector3f color, Vector2f texture) { - this.position = position; - this.color = color; - } + public Vertex (Vector3f position, Vector3f color, Vector2f texture) { + this.position = position; + this.color = color; + } - public Vector3f getPosition() { - return position; - } + public Vector3f getPosition() { + return position; + } - public Vector3f getColor() { - return color; - } + public Vector3f getColor() { + return color; + } - public Vector2f getTextureCoords() { - return textureCoords; - } + public Vector2f getTextureCoords() { + return textureCoords; + } } diff --git a/src/org/hl/engine/io/Display.java b/src/org/hl/engine/io/Display.java index d9126f7..47c94bc 100644 --- a/src/org/hl/engine/io/Display.java +++ b/src/org/hl/engine/io/Display.java @@ -8,205 +8,207 @@ import org.lwjgl.opengl.GL11; import static org.lwjgl.glfw.GLFW.*; public class Display { - private int width, height; - private String windowName; - private long window; - public int frames; - public int previousFrames = frames; - public long time; - public Input input; - private Vector3f background = new Vector3f(0, 0, 0); - private GLFWWindowSizeCallback resizeCallback; - private boolean isResized; - private boolean isFullscreen; - private int[] windowXPos = new int[1]; - private int[] windowYPos = new int[1]; - private GLFWVidMode videoMode; - private int savedPosX; - private int savedPosY; - private int savedWidth; - private int savedHeight; + private int width, height; + private String windowName; + private long window; + public int frames; + public int previousFrames = frames; + public long time; + public Input input; + private Vector3f background = new Vector3f(0, 0, 0); + private GLFWWindowSizeCallback resizeCallback; + private boolean isResized; + private boolean isFullscreen; + private int[] windowXPos = new int[1]; + private int[] windowYPos = new int[1]; + private GLFWVidMode videoMode; + private int savedPosX; + private int savedPosY; + private int savedWidth; + private int savedHeight; - // Constructor to create the display - public Display (int width, int height, String windowName) { - this.width = width; - this.height = height; - this.windowName = windowName; - } + // Constructor to create the display + public Display (int width, int height, String windowName) { + this.width = width; + this.height = height; + this.windowName = windowName; + } - // Change the window name - public void setWindowName(String windowName) { - this.windowName = windowName; - glfwSetWindowTitle(window, windowName); - } + // Change the window name + public void setWindowName(String windowName) { + this.windowName = windowName; + glfwSetWindowTitle(window, windowName); + } - // Getters for size, name, window, time, and fullScreen - public int getWidth() { - return width; - } - public int getHeight() { - return height; - } - public String getWindowName() { - return windowName; - } - public long getWindow() { - return window; - } - public long getTime() { - return time; - } + // Getters for size, name, window, time, and fullScreen + public int getWidth() { + return width; + } + public int getHeight() { + return height; + } + public String getWindowName() { + return windowName; + } + public long getWindow() { + return window; + } + public long getTime() { + return time; + } - public boolean isFullscreen() { - return isFullscreen; - } + public boolean isFullscreen() { + return isFullscreen; + } - // Makes the screen fullscreen or not based on the argument - public void setFullscreen(boolean fullscreen) { - isFullscreen = fullscreen; - isResized = true; - GL11.glViewport(0, 0, width, height); - if (isFullscreen) { + // Makes the screen fullscreen or not based on the argument + public void setFullscreen(boolean fullscreen) { + isFullscreen = fullscreen; + isResized = true; + GL11.glViewport(0, 0, width, height); + if (isFullscreen) { - int[] xpos = {0}; - int[] ypos = {0}; - glfwGetWindowPos(this.window, xpos, ypos); - savedPosX = xpos[0]; - savedPosY = ypos[0]; + int[] xpos = {0}; + int[] ypos = {0}; + glfwGetWindowPos(this.window, xpos, ypos); + savedPosX = xpos[0]; + savedPosY = ypos[0]; - savedWidth = width; - savedHeight = height; - glfwGetWindowPos(window, windowXPos, windowYPos); - glfwSetWindowMonitor(window, glfwGetPrimaryMonitor(), 0, 0, videoMode.width(), videoMode.height(), 0); - } else { - glfwSetWindowMonitor(window, 0, savedPosX, savedPosY, savedWidth, savedHeight, 0); - } - } + savedWidth = width; + savedHeight = height; + glfwGetWindowPos(window, windowXPos, windowYPos); + glfwSetWindowMonitor(window, glfwGetPrimaryMonitor(), 0, 0, videoMode.width(), videoMode.height(), 0); + } else { + glfwSetWindowMonitor(window, 0, savedPosX, savedPosY, savedWidth, savedHeight, 0); + } + } - // resized getter + // resized getter - public boolean isResized() { - return isResized; - } + public boolean isResized() { + return isResized; + } - // Creates the window (should go in the init() function of your Main program) - public void create() { + // Creates the window (should go in the init() function of your Main program) + public void create() throws Exception { - // initializing glfw - if (!glfwInit()) { - System.err.println("Failed to initialize GLFW! "); - System.exit(1); - } + // initializing glfw + if (!glfwInit()) { + //System.err.println("Failed to initialize GLFW! "); + //System.exit(1); + throw new Exception("Failed to initialize GLFW! "); + } - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6); - glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL11.GL_TRUE); - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6); + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL11.GL_TRUE); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - //Creating window - glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); - window = glfwCreateWindow(this.width, this.height, this.windowName, isFullscreen ? glfwGetPrimaryMonitor():0, 0); - if (window == 0) { - System.err.println("Failed to create window! "); - System.exit(1); - } + //Creating window + glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); + window = glfwCreateWindow(this.width, this.height, this.windowName, isFullscreen ? glfwGetPrimaryMonitor():0, 0); + if (window == 0) { + //System.err.println("Failed to create window! "); + //System.exit(1); + throw new Exception("Failed to create window! "); + } - // Setting size of window + // Setting size of window - videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor()); - windowXPos[0] = (videoMode.width() - this.width) / 2; - windowYPos[0] = (videoMode.height() - this.height ) / 2; - glfwSetWindowPos(window, windowXPos[0], windowYPos[0]); + videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor()); + windowXPos[0] = (videoMode.width() - this.width) / 2; + windowYPos[0] = (videoMode.height() - this.height ) / 2; + glfwSetWindowPos(window, windowXPos[0], windowYPos[0]); - // Graphics - glfwMakeContextCurrent(window); - GL.createCapabilities(); + // Graphics + glfwMakeContextCurrent(window); + GL.createCapabilities(); - GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glEnable(GL11.GL_DEPTH_TEST); - callBacks(); - glfwShowWindow(window); - glfwSwapInterval(1); + callBacks(); + glfwShowWindow(window); + glfwSwapInterval(1); - // setting time + // setting time - time = System.currentTimeMillis(); + time = System.currentTimeMillis(); - } + } - // Creating the resize callback (all other callbacks were removed and are now in Input class) - private void callBacks() { + // Creating the resize callback (all other callbacks were removed and are now in Input class) + private void callBacks() { - resizeCallback = new GLFWWindowSizeCallback() { + resizeCallback = new GLFWWindowSizeCallback() { - @Override - public void invoke(long window, int w, int h) { - width = w; - height = h; - isResized = true; - } - }; + @Override + public void invoke(long window, int w, int h) { + width = w; + height = h; + isResized = true; + } + }; - glfwSetWindowSizeCallback(window, resizeCallback); - } + glfwSetWindowSizeCallback(window, resizeCallback); + } - // Refreshes the screen, resets frame count - public int update() { - if (isResized) { - GL11.glViewport(0, 0, width, height); - isResized = false; - } - GL11.glClearColor(background.getX(), background.getY(), background.getZ(), 1.0F); - GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); - glfwPollEvents(); - frames++; - if (System.currentTimeMillis() > time + 1000) { - previousFrames = frames; - time = System.currentTimeMillis(); - frames = 0; - return frames; - } else { - return previousFrames; + // Refreshes the screen, resets frame count + public int update() { + if (isResized) { + GL11.glViewport(0, 0, width, height); + isResized = false; + } + GL11.glClearColor(background.getX(), background.getY(), background.getZ(), 1.0F); + GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); + glfwPollEvents(); + frames++; + if (System.currentTimeMillis() > time + 1000) { + previousFrames = frames; + time = System.currentTimeMillis(); + frames = 0; + return frames; + } else { + return previousFrames; - } - } + } + } - // Terminates the program (making WindowShouldClose) + // Terminates the program (making WindowShouldClose) - public void terminate() { - glfwSetWindowShouldClose(window, true); - } + public void terminate() { + glfwSetWindowShouldClose(window, true); + } - // Completely DESTROYS the window - public void destroy() { - resizeCallback.free(); - glfwDestroyWindow(window); - glfwTerminate(); - } + // Completely DESTROYS the window + public void destroy() { + resizeCallback.free(); + glfwDestroyWindow(window); + glfwTerminate(); + } - // switches the buffers (for rendering) + // switches the buffers (for rendering) - public void swapBuffers() { - glfwSwapBuffers(window); - } + public void swapBuffers() { + glfwSwapBuffers(window); + } - // get whether the window should close - public boolean shouldClose() { - return glfwWindowShouldClose(window); - } + // get whether the window should close + public boolean shouldClose() { + return glfwWindowShouldClose(window); + } - // changes the background color + // changes the background color - public void setBackgroundColor(float r, float g, float b) { - background.setVector(r, g, b); - } + public void setBackgroundColor(float r, float g, float b) { + background.setVector(r, g, b); + } } \ No newline at end of file diff --git a/src/org/hl/engine/io/Input.java b/src/org/hl/engine/io/Input.java index 7b7f258..5ceeeb7 100644 --- a/src/org/hl/engine/io/Input.java +++ b/src/org/hl/engine/io/Input.java @@ -7,115 +7,115 @@ import java.util.Arrays; import static org.lwjgl.glfw.GLFW.*; public class Input { - private boolean[] keys = new boolean[GLFW.GLFW_KEY_LAST]; - private boolean[] buttons = new boolean[GLFW.GLFW_MOUSE_BUTTON_LAST]; + private boolean[] keys = new boolean[GLFW.GLFW_KEY_LAST]; + private boolean[] buttons = new boolean[GLFW.GLFW_MOUSE_BUTTON_LAST]; - private int[] keyState = new int[GLFW.GLFW_KEY_LAST]; - private int[] buttonState = new int[GLFW.GLFW_MOUSE_BUTTON_LAST]; + private int[] keyState = new int[GLFW.GLFW_KEY_LAST]; + private int[] buttonState = new int[GLFW.GLFW_MOUSE_BUTTON_LAST]; - private long window; - private Display display; + private long window; + private Display display; - private boolean inWindow; + private boolean inWindow; - private double mouseX, mouseY; - private double scrollX, scrollY; + private double mouseX, mouseY; + private double scrollX, scrollY; - // Sets up the callbacks based on the window - public Input(Display d) { - this.display = d; - this.window = this.display.getWindow(); + // Sets up the callbacks based on the window + public Input(Display d) { + this.display = d; + this.window = this.display.getWindow(); - glfwSetKeyCallback(this.window, (window, key, scancode, action, mods) -> { - keys[key] = action != GLFW.GLFW_RELEASE; - keyState[key] = action; - }); + glfwSetKeyCallback(this.window, (window, key, scancode, action, mods) -> { + keys[key] = action != GLFW.GLFW_RELEASE; + keyState[key] = action; + }); - glfwSetMouseButtonCallback(this.window, (window, button, action, mods) -> { - buttons[button] = action != GLFW.GLFW_RELEASE; - buttonState[button] = action; - }); + glfwSetMouseButtonCallback(this.window, (window, button, action, mods) -> { + buttons[button] = action != GLFW.GLFW_RELEASE; + buttonState[button] = action; + }); - glfwSetCursorPosCallback(this.window, (window, xpos, ypos) -> { - mouseX = xpos; - mouseY = ypos; - }); + glfwSetCursorPosCallback(this.window, (window, xpos, ypos) -> { + mouseX = xpos; + mouseY = ypos; + }); - glfwSetCursorEnterCallback(this.window, (window, entered) -> { - inWindow = entered; - }); + glfwSetCursorEnterCallback(this.window, (window, entered) -> { + inWindow = entered; + }); - glfwSetScrollCallback(this.window, (window, xoffset, yoffset) -> { - scrollX += xoffset; - scrollY += yoffset; - }); + glfwSetScrollCallback(this.window, (window, xoffset, yoffset) -> { + scrollX += xoffset; + scrollY += yoffset; + }); - resetKeyboard(); - resetButtons(); - } + resetKeyboard(); + resetButtons(); + } - // All states (isDown will return whether it has been held down but Press only returns a press) + // All states (isDown will return whether it has been held down but Press only returns a press) - public boolean isKeyDown(int key) { - return keys[key]; - } + public boolean isKeyDown(int key) { + return keys[key]; + } - public boolean keyPress(int key) { - return keyState[key] == GLFW.GLFW_PRESS; - } + public boolean keyPress(int key) { + return keyState[key] == GLFW.GLFW_PRESS; + } - public boolean keyReleased(int key) { - return keyState[key] == GLFW.GLFW_RELEASE; - } + public boolean keyReleased(int key) { + return keyState[key] == GLFW.GLFW_RELEASE; + } - public boolean isButtonDown(int button) { - return buttons[button]; - } + public boolean isButtonDown(int button) { + return buttons[button]; + } - public boolean buttonPress(int button) { - return buttonState[button] == GLFW.GLFW_PRESS; - } + public boolean buttonPress(int button) { + return buttonState[button] == GLFW.GLFW_PRESS; + } - public boolean buttonReleased(int button) { - return buttonState[button] == GLFW.GLFW_RELEASE; - } + public boolean buttonReleased(int button) { + return buttonState[button] == GLFW.GLFW_RELEASE; + } - // Resets keyboard and buttons so the presses will only be registered once - private void resetKeyboard() { - Arrays.fill(keyState, -1); - } + // Resets keyboard and buttons so the presses will only be registered once + private void resetKeyboard() { + Arrays.fill(keyState, -1); + } - private void resetButtons() { - Arrays.fill(buttonState, -1); - } + private void resetButtons() { + Arrays.fill(buttonState, -1); + } - // This function should only be called after all input has been taken inside the loop. It must be called if keyPress and buttonPress should work. + // This function should only be called after all input has been taken inside the loop. It must be called if keyPress and buttonPress should work. - public void reset() { - resetKeyboard(); - resetButtons(); - } + public void reset() { + resetKeyboard(); + resetButtons(); + } - // Scroll, mouse, and window getters + // Scroll, mouse, and window getters - public double getMouseX() { - return mouseX; - } + public double getMouseX() { + return mouseX; + } - public double getMouseY() { - return mouseY; - } + public double getMouseY() { + return mouseY; + } - public boolean inWindow() { - return inWindow; - } + public boolean inWindow() { + return inWindow; + } - public double getScrollX() { - return scrollX; - } + public double getScrollX() { + return scrollX; + } - public double getScrollY() { - return scrollY; - } + public double getScrollY() { + return scrollY; + } } diff --git a/src/org/hl/engine/math/lalg/Vector2f.java b/src/org/hl/engine/math/lalg/Vector2f.java index e1e990c..8401f3e 100644 --- a/src/org/hl/engine/math/lalg/Vector2f.java +++ b/src/org/hl/engine/math/lalg/Vector2f.java @@ -1,33 +1,33 @@ package org.hl.engine.math.lalg; public class Vector2f { - private float x; - private float y; + private float x; + private float y; - // Just a vector if you know what I mean - public Vector2f (float x, float y) { - this.x = x; - this.y = y; - } + // Just a vector if you know what I mean + public Vector2f (float x, float y) { + this.x = x; + this.y = y; + } - public void setVector(float x, float y) { - this.x = x; - this.y = y; - } + public void setVector(float x, float y) { + this.x = x; + this.y = y; + } - public float getX() { - return x; - } + public float getX() { + return x; + } - public void setX(float x) { - this.x = x; - } + public void setX(float x) { + this.x = x; + } - public float getY() { - return y; - } + public float getY() { + return y; + } - public void setY(float y) { - this.y = y; - } + public void setY(float y) { + this.y = y; + } } diff --git a/src/org/hl/engine/math/lalg/Vector3f.java b/src/org/hl/engine/math/lalg/Vector3f.java index b2a87f0..ea90ce5 100644 --- a/src/org/hl/engine/math/lalg/Vector3f.java +++ b/src/org/hl/engine/math/lalg/Vector3f.java @@ -1,44 +1,44 @@ package org.hl.engine.math.lalg; public class Vector3f { - private float x; - private float y; - private float z; + private float x; + private float y; + private float z; - // Just a vector if you know what I mean - public Vector3f (float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - } + // Just a vector if you know what I mean + public Vector3f (float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + } - public void setVector(float x, float y, float z) { - this.x = x; - this.y = y; - this.z = z; - } + public void setVector(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + } - public float getX() { - return x; - } + public float getX() { + return x; + } - public void setX(float x) { - this.x = x; - } + public void setX(float x) { + this.x = x; + } - public float getY() { - return y; - } + public float getY() { + return y; + } - public void setY(float y) { - this.y = y; - } + public void setY(float y) { + this.y = y; + } - public float getZ() { - return z; - } + public float getZ() { + return z; + } - public void setZ(float z) { - this.z = z; - } + public void setZ(float z) { + this.z = z; + } } diff --git a/src/org/hl/engine/math/lalg/Vector4f.java b/src/org/hl/engine/math/lalg/Vector4f.java new file mode 100644 index 0000000..3370f4f --- /dev/null +++ b/src/org/hl/engine/math/lalg/Vector4f.java @@ -0,0 +1,55 @@ +package org.hl.engine.math.lalg; + +public class Vector4f { + private float x; + private float y; + private float z; + private float a; + + // Just a vector if you know what I mean + public Vector4f (float x, float y, float z, float a) { + this.x = x; + this.y = y; + this.z = z; + this.a = a; + } + + public void setVector(float x, float y, float z, float a) { + this.x = x; + this.y = y; + this.z = z; + this.a = a; + } + + public float getX() { + return x; + } + + public void setX(float x) { + this.x = x; + } + + public float getY() { + return y; + } + + public void setY(float y) { + this.y = y; + } + + public float getZ() { + return z; + } + + public void setZ(float z) { + this.z = z; + } + + public float getA() { + return a; + } + + public void setA(float a) { + this.a = a; + } +} diff --git a/src/org/hl/engine/utils/FileUtils.java b/src/org/hl/engine/utils/FileUtils.java index f1a1390..a314565 100644 --- a/src/org/hl/engine/utils/FileUtils.java +++ b/src/org/hl/engine/utils/FileUtils.java @@ -7,22 +7,22 @@ import java.io.InputStreamReader; public class FileUtils { - // Reads a filepath and returns that as a String - public static String loadAsString(String filepath) { - StringBuilder result = new StringBuilder(); - try (BufferedReader reader = new BufferedReader(new - InputStreamReader(FileUtils.class.getResourceAsStream(filepath)))) { - String line = ""; - while ((line = reader.readLine()) != null) { - result.append(line) .append("\n"); - } - } catch (Exception e) { - System.err.println("Couldn't get the file at " + filepath); - System.exit(1); + // Reads a filepath and returns that as a String + public static String loadAsString(String filepath) { + StringBuilder result = new StringBuilder(); + try (BufferedReader reader = new BufferedReader(new + InputStreamReader(FileUtils.class.getResourceAsStream(filepath)))) { + String line = ""; + while ((line = reader.readLine()) != null) { + result.append(line) .append("\n"); + } + } catch (Exception e) { + System.err.println("Couldn't get the file at " + filepath); + System.exit(1); - } + } - return result.toString(); - } + return result.toString(); + } } diff --git a/src/org/hl/engine/utils/TextureLoader.java b/src/org/hl/engine/utils/TextureLoader.java index 7f3e0b7..49b65de 100644 --- a/src/org/hl/engine/utils/TextureLoader.java +++ b/src/org/hl/engine/utils/TextureLoader.java @@ -14,57 +14,57 @@ import org.lwjgl.opengl.GL12; import static org.lwjgl.opengl.GL11.*; public class TextureLoader { - private static final int BYTES_PER_PIXEL = 4;//3 for RGB, 4 for RGBA - public static int loadTexture(BufferedImage image){ + private static final int BYTES_PER_PIXEL = 4;//3 for RGB, 4 for RGBA + public static int loadTexture(BufferedImage image){ - int[] pixels = new int[image.getWidth() * image.getHeight()]; - image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth()); + int[] pixels = new int[image.getWidth() * image.getHeight()]; + image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth()); - ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * BYTES_PER_PIXEL); //4 for RGBA, 3 for RGB + ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * BYTES_PER_PIXEL); //4 for RGBA, 3 for RGB - for(int y = 0; y < image.getHeight(); y++){ - for(int x = 0; x < image.getWidth(); x++){ - int pixel = pixels[y * image.getWidth() + x]; - buffer.put((byte) ((pixel >> 16) & 0xFF)); // Red component - buffer.put((byte) ((pixel >> 8) & 0xFF)); // Green component - buffer.put((byte) (pixel & 0xFF)); // Blue component - buffer.put((byte) ((pixel >> 24) & 0xFF)); // Alpha component. Only for RGBA - } - } + for(int y = 0; y < image.getHeight(); y++){ + for(int x = 0; x < image.getWidth(); x++){ + int pixel = pixels[y * image.getWidth() + x]; + buffer.put((byte) ((pixel >> 16) & 0xFF)); // Red component + buffer.put((byte) ((pixel >> 8) & 0xFF)); // Green component + buffer.put((byte) (pixel & 0xFF)); // Blue component + buffer.put((byte) ((pixel >> 24) & 0xFF)); // Alpha component. Only for RGBA + } + } - buffer.flip(); //FOR THE LOVE OF GOD DO NOT FORGET THIS + buffer.flip(); //FOR THE LOVE OF GOD DO NOT FORGET THIS - // You now have a ByteBuffer filled with the color data of each pixel. - // Now just create a texture ID and bind it. Then you can load it using - // whatever OpenGL method you want, for example: + // You now have a ByteBuffer filled with the color data of each pixel. + // Now just create a texture ID and bind it. Then you can load it using + // whatever OpenGL method you want, for example: - int textureID = glGenTextures(); //Generate texture ID - glBindTexture(GL_TEXTURE_2D, textureID); //Bind texture ID + int textureID = glGenTextures(); //Generate texture ID + glBindTexture(GL_TEXTURE_2D, textureID); //Bind texture ID - //Setup wrap mode - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); + //Setup wrap mode + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); - //Setup texture scaling filtering - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + //Setup texture scaling filtering + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - //Send texel data to OpenGL - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + //Send texel data to OpenGL + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); - //Return the texture ID so we can bind it later again - return textureID; - } + //Return the texture ID so we can bind it later again + return textureID; + } - public static BufferedImage loadImage(String loc) - { - try { - return ImageIO.read(TextureLoader.class.getResource(loc)); - } catch (IOException e) { - //Error Handling Here - System.err.println("Error with loading texture. "); - System.exit(1); - } - return null; - } + public static BufferedImage loadImage(String loc) + { + try { + return ImageIO.read(TextureLoader.class.getResource(loc)); + } catch (IOException e) { + //Error Handling Here + System.err.println("Error with loading texture. "); + System.exit(1); + } + return null; + } } \ No newline at end of file diff --git a/src/resources/shaders/mainFragment.glsl b/src/resources/shaders/mainFragment.glsl index 4be6a4c..3f034ff 100644 --- a/src/resources/shaders/mainFragment.glsl +++ b/src/resources/shaders/mainFragment.glsl @@ -1,4 +1,4 @@ -#version 460 core +#version 410 core in vec3 passColor; in vec2 passTextureCoord; diff --git a/src/resources/shaders/mainVertex.glsl b/src/resources/shaders/mainVertex.glsl index 013665a..172bf89 100644 --- a/src/resources/shaders/mainVertex.glsl +++ b/src/resources/shaders/mainVertex.glsl @@ -1,4 +1,4 @@ -#version 460 core +#version 410 core in vec3 position; in vec3 color; From 2294aba9e39d8b2487da8fe66b3cd4d20818ea54 Mon Sep 17 00:00:00 2001 From: EvilMuffinHa Date: Mon, 25 May 2020 14:59:42 -0400 Subject: [PATCH 8/8] texturing works --- resources/textures/testimg.png | Bin 5785 -> 0 bytes resources/textures/thonk.png | Bin 0 -> 9190 bytes src/Test.java | 4 ++-- src/org/hl/engine/graphics/Vertex.java | 3 ++- src/org/hl/engine/io/Display.java | 6 +++++- src/resources/shaders/mainFragment.glsl | 6 +++--- src/resources/shaders/mainVertex.glsl | 10 +++++----- src/resources/textures/testimg.png | Bin 5785 -> 0 bytes 8 files changed, 17 insertions(+), 12 deletions(-) delete mode 100644 resources/textures/testimg.png create mode 100644 resources/textures/thonk.png delete mode 100644 src/resources/textures/testimg.png diff --git a/resources/textures/testimg.png b/resources/textures/testimg.png deleted file mode 100644 index ffe963ef4dd2c0a504e694b733c8f1f274fe07cb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5785 zcmdsbXH*m2_jN+(5JC|UPy@J!kK;&zYHf@4B(quNi?^1z7I4Ar$(k7G-VC-~pZ0in`da`K(Nr>FB+|&Y!!V;*%-xYiL^M2H+AvPqupnIco>Jh; z3jZH6HiNyTvT zmw@)i4y}i#T1qem;y^PD0TE_!VY{vRr$74yR=M(s2t)p^(3}YQ{m{5$GW?rasGBB`eo=$`Okx$h}q$uF&-L4 zj^7-a|8($-{m$TcMimQ8nY?i5d`k6)DC`hv(SX$?8Z|_R4w7G6w8Yj&JGg{ zKI832m8h}JU;GL}N3YNAbxc8g{grq?vS>{EA4lp+>t1f?&(p?DGg;OwW3LPNuxZ{$ zRxw9%lyUPxO%g281w;pB32l~Lb_S{P~pfIqJAFm0`+E92_TCp zN^9CmSSbZuIw~tp|FRXA&k>paBT$R}2g#+-lH&;+#_gV}L7G1U_gToTU;}6eTYOkw zUf(Vs=}1UizsApiWzmTzMgws=Ot()VU48q>A3YT>0iTN8D@rwLTDG_?KuqpTJ(P?t5WhhhYkMfeztkJft4Y?OZ!vHE!%BG#=ZJZ{JG zmFVNZ#UGBSOEkTXZi<)XRG4Mhk#X`37tpE~pCb!3+0qOWaw(k!>6d?wqJ(i=185^! z3|BPWG|EAcWO)0s-T{b&aCO;=ob$NfThrid&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u*X)h4_V*jkeAV-&sh)q9QP{d{$Q2Q)AI_oNC6!qp3tMWd)OpF_47%*Z=dX% zO3Q>vReBmaX}KfBzoe1LC?M` zAh_HuaZm4+>xPc3BAk`JH#w#57@Fa7b%7sUy(9SD#3PVv7Oe`jqowTKFX(-<^JUz$ zGq1wvX5`ELnLNQPUm#~c9~-)+n=b!dH9*os8t_H%|0~mRR+~%(vI0KFqh}I&XvfI_ N6T@o;6?%5z{|D3YR%`$O diff --git a/resources/textures/thonk.png b/resources/textures/thonk.png new file mode 100644 index 0000000000000000000000000000000000000000..a166634cce2f2d44dd1e295d339cc4b9887e31b7 GIT binary patch literal 9190 zcmVLQRcpDyh`e6wM?vE@x74 zg2&~tUB*iYPSnAU7r-_+5+q@jKnoID(7v>!R`1K(?!9OJ??3OhUO&Ajb&E#8lzw!( zU*F{{-}%q?FX!BcqRVp0L=~R6EFYX)2Ky4qWw0-yTn76R%4M)GpjmXBm`44^^Wo zk5<;$cB8eet>nzIsL4?@i%*oR2xTH3orpMe)WjL9UXpQc^?r$$R{I})=LOn~GB&g? zjkG4P75&S<{m-BIXLZA~y;A7rRW7Zn(6ovFs2JqCR^@8m zLNv(dyBajLbp$9Uci}^qNe5eRXtQbV0gDc73241=F!)%e{@1=zRdej{@YPvAxZNUs zE9>?m$0p?g;DEAFRkn~8umHJ>Yb zW2-~0__PV2f9OVbQo-K9K(AkKIJKQQ__2+D?JD)vD^x=b6^2|`e$y$dL`qkk%$f|c{row z@dK{sk>w8ZgD2G0zdUoc99DwImul7C{-J?BX<&nYF=h3uYZnK$y4P~;mEC7jkzf4F zyQ!@^j?eM}|4J38sLwYB46?@b)?_Ooit`KK1I-UI849L0#hgF-y{o8sev=oBWDYYG zB`pfdgFw0PVJw?V*VZuW@o7Ks-zD4LXnV02)h9c8!t&5oQ?UFi9N!O2F4)nDNapoh z|GR{ z>xi;Y=Nx2ViTIr(uORIYGPrw~o?f(E`YCmK+tuyQr*n6XN;m)?B*#yv!{?LitLy&6 zi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V(=ugH?o}<8S$Ou$4-$K>7#3(8dP~(G(#ND z*PTg~VfMS(eEli=-mCFa0H8qr0`Ol9QJ{}5O zUU3?7QoJLREJg>p?x$)ihfjHTGn?EVQTh|EtD0Tg>|`~Fo0KyIZW3kz2Wr0QYEJ9( zg?oe5`3Q6OC@ox!goT?;p)hbbY`h)~yn~eAtvr9T?>L)uD)nOI`WNK8ydh&^h_D=G zlxFmN-sMXo;Z%~(8_4cG62H#1>`!xxZgU;IkY{HMFSDhx>JWGE*UFAGN65d6yBguZ z2)jfvfsLyQdxXB&Hq*#ra_XB#!|Mx5{w-*Yq!Z02a=BO=8-Ed|v&)v%yV(}JU@7Nc zs4DxfYQggZcuebdi#m3yiGGviI9fM(0>HOSC3{s3^H=UmtWtkjHE+buE{fPeJ$s@_ z_Q`gae|30A-`_8mQ&4lDyct`ujDVhF8LLF9{ii~``CT@uQ~{>N<KpRHm=pcf> zKJZr+EsWSLjvXvui{smkjoHZD1yd;=U&>xV3niSmxM2uNaEK!S(#ah_n}H3I?1Ec# ziorc*>EJL&(TB8W?dDi=E2-2Wdj5C4A=Pc%*y^<6L+i%TudsN(@}YvAFMz0UYGN=R zf1Ff%$o1c0R$a*Vv~JL}<;5sv4o~CgdT|i37PC!Tzz;B+zg zy_Og7Z~p{G_??dBoSKb;$q!rtldEw$o9^dglBNeDmpq4BkZL zBM)}I2=IA-gfd=$#8y0(yO(DSwV!_gCtE&NV4qKNGhnPJ`B!-MLzDk+!2USMWw0-y wTn76R%4M)GpLkHvj+t07*qoM6N<$f*x=I)&Kwi literal 0 HcmV?d00001 diff --git a/src/Test.java b/src/Test.java index 45cb36a..71cfeb3 100644 --- a/src/Test.java +++ b/src/Test.java @@ -24,7 +24,7 @@ public class Test { 0, 1, 2, 0, 2, 3 - }, new Material(new Texture("resources/textures/testimg.png"))); + }, new Material(new Texture("resources/textures/thonk.png"))); public void run() throws Exception { setup(); @@ -49,7 +49,7 @@ public class Test { display.create(); shader = new Shader("/resources/shaders/mainVertex.glsl", "/resources/shaders/mainFragment.glsl"); renderer = new Renderer(shader); - display.setBackgroundColor(1F, 0, 0); + display.setBackgroundColor(1F, 1F, 1F); mesh.create(); shader.create(); diff --git a/src/org/hl/engine/graphics/Vertex.java b/src/org/hl/engine/graphics/Vertex.java index 3270b27..99a58d7 100644 --- a/src/org/hl/engine/graphics/Vertex.java +++ b/src/org/hl/engine/graphics/Vertex.java @@ -10,9 +10,10 @@ public class Vertex { private Vector3f color; private Vector2f textureCoords; - public Vertex (Vector3f position, Vector3f color, Vector2f texture) { + public Vertex (Vector3f position, Vector3f color, Vector2f textureCoords) { this.position = position; this.color = color; + this.textureCoords = textureCoords; } public Vector3f getPosition() { diff --git a/src/org/hl/engine/io/Display.java b/src/org/hl/engine/io/Display.java index 47c94bc..5303606 100644 --- a/src/org/hl/engine/io/Display.java +++ b/src/org/hl/engine/io/Display.java @@ -1,5 +1,6 @@ package org.hl.engine.io; import org.hl.engine.math.lalg.Vector3f; +import org.lwjgl.glfw.GLFWErrorCallback; import org.lwjgl.glfw.GLFWVidMode; import org.lwjgl.glfw.GLFWWindowSizeCallback; import org.lwjgl.opengl.GL; @@ -96,6 +97,8 @@ public class Display { // Creates the window (should go in the init() function of your Main program) public void create() throws Exception { + GLFWErrorCallback.createPrint(System.err).set(); + // initializing glfw if (!glfwInit()) { //System.err.println("Failed to initialize GLFW! "); @@ -104,7 +107,7 @@ public class Display { } glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL11.GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); @@ -190,6 +193,7 @@ public class Display { // Completely DESTROYS the window public void destroy() { resizeCallback.free(); + glfwSetErrorCallback(null).free(); glfwDestroyWindow(window); glfwTerminate(); } diff --git a/src/resources/shaders/mainFragment.glsl b/src/resources/shaders/mainFragment.glsl index 3f034ff..9ad7039 100644 --- a/src/resources/shaders/mainFragment.glsl +++ b/src/resources/shaders/mainFragment.glsl @@ -1,9 +1,9 @@ #version 410 core -in vec3 passColor; -in vec2 passTextureCoord; +layout(location = 0) in vec3 passColor; +layout(location = 1) in vec2 passTextureCoord; -out vec4 outColor; +layout(location = 0) out vec4 outColor; uniform sampler2D tex; diff --git a/src/resources/shaders/mainVertex.glsl b/src/resources/shaders/mainVertex.glsl index 172bf89..3544e06 100644 --- a/src/resources/shaders/mainVertex.glsl +++ b/src/resources/shaders/mainVertex.glsl @@ -1,11 +1,11 @@ #version 410 core -in vec3 position; -in vec3 color; -in vec2 textureCoord; +layout(location = 0) in vec3 position; +layout(location = 1) in vec3 color; +layout(location = 2) in vec2 textureCoord; -out vec3 passColor; -out vec2 passTextureCoord; +layout(location = 0) out vec3 passColor; +layout(location = 1) out vec2 passTextureCoord; void main() { gl_Position = vec4(position, 1.0); diff --git a/src/resources/textures/testimg.png b/src/resources/textures/testimg.png deleted file mode 100644 index ffe963ef4dd2c0a504e694b733c8f1f274fe07cb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5785 zcmdsbXH*m2_jN+(5JC|UPy@J!kK;&zYHf@4B(quNi?^1z7I4Ar$(k7G-VC-~pZ0in`da`K(Nr>FB+|&Y!!V;*%-xYiL^M2H+AvPqupnIco>Jh; z3jZH6HiNyTvT zmw@)i4y}i#T1qem;y^PD0TE_!VY{vRr$74yR=M(s2t)p^(3}YQ{m{5$GW?rasGBB`eo=$`Okx$h}q$uF&-L4 zj^7-a|8($-{m$TcMimQ8nY?i5d`k6)DC`hv(SX$?8Z|_R4w7G6w8Yj&JGg{ zKI832m8h}JU;GL}N3YNAbxc8g{grq?vS>{EA4lp+>t1f?&(p?DGg;OwW3LPNuxZ{$ zRxw9%lyUPxO%g281w;pB32l~Lb_S{P~pfIqJAFm0`+E92_TCp zN^9CmSSbZuIw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