started rewriting rendering and window handling
This commit is contained in:
1 parent
c14411bd7b
commit
26c0f433ae
5 files changed
+164
-42
No files matched your search
@@ -1,11 +1,13 @@
|
||||
package org.example;
|
||||
|
||||
import org.joml.*;
|
||||
import org.lwjgl.*;
|
||||
import org.lwjgl.Version;
|
||||
import org.lwjgl.glfw.*;
|
||||
import org.lwjgl.opengl.*;
|
||||
import org.lwjgl.system.*;
|
||||
|
||||
import java.lang.Math;
|
||||
import java.nio.*;
|
||||
import java.io.*;
|
||||
import java.text.MessageFormat;
|
||||
@@ -13,6 +15,9 @@ import java.text.MessageFormat;
|
||||
import static org.lwjgl.glfw.Callbacks.*;
|
||||
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.*;
|
||||
import static org.lwjgl.system.MemoryStack.*;
|
||||
import static org.lwjgl.system.MemoryUtil.*;
|
||||
|
||||
@@ -21,7 +26,11 @@ import org.lwjgl.system.MemoryStack;
|
||||
|
||||
public class Game
|
||||
{
|
||||
public static final float Z_FAR = 1000.0f;
|
||||
public static final float Z_NEAR = 0.1f;
|
||||
public static final float FOV = (float) Math.toRadians(90.0f);
|
||||
private long window;
|
||||
private Matrix4f projection_matrix;
|
||||
|
||||
public void run()
|
||||
{
|
||||
@@ -102,6 +111,12 @@ public class Game
|
||||
// Add stuff to world
|
||||
world.addEntity(new Entity("/objs/cube.obj", "/shaders/shader.frag", "/shaders/shader.vert"));
|
||||
|
||||
// Calculate Perspective Matrix
|
||||
int w, h;
|
||||
glfwGetWindowSize(window, w, h);
|
||||
float aspect_ratio = (float) ;
|
||||
this.projection_matrix = new Matrix4f().perspective(FOV, )
|
||||
|
||||
// Main loop or something
|
||||
while ( !glfwWindowShouldClose(window) )
|
||||
{
|
||||
@@ -109,10 +124,22 @@ public class Game
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
|
||||
for (Entity entity : world.entities)
|
||||
render(entity);
|
||||
|
||||
glfwPollEvents();
|
||||
}
|
||||
}
|
||||
|
||||
public void render(Entity entity) {
|
||||
entity.shader.bind();
|
||||
|
||||
glBindVertexArray(entity.mesh.vao_id);
|
||||
glEnableVertexAttribArray(0);
|
||||
glEnableVertexAttribArray(1);
|
||||
glDrawElements(GL_TRIANGLES, entity.mesh.vertex_count, GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
new Game().run();
|
||||
|
||||
Reference in new issue
Block a user