c++ - 在 GLFW 窗口中启用多重采样不会提高抗锯齿的质量
问题描述
我在 GLfW 窗口中启用了多重采样,但输出看起来很奇怪,而不是改善对象变得更加混叠。
增加样本后,输出变得更加混叠。
这是代码。
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);
}
}
解决方案
推荐阅读
- linux - 当分词器出现多次时如何解析文件并返回关键字后面的字符串
- flutter - 在 Flutter 应用中动态更改应用文本主题
- python - 如何组合嵌套列表和列表?
- javascript - 奇怪的 Nodejs 内存泄漏
- webdriver-io - webdriverIO 和 saucelab 集成不起作用
- python - 如何从 Python 中的列表中提取变化的文本?
- python - 如何从数据库中获取一个国家的城市列表?
- asp.net - 在 asp.net 框架 Web 应用程序中上传图像文件
- powershell - 从 Powershell ISE 和 Windows 资源管理器运行脚本的不同行为
- javascript - 关于 Discord 中的嵌入 (JAVASCRIPT)