本文整理汇总了C++中GLSLProgram::loadShader方法的典型用法代码示例。如果您正苦于以下问题:C++ GLSLProgram::loadShader方法的具体用法?C++ GLSLProgram::loadShader怎么用?C++ GLSLProgram::loadShader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GLSLProgram
的用法示例。
在下文中一共展示了GLSLProgram::loadShader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: customInit
void OgroInvasion::customInit()
{
filename = g_programName + "/" + "Lenna.png";
try
{
glslProgram.loadShader(GLSLShaderType::VERTEX, g_programName + "/" + "shader.vert");
glslProgram.loadShader(GLSLShaderType::FRAGMENT, g_programName + "/" + "shader.frag");
}
catch (GLSLProgramException& e)
{
printf("%s\n", e.what());
system("pause");
exit(EXIT_FAILURE);
}
glslProgram.link();
GLint vertexAttribLoc = glslProgram.getAttributeLocation("vVertex");
//quad vertices and indices
glm::vec2 vertices[4];
GLushort indices[6];
vertices[0] = glm::vec2(0.0f, 0.0f);
vertices[1] = glm::vec2(1.0f, 0.0f);
vertices[2] = glm::vec2(1.0f, 1.0f);
vertices[3] = glm::vec2(0.0f, 1.0f);
GLushort* id = indices;
*id++ = 0;
*id++ = 1;
*id++ = 2;
*id++ = 0;
*id++ = 2;
*id++ = 3;
glGenVertexArrays(1, &vaoID);
glBindVertexArray(vaoID);
glGenBuffers(1, &vboVerticesID);
glGenBuffers(1, &vboIndicesID);
glBindBuffer(GL_ARRAY_BUFFER, vboVerticesID);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vboIndicesID);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
glVertexAttribPointer(vertexAttribLoc, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
glEnableVertexAttribArray(vertexAttribLoc);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
mTexture = new Texture(filename);
mTexture->load();
mTexture->activateTexture(0); // GL_TEXTURE0
glslProgram.setUniform("textureMap", 0); // GL_TEXTURE0
}
示例2: customInit
void HelloGLSL::customInit()
{
try
{
glslProgram.loadShader(GLSLShaderType::VERTEX, g_programName + "/" + "HelloGLSL.vert");
glslProgram.loadShader(GLSLShaderType::FRAGMENT, g_programName + "/" + "HelloGLSL.frag");
}
catch (GLSLProgramException& e)
{
printf("%s\n", e.what());
system("pause");
exit(EXIT_FAILURE);
}
glslProgram.link();
glGenBuffers(1, &positionBufferObject);
glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW);
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
GLint positionLoc = glslProgram.getAttributeLocation("position");
glEnableVertexAttribArray(positionLoc);
glVertexAttribPointer(positionLoc, 4, GL_FLOAT, GL_FALSE, 0, 0);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}