Added correctViewport

This commit is contained in:
Antoine 2021-06-02 20:12:13 +02:00
parent 7b349c573b
commit 48c0a66f11

View File

@ -80,11 +80,12 @@ public class Engine {
glfwShowWindow(getWindow());
GL.createCapabilities();
correctViewport(this.width, this.height);
glfwSetFramebufferSizeCallback(getWindow(), resizeWindow);
glEnable(GL_DEPTH_TEST); // Z-Buffer plus z est grand plus l'objet est proche de la camera limite à 100.0f au dela l'objet disparait
glScissor(0,0,this.width,this.height); // La zone de dessin du background
glEnable(GL_BLEND); // Transparence
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -131,6 +132,23 @@ public class Engine {
objectsGl.remove(obj);
}
public static void correctViewport(int width, int height){
int heightViewport, widthViewport, x, y;
if (width >= height * 4.0f/3.0f){
heightViewport = height;
widthViewport = (int) (height * 4.0f/3.0f);
y = 0;
x = (width - widthViewport)/2;
} else {
widthViewport = width;
heightViewport = (int) (width * 3.0f/4.0f);
y = (height - heightViewport)/2;
x = 0;
}
glScissor(x, y, widthViewport, heightViewport);
glViewport(x, y, widthViewport, heightViewport);
}
public boolean isRunning() {
return running;
}
@ -158,21 +176,7 @@ public class Engine {
private static final GLFWFramebufferSizeCallback resizeWindow = new GLFWFramebufferSizeCallback() {
@Override
public void invoke(long window, int width, int height) {
int heightViewport, widthViewport, x, y;
if (width >= height * 4.0f/3.0f){
heightViewport = height;
widthViewport = (int) (height * 4.0f/3.0f);
y = 0;
x = (width - widthViewport)/2;
} else {
widthViewport = width;
heightViewport = (int) (width * 3.0f/4.0f);
y = (height - heightViewport)/2;
x = 0;
}
glScissor(x, y, widthViewport, heightViewport);
glViewport(x, y, widthViewport, heightViewport);
correctViewport(width, height);
}
};