我已经在GLfW窗口中启用了多重采样,但是输出看起来很奇怪,而不是改善了对象的别名。
当我将Samples设置为0时,这就是结果。
当我将样本设置为8时,这就是结果。
增加样本后,输出将变得更易混淆。
这是代码。
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void processInput(GLFWwindow *window);
float Trianglevertices[] = {
-0.5f, -0.5f, 0.0f,
0.5f, -0.5f, 0.0f,
0.0f, 0.5f, 0.0f
};
int main(int argc, char *argv[])
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
glfwWindowHint(GLFW_SAMPLES, 8 ); // defined samples for GLFW Window
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH , SCR_HEIGHT, "Renderer", nullptr, nullptr); // Create the render window
if (window == NULL)
{
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
GLenum GlewInitResult;
glewExperimental = GL_TRUE;
GlewInitResult = glewInit();
if ( GLEW_OK != GlewInitResult) // Check if glew is initialized properly
{
glfwTerminate();
return -1;
}
glEnable(GL_MULTISAMPLE); // Enabled Multisample
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendEquation(GL_FUNC_ADD);
LoadShader("C:\\vertex.txt", "C:\\Fragment.txt");
unsigned int VBOdel, VAOdel;
glGenVertexArrays(1, &VAOdel);
glGenBuffers(1, &VBOdel);
glBindVertexArray(VAOdel);
glBindBuffer(GL_ARRAY_BUFFER, VBOdel);
glBufferData(GL_ARRAY_BUFFER, sizeof(Trianglevertices), &Trianglevertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (void*)0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
GetShader("TestShader").Use();
while (!glfwWindowShouldClose(window))
{
// input
// -----
processInput(window);
// glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.)
// -------------------------------------------------------------------------------
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
////////////////////////////////////////////////////////////////
glBindVertexArray(VAOdel);
glDrawArrays( GL_TRIANGLES, 0, 3);
glBindVertexArray(0);
glfwSwapBuffers(window);
glfwPollEvents();
}
// glfw: terminate, clearing all previously allocated GLFW resources.
// ------------------------------------------------------------------
glfwTerminate();
return 0;
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height );
}
void processInput(GLFWwindow *window)
{
if (glfwGetKey( window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
{
QMessageBox MsgBox;
MsgBox.setText("EScape Key Pressed");
glfwSetWindowShouldClose(window, true);
}
}
最佳答案
经过一番摆弄之后,我终于发现,如果我将“首选图形”处理器更改为“高性能Nvidia处理器”,则在NVidia控制面板中可以管理3D设置,因此可以进行多重采样。
最初将其设置为“自动选择”,并且该应用程序使用的是Integrated Graphics处理器。
关于c++ - 在GLFW窗口中启用多重采样不会提高抗锯齿的质量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56929872/