loadShader()

Rendering / Shaders

Description

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

NameTypeDescription
fragPathstd::stringpath to fragment shader file
vertPathstd::stringpath 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; }