Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java LWJGL 3窗口大小调整_Java_Opengl_Lwjgl_Glfw - Fatal编程技术网

Java LWJGL 3窗口大小调整

Java LWJGL 3窗口大小调整,java,opengl,lwjgl,glfw,Java,Opengl,Lwjgl,Glfw,我无法调整窗口的大小。 当我试图调整窗口大小时,屏幕并没有正确地改变。 这是窗口的原始大小: 但当我调整窗口大小时,屏幕会变成这样: 每次调整窗口大小但仍不工作时,我都调用updateProjectionMatrix()和glVievport() 我的代码: 公共类窗口{ 私有静态长窗口; 私人静置时间长; 私有静态字符串title=“游戏”; 私有静态输入; 公共静态矩阵x4f投影矩阵; 私有静态布尔值被重新设计; 私有静态布尔值isFullscreen=false; 私有静态int帧

我无法调整窗口的大小。 当我试图调整窗口大小时,屏幕并没有正确地改变。 这是窗口的原始大小:


但当我调整窗口大小时,屏幕会变成这样:


每次调整窗口大小但仍不工作时,我都调用updateProjectionMatrix()和glVievport()

我的代码:

公共类窗口{
私有静态长窗口;
私人静置时间长;
私有静态字符串title=“游戏”;
私有静态输入;
公共静态矩阵x4f投影矩阵;
私有静态布尔值被重新设计;
私有静态布尔值isFullscreen=false;
私有静态int帧;
私有静态长lastFrameTime;
私有静态浮动三角洲;
私有静态整数fps;
私有静态int[]windowPosX=newint[1],windowPosY=newint[1];
私有静态GLFWWindowSizeCallback sizeCallback;
公共静态void createDisplay(){
如果(!GLFW.glfwInit()){
系统错误打印项次(“cD REEOR”);
返回;
}
window=GLFW.glfwCreateWindow((int)Data.getWindowWidth(),(int)Data.getWindowHeight(),“TEST”,isFullscreen?GLFW.glfwGetPrimaryMonitor():0,0);
输入=新输入(窗口);
如果(窗口==0){
System.err.println(“错误:未创建窗口”);
返回;
}
GLFWVidMode videoMode=GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
windowPosX[0]=(videoMode.width()-Data.getWindowWidth())/2;
windowPosY[0]=(videoMode.height()-Data.getWindowHeight())/2;
GLFW.glfwSetWindowPos(window,windowPosX[0],windowPosY[0]);
GLFW.glfwMakeContextCurrent(窗口);
GLFW.glfwShowWindow(窗口);
GL.createCapabilities();
//ContextAttribs attribs=新的ContextAttribs(3,2)。withForwardCompatible(true)。withProfileCore(true);
GLFW.glfwSwapInterval(1);
createCallbacks();
createProjectionMatrix();
}
公共静态矩阵4f getProjectionMatrix(){
返回投影矩阵;
}
公共静态无效setProjectionMatrix(Matrix4f projectionMatrix){
Window.projectionMatrix=projectionMatrix;
}
公共静态长getWindow(){
返回窗口;
}
公共静态窗口(长窗口){
Window.Window=Window;
}
公共静态void updateDisplay(){
如果(isResized){
GL11.glViewport(100,15,Data.getWindowWidth(),Data.getWindowHeight());
isResized=假;
updateProjectionMatrix();
}
GL.createCapabilities();
GLFW.glfwPollEvents();
frames++;
if(System.currentTimeMillis()>时间+1000){
fps=帧;
时间=System.currentTimeMillis();
帧=0;
}
长currentFrameTime=getCurrentTime();
增量=(当前帧时间-最后帧时间)/1000f;
lastFrameTime=currentFrameTime;
}
私有静态void createCallbacks(){
sizeCallback=新的GLFWWindowSizeCallback(){
公共void调用(长窗口、int w、int h){
数据。设置窗口宽度(w);
数据。设置窗口宽度(h);
isResized=真;
}
};
GLFW.glfwSetKeyCallback(window,input.getKeyboardCallback());
GLFW.glfwsetcursorpocallback(窗口,input.getMouseMoveCallback());
GLFW.glfwSetMouseButtonCallback(窗口,input.getmousebuttoncallback());
GLFW.glfwSetScrollCallback(窗口,input.getMouseScrollCallback());
GLFW.glfwsetWindowsSizeCallback(窗口,sizeCallback);
}
公共静态布尔值isFullscreen(){
全屏返回;
}
公共静态void setFullscreen(布尔值为FullScreen){
Window.isFullscreen=isFullscreen;
isResized=真;
如果(全屏显示){
GLFW.glfwGetWindowPos(窗口,windowPosX,windowPosY);
GLFW.glfwSetWindowMonitor(窗口,GLFW.glfwGetPrimaryMonitor(),0,0,Data.getWindowWidth(),Data.getWindowHeight(),0);
}否则{
GLFW.glfwSetWindowMonitor(窗口,0,windowPosX[0],windowPosY[0],Data.getWindowWidth(),Data.getWindowHeight(),0);
}
}
公共静态无效swapBuffers(){
GLFW.glfwSwapBuffers(窗口);
}
公共静态浮点getFrameTimeSeconds(){
返回三角洲;
}
公共静态void closeDisplay(){
//Display.destroy();
}
公共静态长getCurrentTime(){
浮点时间=(浮点)(GLFW.glfwGetTimerValue()*1000/(GLFW.glfwGetTimerFrequency());
//系统输出打印LN(时间);
返回(长)时间;
}
公共静态布尔值shouldClose(){
返回GLFW.glfwWindowShouldClose(窗口);
}
公共静态int getFps(){
返回fps;
}
公共静态无效设置fps(整数fps){
Window.fps=fps;
}
公共静态void setTimer(){
lastFrameTime=getCurrentTime();
}
私有静态void createProjectionMatrix(){
float aspectRatio=(float)Data.getWindowWidth()/(float)Data.getWindowHeight();
float y_scale=(float)((1f/Math.tan(Math.toRadians(Data.getProjectionFov()/2f)))*aspectRatio);
浮动x_比例=y_比例/纵横比;
浮动平截头体长度=Data.getProjectionFarPlane()-Data.getProjectionAnarPlane();
projectionMatrix=新矩阵x4f();
projectionMatrix.m00=x_标度;
projectionMatrix.m11=y_标度;
projectionMatrix.m22=-((Data.getProjectionFarPlane()+Data.getProjectionAnarPlane())/trustum_长度);
projectionMatrix.m23=-1;
projectionMatrix.m32=-((2*Data.getProjectionNearPlane()*Data.getProjectionFarPlane())/trustum_length);
projectionMatrix.m33=0;
}
私有静态void updateProjectMatrix(){
float aspectRatio=(float)Data.getWindowWidth()/(float)Data.getWin
float y_scale = (float) ((1f / Math.tan(Math.toRadians(Data.getProjectionFov() / 2f))) * aspectRatio);
float y_scale = (float) ((1f / Math.tan(Math.toRadians(Data.getProjectionFov() / 2f))) );