You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
W2.Wizard edited this page Mar 9, 2022
·
5 revisions
Shaders
In computer graphics, a shader is a type of computer program used for shading in 3D/2D scenes (the production of appropriate levels of light, darkness, and color in a rendered image). MLX42 does expose the shaders and compiles them into the library for portability.
// Example of shader code, GLSL is similar to C but not quite.#version330 core
layout(location =0) invec3 aPos;
layout(location =1) invec2 aTexCoord;
outvec2 TexCoord;
uniformmat4 ProjMatrix;
void main()
{
gl_Position= ProjMatrix *vec4(aPos, 1.0);
TexCoord = aTexCoord;
}
Beware
Shaders aren't really meant to be used by students but are more there for convenience of the developers. (though some advanced students might make some use of them)
Compiliation
Shaders are converted into a .c appropriate format and then compiled into the library and referenced via an extern global variable appropriately named vert_shader & frag_shader. The reason why this is done is because to keep the final game/executable portable, that is being able to use it at any given location within a filesystem, while still being easy to work on the shaders instead of having to mess with it in the .c files directly.