我已经在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);
}
}