still trying to debug why it isn't rendering

This commit is contained in:
0x01fe committed 2024-09-24 22:58:58 -05:00
1 parent e71a1a9b0b
commit 8da13e805b
5 files changed
+18 -4

No files matched your search

+5
View File
@@ -1,11 +1,15 @@
package org.xfe.engine;
import org.joml.Matrix4f;
import java.util.Scanner;
public class Entity
{
Mesh mesh;
public Matrix4f model;
public ShaderProgram shader;
public Entity(String object_file_path, String fragment_shader_path, String vertex_shader_path)
@@ -47,6 +51,7 @@ public class Entity
try {
shader.createUniform("projection");
shader.createUniform("model");
} catch (Exception e) {
e.printStackTrace();
}
+3
View File
@@ -9,6 +9,7 @@ import java.io.InputStream;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import static org.lwjgl.opengl.GL11.*;
@@ -95,6 +96,8 @@ public class Mesh {
// OBJ File has been read, setup openGL buffers
init();
System.out.println(Arrays.toString(this.vertices));
}
private void init() {
+5 -2
View File
@@ -23,7 +23,7 @@ public class Render {
public void render(Window window, World world) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glfwSwapBuffers(window.getWindowHandle());
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
float aspect_ratio = (float) window.getWidth() / window.getHeight();
projection_matrix = new Matrix4f().perspective(Engine.FOV, aspect_ratio, Engine.Z_FAR, Engine.Z_NEAR);
@@ -32,6 +32,7 @@ public class Render {
entity.shader.bind();
entity.shader.setUniform("projection", projection_matrix);
entity.shader.setUniform("model", entity.model);
// entity.shader.setUniform("model", new Matrix4f().identity());
// entity.shader.setUniform("view", new Matrix4f().identity());
// entity.shader.setUniform("lightPos", world.lights.get(0).position);
@@ -41,10 +42,12 @@ public class Render {
// entity.shader.setUniform("viewPos", new Vector3f(0.0f, 0.0f, 0.0f));
glBindVertexArray(entity.mesh.ebo_id);
glBindVertexArray(entity.mesh.vao_id);
glEnableVertexAttribArray(0);
// glEnableVertexAttribArray(1);
glDrawElements(GL_TRIANGLES, entity.mesh.vertice_indices.length, GL_UNSIGNED_INT, 0);
}
// glfwSwapBuffers(window.getWindowHandle());
}
}
+3
View File
@@ -1,5 +1,6 @@
package org.xfe.game;
import org.joml.Matrix4f;
import org.xfe.engine.*;
public class Main implements GameLogic {
@@ -18,6 +19,8 @@ public class Main implements GameLogic {
@Override
public void init(Window window, World world, Render render) {
Entity cube = new Entity("/objs/cube.obj", "/shaders/shader.frag", "/shaders/shader.vert");
cube.model = new Matrix4f().identity().translate(0, 0, -10);
System.out.println(cube.model.toString());
world.addEntity(cube);
}
+2 -2
View File
@@ -3,7 +3,7 @@ layout (location = 0) in vec3 aPos;
// layout (location = 1) in vec3 aNormal;
//layout (location = 1) in vec3 aColor;
// uniform mat4 model;
uniform mat4 model;
// uniform mat4 view;
uniform mat4 projection;
// uniform vec3 lightPos;
@@ -15,7 +15,7 @@ out vec3 FragPos;
void main()
{
// * view * model
gl_Position = projection * vec4(aPos, 1.0);
gl_Position = projection * model * vec4(aPos, 1.0);
FragPos = vec3(vec4(aPos, 1.0));
// Normal = mat3(transpose(inverse(view * model))) * aNormal;
// LightPos = vec3(view * vec4(lightPos, 1.0));