本文整理汇总了C++中ShaderProgram::AttachShader方法的典型用法代码示例。如果您正苦于以下问题:C++ ShaderProgram::AttachShader方法的具体用法?C++ ShaderProgram::AttachShader怎么用?C++ ShaderProgram::AttachShader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShaderProgram
的用法示例。
在下文中一共展示了ShaderProgram::AttachShader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InitializeProgram
void InitializeProgram() {
Shader s1(GL_VERTEX_SHADER), s2(GL_FRAGMENT_SHADER);
s1.CompileSource(strVertexShader);
s2.CompileSource(strFragmentShader);
ShaderProgram program;
program.AttachShader(s1);
program.AttachShader(s2);
program.SetupProgram();
glUseProgram(program.id());
}
示例2: WinMain
int CALLBACK WinMain(
__in HINSTANCE hInstance,
__in HINSTANCE hPrevInstance,
__in LPSTR lpCmdLine,
__in int nCmdShow
)
#endif
{
if (!glfwInit())
return 0;
GLFWwindow* window = glfwCreateWindow(640, 480, "Window Title", NULL, NULL);
glfwMakeContextCurrent(window);
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK)
return -1;
GLuint vertexBuffer;
glGenBuffers(1, &vertexBuffer);
Shader* vertexShader = new Shader("Content\\Shaders\\vertexShader.vs", GL_VERTEX_SHADER);
Shader* fragmentShader = new Shader("Content\\Shaders\\fragmentShader.fs", GL_FRAGMENT_SHADER);
ShaderProgram* program = new ShaderProgram();
program->AttachShader(vertexShader);
program->AttachShader(fragmentShader);
program->BindFragDataLocation(0, "outColour");
program->Link();
program->Use();
GLint posAttrib = program->GetAttribLocation("position");
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
GLuint vbo;
glGenBuffers(1, &vbo);
float vertices[] = {
0.0f, 0.5f,
0.5f, -0.5f,
-0.5f, -0.5f
};
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(posAttrib);
glVertexAttribPointer
(posAttrib, // Ref input
2, // Number of values for input
GL_FLOAT, // Type of each component
GL_FALSE, // Whether to normalise
0, // Stride
0); // Offset
while (!glfwWindowShouldClose(window))
{
glClearColor(0.f, 0.f, 0.f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES, 0, 3);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwDestroyWindow(window);
return 0;
}