本文整理汇总了C++中GLShader::loadShader方法的典型用法代码示例。如果您正苦于以下问题:C++ GLShader::loadShader方法的具体用法?C++ GLShader::loadShader怎么用?C++ GLShader::loadShader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GLShader
的用法示例。
在下文中一共展示了GLShader::loadShader方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createShader
/// This function will create a new shader program from the raw code
/// It runs a preprocessing step to identify what portions belong to what shader
GDI_ShaderProgram* RendererOpenGL::createShader(const String& code)
{
GLShader* shaderProgram = new GLShader;
String _vertex;
String _frag;
int current_type = 0;
std::size_t i = 0;
while (i < code.size())
{
if (code[i] == '#' && code.substr(i + 1, 6) == "VERTEX")
{
current_type = 1;
i += 7;
}
else if (code[i] == '#' && code.substr(i + 1, 5) == "PIXEL")
{
current_type = 2;
i += 6;
}
else if (current_type == 0)
{
++i;
}
else
{
// add the char to the sources
if (current_type == 1)
{
_vertex += code[i++];
}
else if (current_type == 2)
{
_frag += code[i++];
}
}
}
shaderProgram->loadShader(GLShader::VertexUnit, _vertex);
shaderProgram->loadShader(GLShader::FragmentUnit, _frag);
shaderProgram->addAttributeLocation(0, "vertex");
shaderProgram->addAttributeLocation(1, "color");
shaderProgram->addAttributeLocation(2, "texCoord");
shaderProgram->addAttributeLocation(3, "normal");
if (shaderProgram->create())
{
Log("SUCCESS CREATESHADER");
}
std::cout << "Vertex " << std::endl
<< _vertex << std::endl;
std::cout << "Pixel " << std::endl
<< _frag << std::endl;
_shaderPrograms.push_back(shaderProgram);
return shaderProgram;
}