gpt4 book ai didi

Java LWJGL glfwGetMonitorPhysicalSize 和 glfwGetVideoMode 未返回预期值

转载 作者:行者123 更新时间:2023-11-30 08:12:24 26 4
gpt4 key购买 nike

我目前正在尝试创建一个基本的监视器实用程序类,用于在监视器上获取和打印信息。我在 java 中使用 LWJGL 为此。当我调用函数 glfwGetMonitorPhysicalSize 时,x 和 y 总是返回 0。而glfwGetVideoMode函数只返回“- '”。我找不到我在这里做错了什么!

而且,每次运行程序时,monitorID 似乎都不同。这正常吗?

请注意,此代码只是一个测试片段:

private static GLFWErrorCallback errorCallback = Callbacks.errorCallbackPrint(System.out);
private static PointerBuffer monitors = null;

public static long getPrimaryMonitor(){
glfwSetErrorCallback(errorCallback);

if(glfwInit() == GL_FALSE)
System.out.println("error");

monitors = glfwGetMonitors();
long monitorId = monitors.get(0);

// Monitor name
System.out.println(glfwGetMonitorName(monitorId));

// Monitor physical size
IntBuffer xSize = IntBuffer.allocate(4);
IntBuffer ySize = IntBuffer.allocate(4);
glfwGetMonitorPhysicalSize(monitorId, xSize, ySize);

System.out.print("Pos X: ");
while(xSize.hasRemaining())
System.out.print(xSize.get());
System.out.println();

System.out.print("Pos Y: ");
while(ySize.hasRemaining())
System.out.print(ySize.get());
System.out.println();

// Monitor video mode
ByteBuffer videoMode = glfwGetVideoMode(monitorId);

System.out.print("Video mode: ");
while(videoMode.hasRemaining())
System.out.print(videoMode.getChar());
System.out.println();

return monitorId;
}

最佳答案

我找到了解决办法!这些函数实际上返回了有效值,但显然我以错误的方式读取它们!

视频模式的正确使用方法:

ByteBuffer vidmode = glfwGetVideoMode(monitorId);

System.out.println("Video mode width: " + GLFWvidmode.width(vidmode));
System.out.println("Video mode height: " + GLFWvidmode.height(vidmode));

关于Java LWJGL glfwGetMonitorPhysicalSize 和 glfwGetVideoMode 未返回预期值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30192667/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com