Files
shooter/src/main/java/org/xfe/engine/Render.java
T
2024-09-24 17:00:18 -05:00

51 lines
1.8 KiB
Java

package org.xfe.engine;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.lwjgl.opengl.GL;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL15.*;
import static org.lwjgl.opengl.GL20.*;
import static org.lwjgl.opengl.GL30.*;
public class Render {
private Matrix4f projection_matrix;
public Render() {
GL.createCapabilities();
}
public void cleanup() {
// Nothing to be done here yet
}
public void render(Window window, World world) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glfwSwapBuffers(window.getWindowHandle());
float aspect_ratio = (float) window.getWidth() / window.getHeight();
projection_matrix = new Matrix4f().perspective(Engine.FOV, aspect_ratio, Engine.Z_FAR, Engine.Z_NEAR);
for (Entity entity : world.entities) {
entity.shader.bind();
entity.shader.setUniform("projection", projection_matrix);
// entity.shader.setUniform("model", new Matrix4f().identity());
// entity.shader.setUniform("view", new Matrix4f().identity());
// entity.shader.setUniform("lightPos", world.lights.get(0).position);
// entity.shader.setUniform("light_power", world.lights.get(0).power);
// entity.shader.setUniform("lightColor", world.lights.get(0).color);
// entity.shader.setUniform("objectColor", new Vector3f(1.0f, 1.0f, 1.0f));
// entity.shader.setUniform("viewPos", new Vector3f(0.0f, 0.0f, 0.0f));
glBindVertexArray(entity.mesh.ebo_id);
glEnableVertexAttribArray(0);
// glEnableVertexAttribArray(1);
glDrawElements(GL_TRIANGLES, entity.mesh.vertice_indices.length, GL_UNSIGNED_INT, 0);
}
}
}