This commit is contained in:
2025-04-26 18:18:27 +02:00
parent 65c904478f
commit b62dcffcb1
5 changed files with 70 additions and 109 deletions

View File

@@ -1,6 +1,5 @@
package chess.view.DDDrender;
import org.joml.Vector3f;
import org.lwjgl.*;
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
@@ -11,7 +10,6 @@ import chess.controller.commands.GetPieceAtCommand;
import chess.model.Coordinate;
import chess.model.Piece;
import java.io.IOException;
import java.nio.*;
import static org.lwjgl.glfw.Callbacks.*;
@@ -96,16 +94,11 @@ public class Window {
glfwShowWindow(window);
}
private void render() {
final float angle = 0.01f;
float x = cam.getPos().x();
float y = cam.getPos().z();
cam.setPosition(new Vector3f(x * (float) Math.cos(angle) - y * (float) Math.sin(angle), 1.0f,
x * (float) Math.sin(angle) + y * (float) Math.cos(angle)));
int width[] = new int[1];
int height[] = new int[1];
glfwGetWindowSize(window, width, height);
cam.setAspectRatio((float) width[0] / (float) height[0]);
private void render(float delta, float aspectRatio) {
final float angle = 1f;
cam.setRotateAngle(cam.getRotateAngle() + angle * delta);
cam.setAspectRatio(aspectRatio);
renderer.Render(cam);
renderPieces();
}
@@ -149,12 +142,20 @@ public class Window {
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
double lastTime = glfwGetTime();
int width[] = new int[1];
int height[] = new int[1];
glfwGetWindowSize(window, width, height);
// Run the rendering loop until the user has attempted to close
// the window or has pressed the ESCAPE key.
while (!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer
render();
double currentTime = glfwGetTime();
render((float) (currentTime - lastTime), (float) width[0] / (float) height[0]);
lastTime = glfwGetTime();
glfwSwapBuffers(window); // swap the color buffers
@@ -162,15 +163,9 @@ public class Window {
// invoked during this call.
glfwPollEvents();
try (MemoryStack stack = stackPush()) {
IntBuffer pWidth = stack.mallocInt(1); // int*
IntBuffer pHeight = stack.mallocInt(1); // int*
glfwGetWindowSize(window, width, height);
glViewport(0, 0, width[0], height[0]);
// Get the window size passed to glfwCreateWindow
glfwGetWindowSize(window, pWidth, pHeight);
glViewport(0, 0, pWidth.get(), pHeight.get());
} // the stack frame is popped automatically
}
}