-
Notifications
You must be signed in to change notification settings - Fork 0
Shader class
Note
LibGui has it's own build-in shaders, so if you don't need to have custom ones, you can just skip this part.
LibGui::Shader is wrapper for OpenGL shader programs, they are programs that run on GPU and calculate positions of vertexes and colors of individual pixels.
Warning
If you aren't familiar with shaders, please read this first.
To initialize from file you can simply do this:
LibGui::Shader MyShader("my_vertex_shader_source.txt", "my_fragment_shader_source.txt");If you have string variable you want to create shader from, you can do this:
std::string vertex_source;
std::string fragment_source;
LibGui::Shader MyShader;
MyShader.Compile(vertex_source, fragment_source);Binds shader.
Unbinds shader.
equivalent of this
Returns shader's OpenGL id.
To set an uniform, you can call one of these:
| int | unsigned int | float | |
|---|---|---|---|
| 1 value | SetUniform1Int |
SetUniform1UInt |
SetUniform1Float |
| Vec2 | SetUniformVec2i |
SetUniform2UInt |
SetUniformVec2 |
| Vec3 | SetUniform3Int |
SetUniform3UInt |
SetUniform3Float |
| Vec4 | SetUniform4Int |
SetUniform4UInt |
SetUniform4Float |
If the shader can run, the compilationSuccessful property will be true. Otherwise the errors will be printed to console, and added to std::vector<std::string> compilationErrors.
| Name | Description |
|---|---|
vec2 u_ParentPos |
Object.pos; will be added to vertexes final coord |
vec2 u_Scale |
Object.scale; will be multiplied with vertexes local coord |
vec2 u_RightVector |
first half of rotation matrix (come on, we don't even have linear algebra at school yet) |
vec2 u_UpVector |
second half of rotation matrix |
vec4 u_ParentPos |
Object.color; will be multiplied with vertexes color |
| Name | Desription |
|---|---|
sampler2D myTexture |
Object.texture |
bool u_HasTexture |
Object.texture!=nullptr |
vec2 u_EdgeMin |
Upper left corner of render mask |
vec2 u_EdgeMax |
Lower right corner of render mask |
Features