mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-04-10 06:14:07 +08:00
feat: initialize OpenGL
This commit is contained in:
63
src/shaders/vShader.glsl
Normal file
63
src/shaders/vShader.glsl
Normal file
@@ -0,0 +1,63 @@
|
||||
#version 430
|
||||
|
||||
layout (location = 0) in vec3 pos;
|
||||
layout (location = 1) in vec2 texCoord;
|
||||
out vec2 tc;
|
||||
|
||||
|
||||
mat4 buildRotateX(float rad);
|
||||
mat4 buildRotateY(float rad);
|
||||
mat4 buildRotateZ(float rad);
|
||||
mat4 buildTranslate(float x, float y, float z);
|
||||
|
||||
uniform mat4 mv_matrix;
|
||||
uniform mat4 proj_matrix;
|
||||
out vec4 varyingColor;
|
||||
|
||||
layout (binding = 0) uniform sampler2D samp;
|
||||
|
||||
void main(void) {
|
||||
gl_Position = proj_matrix * mv_matrix * vec4(pos, 1.0);
|
||||
tc = texCoord;
|
||||
varyingColor = vec4(pos, 1.0) * 0.5 + vec4(0.5, 0.5, 0.5, 0.5);
|
||||
}
|
||||
|
||||
mat4 buildTranslate(float x, float y, float z) {
|
||||
mat4 trans = mat4(
|
||||
1.0, 0.0, 0.0, 0.0,
|
||||
0.0, 1.0, 0.0, 0.0,
|
||||
0.0, 0.0, 1.0, 0.0,
|
||||
x, y, z, 1.0
|
||||
);
|
||||
return trans;
|
||||
}
|
||||
|
||||
mat4 buildRotateX(float rad) {
|
||||
mat4 xrot = mat4(
|
||||
1.0, 0.0, 0.0, 0.0,
|
||||
0.0, cos(rad), -sin(rad), 0.0,
|
||||
0.0, sin(rad), cos(rad), 0.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
);
|
||||
return xrot;
|
||||
}
|
||||
|
||||
mat4 buildRotateY(float rad) {
|
||||
mat4 yrot = mat4(
|
||||
cos(rad), 0.0, sin(rad), 0.0,
|
||||
0.0, 1.0, 0.0, 0.0,
|
||||
-sin(rad), 0.0, cos(rad), 0.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
);
|
||||
return yrot;
|
||||
}
|
||||
|
||||
mat4 buildRotateZ(float rad) {
|
||||
mat4 zrot = mat4(
|
||||
cos(rad), -sin(rad), 0.0, 0.0,
|
||||
sin(rad), cos(rad), 0.0, 0.0,
|
||||
0.0, 0.0,1.0 , 0.0,
|
||||
0.0, 0.0, 0.0, 1.0
|
||||
);
|
||||
return zrot;
|
||||
}
|
||||
Reference in New Issue
Block a user