我刚刚用LWJGL编写了一些代码,当我现在开始我的程序时,它只是输出一个带有圆角的正方形(圆角边是在阴影中创建的,而不是通过纹理创建的)。这个正方形在边缘周围有很多混叠,我想把它去掉。我相信,在LWJGL中这样做的常见方法是将glfwWindowHint(GLFW_SAMPLES, 8);添加到窗口提示中,然后调用glEnable(GL_MULTISAMPLE);。边是四舍五入的,因为它们的alpha值(不是因为它们有多个顶点),我还必须调用glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE)来启用OpenGLα反混叠。但由于某些原因,这是行不通的,只有阿尔法混合是好的,但阿尔法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,key,scancode,action,mods);
});
glfwSetCursorPosCallback(window, (window,xPos,yPos) -> {
mousePos(window,xPos,yPos);
});
glfwSetMouseButtonCallback(window, (window,button,action,mods) -> {
mouseClick(window,button,action,mods);
});
glfwSetWindowSizeCallback(window, (window, width, height) -> {
glViewport(0, 0,width, 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");
}
}有人知道为什么这不管用吗?
发布于 2021-05-11 16:03:04
打开GPU控制面板中的AA。

AA起飞:

AA关于:

编辑: OP说他们有AMD卡。这里编辑2:更正答案并添加图像。
P.S. window.samples是我为GLFW/LWJGL3.2编写和使用的包装代码。
https://stackoverflow.com/questions/67490373
复制相似问题