本文整理汇总了C++中GLShader::create方法的典型用法代码示例。如果您正苦于以下问题:C++ GLShader::create方法的具体用法?C++ GLShader::create怎么用?C++ GLShader::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GLShader
的用法示例。
在下文中一共展示了GLShader::create方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compile
bool Shader::compile (ShaderType::Enum target, const CharString &source)
{
//Make sure old shaders are detached
detachShaders();
//Create a new shader
GLShader *shader = new GLShader;
shader->create( target );
//Add to shader list
switch (target) {
case ShaderType::Vertex:
vertShaders.pushBack( shader ); break;
case ShaderType::Fragment:
fragShaders.pushBack( shader ); break; }
//Compile the source
bool status = shader->compile( source );
if (status)
printf( "%s shader compiled.\n",
target == ShaderType::Vertex ? "Vertex" : "Fragment" );
else
printf( "Failed compiling %s shader!",
target == ShaderType::Vertex ? "vertex" : "fragment" );
CharString infoLog = shader->getInfoLog ();
if (infoLog.length() > 0)
printf ("Info Log:\n%s\n", infoLog.buffer());
return status;
}
示例2: 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;
}