|
|
|
|
@ -43,26 +43,26 @@ typedef Attribute<2, Vector2> TextureCoords;
|
|
|
|
|
- **Constructor**, which attaches particular shaders, links the program, |
|
|
|
|
binds attribute locations and gets uniform locations, for example: |
|
|
|
|
@code |
|
|
|
|
// Load shaders from file and attach them to the program
|
|
|
|
|
Shader* vertexShader = Shader::fromFile(Shader::Vertex, "PhongShader.vert"); |
|
|
|
|
Shader* fragmentShader = Shader::fromFile(Shader::Fragment, "PhongShader.frag"); |
|
|
|
|
attachShader(vertexShader); |
|
|
|
|
attachShader(fragmentShader); |
|
|
|
|
|
|
|
|
|
// Bind attribute names to IDs
|
|
|
|
|
bindAttribute(Vertex::Location, "vertex"); |
|
|
|
|
bindAttribute(Normal::Location, "normal"); |
|
|
|
|
bindAttribute(TextureCoords::Location, "textureCoords"); |
|
|
|
|
|
|
|
|
|
// Link, then delete now uneeded shaders
|
|
|
|
|
link(); |
|
|
|
|
delete vertexShader; |
|
|
|
|
delete fragmentShader; |
|
|
|
|
|
|
|
|
|
// Get locations of uniforms
|
|
|
|
|
transformationMatrixUniform = uniformLocation("transformationMatrix"); |
|
|
|
|
projectionMatrixUniform = uniformLocation("projectionMatrix"); |
|
|
|
|
// more uniforms like light location, colors etc.
|
|
|
|
|
// Load shaders from file and attach them to the program
|
|
|
|
|
Shader* vertexShader = Shader::fromFile(Shader::Vertex, "PhongShader.vert"); |
|
|
|
|
Shader* fragmentShader = Shader::fromFile(Shader::Fragment, "PhongShader.frag"); |
|
|
|
|
attachShader(vertexShader); |
|
|
|
|
attachShader(fragmentShader); |
|
|
|
|
|
|
|
|
|
// Bind attribute names to IDs
|
|
|
|
|
bindAttribute(Vertex::Location, "vertex"); |
|
|
|
|
bindAttribute(Normal::Location, "normal"); |
|
|
|
|
bindAttribute(TextureCoords::Location, "textureCoords"); |
|
|
|
|
|
|
|
|
|
// Link, then delete now uneeded shaders
|
|
|
|
|
link(); |
|
|
|
|
delete vertexShader; |
|
|
|
|
delete fragmentShader; |
|
|
|
|
|
|
|
|
|
// Get locations of uniforms
|
|
|
|
|
transformationMatrixUniform = uniformLocation("transformationMatrix"); |
|
|
|
|
projectionMatrixUniform = uniformLocation("projectionMatrix"); |
|
|
|
|
// more uniforms like light location, colors etc.
|
|
|
|
|
@endcode |
|
|
|
|
- **Uniform binding functions**, which set shader uniforms using |
|
|
|
|
setUniform() and setUniformArray() functions. Example: |
|
|
|
|
|