基本上,我正在使用带有LWJGL的Java创建一个简单的游戏引擎。 要创建一个窗口,我使用的是GLFW,问题是当我以全屏模式打开一个窗口,然后进入窗口模式时,左上方的像素没有出现,它们基本上变得透明并显示了下方的像素。示例:
最奇怪的是,当我在窗口模式下创建窗口然后再次进入全屏并再次返回时,这还没有发生,所以我认为这可能与glfw提示有关?>
另一个奇怪的事情是,当我使用鼠标将窗口调整为较小的窗口时,左上方的像素消失了,但是当我重新调整尺寸时,它们会再次出现...
有人有什么解决方案不需要我以窗口模式启动窗口,然后才进入全屏模式吗?
由于我正在构建引擎,因此代码已经有些复杂,但是,如果我提取GLFW函数,则代码将如下所示:
GLFWErrorCallback.createPrint(System.err).set();
if (!GLFW.glfwInit());
GLFW.glfwDefaultHints();
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT,true);
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR,4);
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR,6);
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE,GLFW.GLFW_OPENGL_CORE_PROFILE);
long monitorReference = ...;
GLFWVidmode mode = GLFW.glfwGetVideoMode(monitorReference);
long windowReference = GLFW.glfwCreateWindow(mode.width(),mode.height(),title,monitorReference,0);
GLFW.glfwMakeContextCurrent(windowReference);
GLCapabilities capabilities = GL.createCapabilities();
GLFW.glfwSwapInterval(1);
GLFW.glfwShowWindow(windowReference);
GL11.glViewport(0,windowWidth,windowHeight);
// Bind Callbacks To Events
...
// main loop
while (toRun) {
if (Keyboard.isKeypressed(GLFW.GLFW_KEY_F)) // go from fullscreen mode to windowed mode
GLFW.glfwSetWindowMonitor(windowReference,somePosX,somePosY,someWidth,someHeight,0);
GLFW.glfwSwapBuffers(windowReference);
GLFW.glfwPollEvents();
}
// Cleanup stuff
...
// Resize callback code
static void windowSizeCallback(long windowReference,int width,int height) {
if (GLFW.glfwgetcurrentContext() != windowReference) {
GLFW.glfwMakeContextCurrent(windowReference);
GL.setCapabilities(capabilities);
}
GL11.glViewport(0,newWindowWidth,newWindowHeight);
}