我决定选择OpenGL,现在我已经渲染了一个简单的三角形,我想学习如何使用其他方式来渲染glMultiDrawArraysIndirect
似乎没有任何包含此功能的简单在线示例。我试着在GitHub上搜索开源代码,但它主要是文档和复杂的框架。
有人可以解释使用glMultiDrawArraysIndirect
呈现Hello World三角形的步骤吗?
以下是我用于渲染简单三角形的以下工作代码。我有一张4.5 OpenGL卡。
static const char * vs_source[] =
{
"#version 450 core \n"
" \n"
"void main(void) \n"
"{ \n"
" const vec4 vertices[] = vec4[](vec4( 0.25, -0.25, 0.5, 1.0), \n"
" vec4(-0.25, -0.25, 0.5, 1.0), \n"
" vec4( 0.25, 0.25, 0.5, 1.0)); \n"
" \n"
" gl_Position = vertices[gl_VertexID]; \n"
"} \n"
};
static const char * fs_source[] =
{
"#version 450 core \n"
" \n"
"out vec4 color; \n"
" \n"
"void main(void) \n"
"{ \n"
" color = vec4(0.0, 0.8, 1.0, 1.0); \n"
"} \n"
};
program = glCreateProgram();
GLuint fs = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fs, 1, fs_source, NULL);
glCompileShader(fs);
GLuint vs = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vs, 1, vs_source, NULL);
glCompileShader(vs);
glAttachShader(program, vs);
glAttachShader(program, fs);
glLinkProgram(program);
glCreateVertexArrays(1, &vao);
while (!glfwWindowShouldClose(window))
{
const GLfloat green[] = { 0.0f, 0.25f, 0.0f, 1.0f };
glClearBufferfv(GL_COLOR, 0, green);
glUseProgram(program);
glDrawArrays(GL_TRIANGLES, 0, 3);
glfwSwapBuffers(window);
glfwPollEvents();
}