首页 > 解决方案 > 全屏闪烁:LWJGL

问题描述

我已经看到有关 LWJGL 窗口在渲染期间闪烁的问题,但我在这里谈论的是全屏闪烁,而不仅仅是窗口。闪烁是正常计算机屏幕的约 1.5 秒长,然后是全黑约 1.5 秒。

我不想全屏运行应用程序。

我正在使用本教程中的代码,我在 Kotlin 中重写了该代码:

fun main(args: Array<String>){
    SharedLibraryLoader.load()

    thread {
        Main.run()
    }
}

object Main: Runnable {

    val window: Long

    init {
        if (glfwInit() != GL_TRUE)
            throw RuntimeException("Couldn't initialize GLFW...")

        glfwWindowHint(GLFW_RESIZABLE, GL_TRUE)

        window = glfwCreateWindow(800, 600, "Test", NULL, NULL)
        if (window == NULL)
            throw RuntimeException("Couldn't create the window...")

        val videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor())
        glfwSetWindowPos(window, 100, 100)
        glfwMakeContextCurrent(window)
        glfwShowWindow(window)
    }

    fun update() {
        glfwPollEvents()
    }

    fun render() {
        glfwSwapBuffers(window)
    }

    override fun run() {
        while (glfwWindowShouldClose(window) != GL_TRUE){
            update()
            render()
        }
    }

}

使用 Gradle 依赖项:

val lwjglVersion = "3.0.0a"
compile("org.lwjgl:lwjgl:${lwjglVersion}")
compile("org.lwjgl:lwjgl-platform:${lwjglVersion}:natives-windows")
compile("org.lwjgl:lwjgl-platform:${lwjglVersion}:natives-linux")
compile("org.lwjgl:lwjgl-platform:${lwjglVersion}:natives-osx")

我在 Debian 9 机器(Linux)上。这是显卡问题吗?还是代码错了?

标签: lwjgl

解决方案


推荐阅读