为什么我的 LWJGL alpha_anti_aliasing 不起作用

问题描述

我刚刚用 LWJGL 编写了一些代码,当我现在启动我的程序时,它只输出一个带有圆边的正方形(圆边是在着色器中创建的,而不是由纹理创建的)。这个正方形在这些边缘周围有很多锯齿,我想将其删除。我相信,在 LWJGL 中执行此操作的常用方法就是将 glfwWindowHint(GLFW_SAMPLES,8); 添加到窗口提示中,然后调用 glEnable(GL_MULTISAMPLE);。边缘是圆形的,因为它们的 alpha 值(不是因为它们有多个顶点),我还必须调用 glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE) 以启用 OpenGL alpha Anti-Aliasing。但由于某种原因这不起作用,只有 alpha 混合很好,但 alpha AA 没有激活。这是窗口创建代码

private void init() {
    GLFWErrorCallback.createPrint(System.err).set();
    if (!glfwInit())
        throw new IllegalStateException("Unable to initialize GLFW");

    glfwDefaultwindowHints();
    glfwWindowHint(GLFW_VISIBLE,GLFW_FALSE);
    glfwWindowHint(GLFW_RESIZABLE,GLFW_TRUE);
    glfwWindowHint(GLFW_DECORATED,GLFW_FALSE);
    glfwWindowHint(GLFW_SAMPLES,8);
    
    //glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER,GLFW_TRUE);
    
    window = glfwCreateWindow(width,height,title,NULL,NULL);
    
    if(window == NULL) {
        throw new RuntimeException("Failed to create the GLFW window");
    }
    
    glfwSetKeyCallback(window,(window,key,scancode,action,mods) -> {
        keyPress(window,mods);
    });
    glfwSetCursorPosCallback(window,xPos,yPos) -> {
        mousePos(window,yPos);
    });
    glfwSetMouseButtonCallback(window,button,mods) -> {
        mouseClick(window,mods);
    });
    
    glfwSetwindowSizeCallback(window,width,height) -> {
        glViewport(0,height);
    });
    
    try ( MemoryStack stack = stackPush() ) {
        IntBuffer pWidth = stack.malLocint(1);
        IntBuffer pHeight = stack.malLocint(1);
        glfwGetwindowSize(window,pWidth,pHeight);
        GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
        glfwSetwindowPos(
                window,(vidmode.width() - pWidth.get(0)) / 2,(vidmode.height() - pHeight.get(0)) / 2
        );
    }
    
    glfwMakeContextCurrent(window);
    glfwSwapInterval(1);
    glfwShowWindow(window);
    GL.createCapabilities();
    
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);  
    glEnable(GL_MULTISAMPLE); 

    
    try {
        initCallback.invoke(this);
    } catch (illegalaccessexception | IllegalArgumentException | InvocationTargetException e) {
        System.err.println("Incompatible Method for initCallback");
    }
}

有人知道为什么这不起作用吗?

解决方法

在 GPU 的控制面板中打开 AA。

enter image description here

AA 关闭: enter image description here

AA 开启: enter image description here

编辑:OP 说他们有一张 AMD 卡。 Here 编辑 2:更正了答案并添加了图片。

附言window.samples 是我为 GLFW/LWJGL 3.2 编写的包装器。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...