loadShader()
Rendering / ShadersDescription
Loads a GLSL shader from a file. Pass the fragment shader path and optionally the vertex shader path.
Syntax
PShader* loadShader(std::string fragPath)
PShader* loadShader(std::string fragPath, std::string vertPath)
Parameters
| Name | Type | Description |
|---|---|---|
| fragPath | std::string | path to fragment shader file |
| vertPath | std::string | path to vertex shader file (optional) |
Returns
PShader*Related
Under the Hood
From Processing.h:
PShader* loadShader(const std::string& fragPath, const std::string& vertPath="");
Under the Hood
From Processing.cpp:
PShader* PApplet::loadShader(const std::string& fragPath,const std::string& vertPath){
std::string fSrc=readShaderFile(fragPath);
std::string vSrc=vertPath.empty()?
"#version 120\nvoid main(){gl_Position=ftransform();gl_TexCoord[0]=gl_MultiTexCoord0;gl_FrontColor=gl_Color;}":
readShaderFile(vertPath);
if(fSrc.empty()){std::cerr<<"loadShader: could not read "<<fragPath<<"\n";return nullptr;}
PShader* s=new PShader(vSrc,fSrc);
s->compile();
return s;
}