vertex.glsl
Code:
layout (location = 0) in vec3 position;
layout (location = 1) in vec2 inCoords;
layout (location = 2) in vec4 fragmentColor;
out vec2 TexCoords;
out vec4 fragColor;
out vec4 setColor;
out vec3 pCoords;
uniform mat4 scale;
uniform mat4 rotateX;
uniform mat4 rotateY;
uniform mat4 rotateZ;
uniform mat4 translation;
uniform vec4 inColor;
mat4 project(float fov, float aspect, float zNear, float zFar) {
mat4 proj_mat;
float fovRad = 1/tan(radians(fov)/2);
proj_mat[0] = vec4( aspect * fovRad, 0.0, 0.0, 0.0 );
proj_mat[1] = vec4( 0.0, fovRad, 0.0, 0.0 );
proj_mat[2] = vec4( 0.0, 0.0, zFar / (zFar - zNear), 1.0 );
proj_mat[3] = vec4( 0.0, 0.0, (-zFar * zNear) / (zFar - zNear), 0.0 );
return proj_mat;
}
void main() {
float wx = 1.0;
mat4 rotation = (rotateX * rotateY * rotateZ);
vec4 rawPOS = vec4(position.xyz,wx);
mat4 view = (rotation * translation * scale);
mat4 projection = project( 45, 800/600, 0.1, 10000);
TexCoords = inCoords;
fragColor = fragmentColor;
setColor = inColor;
pCoords = position;
gl_Position = (projection * view * rawPOS);
}
fragment.glsl
Code:
precision mediump float;
out vec4 color;
in vec4 fragColor;
in vec4 setColor;
in vec3 pCoords;
in vec2 TexCoords;
uniform sampler2D thisTexture;
void main(){
if (setColor.w > 0) {
color = setColor;
} else {
color = texture(thisTexture, TexCoords) * setColor;
};
}
One thing i am doing that is different is instead of subtracting 1 from the array, i inserted a 0,0,0 at the top of the indices. Would this cause extra triangles ?