This commit is contained in:
John Alanbrook 2022-06-22 04:16:14 +00:00
parent b5de1012ff
commit 056ce83eb8
43 changed files with 1019 additions and 67 deletions

View file

@ -10,7 +10,7 @@ endif
UNAME_P != uname -m UNAME_P != uname -m
#CC specifies which compiler we're using #CC specifies which compiler we're using
CC = gcc -std=c99 CC = clang -std=c99
ifeq ($(DEBUG), 1) ifeq ($(DEBUG), 1)
DEFFALGS += -DDEBUG DEFFALGS += -DDEBUG
@ -87,7 +87,7 @@ ifeq ($(UNAME), Windows_NT)
CLIBS = glew32 CLIBS = glew32
EXT = .exe EXT = .exe
else else
LINKER_FLAGS = -static-libgcc LINKER_FLAGS =
ELIBS = editor engine ELIBS = editor engine
CLIBS = glfw SDL2 SDL2_mixer m CLIBS = glfw SDL2 SDL2_mixer m
EXT = EXT =
@ -96,7 +96,8 @@ endif
ELIBS != $(call prefix, $(ELIBS), -l) ELIBS != $(call prefix, $(ELIBS), -l)
CLIBS != $(call prefix, $(CLIBS), -l) CLIBS != $(call prefix, $(CLIBS), -l)
LELIBS = -Wl,-Bstatic $(ELIBS) -Wl,-Bdynamic $(CLIBS) #LELIBS = -Wl,-Bstatic $(ELIBS) -Wl,-Bdynamic $(CLIBS)
LELIBS = $(ELIBS) $(CLIBS)
objects = $(bsobjects) $(eobjects) $(pinobjects) objects = $(bsobjects) $(eobjects) $(pinobjects)
DEPENDS = $(objects:.o=.d) DEPENDS = $(objects:.o=.d)

BIN
fonts/notosans.ttf Executable file

Binary file not shown.

12
shaders/albedofrag.glsl Executable file
View file

@ -0,0 +1,12 @@
#version 330 core
out vec4 FragColor;
in vec3 FragPos;
in vec2 TexCoords;
uniform sampler2D texture_diffuse1;
void main()
{
FragColor = texture(texture_diffuse1, TexCoords);
}

14
shaders/animspritefrag.glsl Executable file
View file

@ -0,0 +1,14 @@
#version 330 core
in vec2 TexCoords;
out vec4 color;
uniform sampler2DArray image;
uniform float frame;
uniform vec3 spriteColor;
void main()
{
color = vec4(spriteColor, 1.f) * texture(image, vec3(TexCoords,frame));
if (color.a < 0.1)
discard;
}

17
shaders/animspritevert.glsl Executable file
View file

@ -0,0 +1,17 @@
#version 330 core
layout (location = 0) in vec2 vertex; // <vec2 position, vec2 texCoords>
out vec2 TexCoords;
layout (std140) uniform Projection
{
mat4 projection;
};
uniform mat4 model;
void main()
{
TexCoords = vertex.xy;
gl_Position = projection * model * vec4(vertex.xy, 0.0, 1.0);
}

3
shaders/billboardfrag.glsl Executable file
View file

@ -0,0 +1,3 @@
void main(){
color = texture( myTextureSampler, UV );
}

11
shaders/billboardvertex.glsl Executable file
View file

@ -0,0 +1,11 @@
void main(){
// Output position of the vertex, in clip space
// map [0..800][0..600] to [-1..1][-1..1]
vec2 vertexPosition_homoneneousspace = vertexPosition_screenspace - vec2(400,300); // [0..800][0..600] -> [-400..400][-300..300]
vertexPosition_homoneneousspace /= vec2(400,300);
gl_Position = vec4(vertexPosition_homoneneousspace,0,1);
// UV of the vertex. No special space for this one.
UV = vertexUV;
}

9
shaders/btdebugfrag.glsl Executable file
View file

@ -0,0 +1,9 @@
#version 330 core
layout (location = 0) out vec4 color;
in vec3 vcolor;
void main(void)
{
color = vec4(vcolor, 1.f);
}

17
shaders/btdebugvert.glsl Executable file
View file

@ -0,0 +1,17 @@
#version 330 core
layout (location = 0) in vec3 position;
layout (location = 1) in vec3 color;
layout (std140) uniform Matrices {
mat4 projection;
mat4 view;
};
out vec3 vcolor;
void main()
{
gl_Position = projection * view * vec4(position, 1.0f);
vcolor = color;
}

24
shaders/circlefrag.glsl Executable file
View file

@ -0,0 +1,24 @@
#version 330
in vec2 coords;
out vec4 color;
uniform float radius;
uniform int thickness;
void main()
{
// int tt = thickness + 1;
float R1 = 1.f;
float R2 = 1.f - (thickness / radius);
float dist = sqrt(dot(coords, coords));
if (dist <= R2 || dist >= R1)
discard;
/*
float smoother = 0.01f - (radius * 0.00003f);
float sm = smoothstep(R1, R1-smoother, dist);
float sm2 = smoothstep(R2, R2+smoother, dist);
float alpha = sm*sm2;
*/
color = vec4(0.4f, 0.5f, 0.6f, 1.f);
}

15
shaders/circlevert.glsl Executable file
View file

@ -0,0 +1,15 @@
#version 330 core
layout (location = 0) in vec4 vertex;
out vec2 coords;
layout (std140) uniform Projection
{
mat4 projection;
};
void main()
{
coords = vertex.zw;
gl_Position = projection * vec4(vertex.xy, 0.0, 1.0);
}

9
shaders/debugcolorfrag.glsl Executable file
View file

@ -0,0 +1,9 @@
#version 330 core
out vec4 FragColor;
uniform vec3 PickingColor;
void main()
{
FragColor = vec4(PickingColor, 1.0); // orthographic
}

22
shaders/debugdepthfrag.glsl Executable file
View file

@ -0,0 +1,22 @@
#version 330 core
out vec4 FragColor;
in vec2 TexCoords;
uniform sampler2D depthMap;
uniform float near_plane;
uniform float far_plane;
// required when using a perspective projection matrix
float LinearizeDepth(float depth)
{
float z = depth * 2.0 - 1.0; // Back to NDC
return (2.0 * near_plane * far_plane) / (far_plane + near_plane - z * (far_plane - near_plane));
}
void main()
{
float depthValue = texture(depthMap, TexCoords).r;
//FragColor = vec4(vec3(LinearizeDepth(depthValue) / far_plane), 1.0); // perspective
FragColor = texture(depthMap, TexCoords); // orthographic
}

99
shaders/fragment.glsl Executable file
View file

@ -0,0 +1,99 @@
#version 330 core
out vec4 FragColor;
struct Light {
vec3 direction;
vec3 color;
};
struct PLight {
vec3 position;
vec3 color;
float constant;
float linear;
float quadratic;
};
struct SLight {
vec3 position;
vec3 direction;
float cutOff;
float outerCutOff;
};
uniform vec3 objectColor;
uniform vec3 lightColor;
uniform vec3 lightPos;
uniform vec3 viewPos;
uniform sampler2D diffuseTex;
uniform sampler2D specTex;
uniform float shininess;
uniform Light light;
uniform PLight plight;
uniform SLight slight;
in vec3 Normal;
in vec3 FragPos;
in vec2 TexCoords;
float near = 0.1;
float far = 100.0;
float LinearizeDepth(float depth)
{
float z = depth * 2.0 - 1.0; // back to NDC
return (2.0 * near * far) / (far + near - z * (far - near));
}
// void main()
// {
// float depth = LinearizeDepth(gl_FragCoord.z) / far; // divide by far for demonstration
// FragColor = vec4(vec3(depth), 1.0);
// }
void main()
{
//vec3 dirDir = normalize(-Directional.direction);
float ambientStrength = 1.f;
vec3 ambient = ambientStrength * vec3(texture(diffuseTex, TexCoords));
// vec3 norm = normalize(Normal);
// vec3 diffuse;
// Directional
//vec3 lightDir = normalize(-light.direction);
// Point
// float distance = length(plight.position - FragPos);
// float attenuation = 1.f / (plight.constant + plight.linear * distance + plight.quadratic * (distance * distance));
// vec3 lightDir = normalize(lightPos - FragPos);
// float diff = max(dot(norm, lightDir), 0.f);
//diffuse = diff * lightColor * vec3(texture(diffuseTex, TexCoords)) * attenuation;
// Spot
// lightDir = normalize(slight.position - FragPos);
// float theta = dot(lightDir, normalize(-slight.direction));
// float epsilon = slight.cutOff - slight.outerCutOff;
// float intensity = clamp((theta - slight.outerCutOff) / epsilon, 0.f, 1.f);
// diffuse = lightColor * diff * vec3(texture(diffuseTex, TexCoords)) * intensity;
// float specularStrength = 0.5f;
// vec3 viewDir = normalize(viewPos - FragPos);
// vec3 reflectDir = reflect(-lightDir, norm);
// float spec = pow(max(dot(viewDir, reflectDir), 0.f), 32);
// vec3 specular = specularStrength * spec * lightColor * texture(specTex, TexCoords).rgb;
// if(texture(specTex, TexCoords).r < 0.1f)
// discard;
//vec3 result = (ambient + diffuse + specular) * objectColor;
FragColor = vec4(ambient, 1.f);
}

11
shaders/gizmofrag.glsl Executable file
View file

@ -0,0 +1,11 @@
#version 330 core
layout (location = 0) out vec4 color;
in vec3 vcolor;
in vec3 FragPos;
void main(void)
{
color = vec4(vcolor, 1.f);
}

21
shaders/gizmovert.glsl Executable file
View file

@ -0,0 +1,21 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (std140) uniform Matrices {
mat4 projection;
mat4 view;
};
out vec3 vcolor;
uniform mat4 model;
void main()
{
vec3 m = aPos;
vcolor.r = m.r / 1.f;
vcolor.g = m.g / 1.f;
vcolor.b = m.b / 1.f;
gl_Position = projection * view * model * (vec4(m, 1.f));
}

19
shaders/gridfrag.glsl Executable file
View file

@ -0,0 +1,19 @@
#version 330
out vec4 color;
in vec2 apos;
vec2 bpos;
uniform int thickness;
uniform int span;
void main(void)
{
float t = thickness / 2.f;
bpos.x = mod(apos.x, span);
bpos.y = mod(apos.y, span);
if (!(bpos.x <= t || bpos.x >= (span - t) || bpos.y <= t || bpos.y >= (span - t)))
discard;
color = vec4(0.4f, 0.7f, 0.2f, 0.3f);
}

16
shaders/gridvert.glsl Executable file
View file

@ -0,0 +1,16 @@
#version 330
layout (location = 0) in vec2 pos;
out vec2 apos;
layout (std140) uniform Projection {
mat4 projection;
};
void main()
{
mat4 iproj = inverse(projection);
vec4 ipos = iproj * vec4(pos, 0.f, 1.f);
apos = ipos.xy;
gl_Position = vec4(pos, 0.f, 1.f);
}

7
shaders/lightfrag.glsl Executable file
View file

@ -0,0 +1,7 @@
#version 330 core
out vec4 FragColor;
void main()
{
FragColor = vec4(1.0f); // set alle 4 vector values to 1.0
}

11
shaders/lightvert.glsl Executable file
View file

@ -0,0 +1,11 @@
#version 330 core
layout (location = 0) in vec3 aPos;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
gl_Position = projection * view * model * vec4(aPos, 1.0);
}

7
shaders/linefrag.glsl Executable file
View file

@ -0,0 +1,7 @@
#version 330
out vec4 color;
void main()
{
color = vec4(0.2f, 0.1f, 0.8f, 1.f);
}

11
shaders/linevert.glsl Executable file
View file

@ -0,0 +1,11 @@
#version 330
layout (location = 0) in vec2 pos;
layout (std140) uniform Projection {
mat4 projection;
};
void main()
{
gl_Position = projection * vec4(pos, 0.f, 1.f);
}

185
shaders/modelfrag.glsl Executable file
View file

@ -0,0 +1,185 @@
#version 330 core
out vec4 FragColor;
struct Light {
vec3 direction;
vec3 color;
float strength;
};
struct PLight {
vec3 position;
float constant;
float linear;
float quadratic;
vec3 color;
float strength;
};
struct SpotLight {
vec3 position;
vec3 direction;
vec3 color;
float strength;
float cutoff;
float outerCutoff;
float distance;
float constant;
float linear;
float quadratic;
};
in vec3 FragPos;
in vec2 TexCoords;
in vec4 FragPosLightSpace;
in mat3 TBN;
//in vec3 TangentLightPos;
in vec3 TangentViewPos;
in vec3 TangentFragPos;
uniform sampler2D texture_diffuse1;
uniform sampler2D texture_normal1;
uniform sampler2D shadowMap;
uniform Light dirLight;
uniform vec3 viewPos;
vec3 norm;
vec3 viewDir;
#define NR_POINT_LIGHTS 1
uniform PLight pointLights[NR_POINT_LIGHTS];
uniform SpotLight spotLight;
float ShadowCalculation(vec4 fragPosLightSpace, vec3 normal, vec3 lightDir) {
// perform perspective divide
vec3 projCoords = fragPosLightSpace.xyz / fragPosLightSpace.w;
// transform to [0,1] range
projCoords = projCoords * 0.5 + 0.5;
// get closest depth value from light's perspective (using [0,1] range fragPosLight as coords)
float closestDepth = texture(shadowMap, projCoords.xy).r;
// get depth of current fragment from light's perspective
float currentDepth = projCoords.z;
// calculate bias (based on depth map resolution and slope)
float bias = max(0.05 * (1.0 - dot(normal, lightDir)), 0.005);
// check whether current frag pos is in shadow
// float shadow = currentDepth - bias > closest Depth ? 1.0 : 0.0;
// PCF
float shadow = 0.0;
vec2 texelSize = 1.0 / textureSize(shadowMap, 0);
for(int x = -1; x <= 1; ++x)
{
for(int y = -1; y <= 1; ++y)
{
float pcfDepth = texture(shadowMap, projCoords.xy + vec2(x, y) * texelSize).r;
shadow += currentDepth - bias > pcfDepth ? 1.0 : 0.0;
}
}
shadow /= 9.0;
// keep the shadow at 0.0 when outside the far_plane region of the light's frustum.
if(projCoords.z > 1.0)
shadow = 0.0;
return shadow;
}
vec3 CalcDirLight(Light light) {
vec3 lightDir = TBN * normalize(-light.direction);
float lightStrength = 3.f;
vec3 lightColor = vec3(1.f);
// diffuse shading
float diff = max(dot(norm, lightDir), 0.f);
// specular shading
float specularStrength = 0.5f;
vec3 reflectDir = reflect(-lightDir, norm);
vec3 halfwayDir = normalize(lightDir + viewDir); // Use this instead of reflectDir?
float spec = pow(max(dot(viewDir, halfwayDir), 0.0), 32.f) * specularStrength; // 32.f is "shininess"
float shadow = ShadowCalculation(FragPosLightSpace, norm, lightDir);
// combine results
return light.strength * (diff + spec) * (1.f-shadow) * light.color;
}
vec3 CalcPointLight(PLight light) {
vec3 tbnPos = TBN * light.position;
vec3 lightDir = normalize(tbnPos - TangentFragPos);
// Diffuse
float diff = max(dot(norm, lightDir), 0.f);
// specular
vec3 reflectDir = reflect(-lightDir, norm);
vec3 halfwayDir = normalize(lightDir + viewDir);
float spec = pow(max(dot(viewDir, halfwayDir), 0.f), 32.f);
// Attenuation
float distance = length(light.position - TangentFragPos);
float attenuation = 1.f / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
return light.color * attenuation * light.strength * (diff + spec);
}
vec3 CalcSpotLight(SpotLight light) {
vec3 tbnPos = TBN * light.position;
vec3 tbnDir = TBN * light.direction;
vec3 lightDir = normalize(tbnPos - TangentFragPos);
float diff = max(dot(norm, lightDir), 0.f);
vec3 reflectDir = reflect(-lightDir, norm);
vec3 halfwayDir = normalize(lightDir + viewDir);
float spec = pow(max(dot(viewDir, halfwayDir), 0.f), 32.f);
float theta = dot(lightDir, normalize(-tbnDir));
float epsilon = light.cutoff - light.outerCutoff;
float intensity = clamp((theta - light.outerCutoff) / epsilon, 0.f, 1.f);
float distance = length(light.position - FragPos);
float attenuation = 1.f / (light.constant + light.linear * distance + light.quadratic * (distance * distance));
return light.color * light.strength * (diff + spec) * intensity * attenuation;
}
void main()
{
vec4 model = texture(texture_diffuse1, TexCoords);
if (model.a <= 0.1f)
discard;
vec3 albedo = model.rgb;
norm = texture(texture_normal1, TexCoords).rgb;
norm = normalize(norm * 2.f - 1.f);
//vec3 norm = normalize(TangentViewPos);
viewDir = normalize(TangentViewPos - TangentFragPos);
// Ambient doesn't change
float ambientStrength = 0.3f;
vec3 ambientColor = vec3(1.f);
vec3 ambient = ambientStrength * ambientColor;
// Per light calculation
// Directional
vec3 result = CalcDirLight(dirLight);
result += ambient;
// Point
for (int i = 0; i < NR_POINT_LIGHTS; i++)
result += CalcPointLight(pointLights[i]);
result += CalcSpotLight(spotLight);
FragColor = vec4(result * model.rgb, 1.f);
}

68
shaders/modelvert.glsl Executable file
View file

@ -0,0 +1,68 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTexCoords;
layout (location = 3) in vec3 aTangent;
layout (location = 4) in vec3 aBitangent;
layout (location = 5) in ivec4 boneIds;
layout (location = 6) in vec4 weights;
layout (std140) uniform Matrices {
mat4 projection;
mat4 view;
};
//out vec3 Normal;
out vec3 FragPos;
out vec2 TexCoords;
//out vec3 TangentLightPos;
out vec3 TangentViewPos;
out vec3 TangentFragPos;
out vec4 FragPosLightSpace;
out mat3 TBN;
uniform mat4 model;
uniform mat4 lightSpaceMatrix;
uniform vec3 viewPos;
const int MAX_BONES = 100;
const int MAX_BONE_INFLUENCE = 4;
uniform mat4 finalBonesMatrices[MAX_BONES];
void main()
{
vec4 totalPosition = vec4(0.f);
for (int i = 0; i < MAX_BONE_INFLUENCE; i++) {
if (boneIds[i] == -1)
continue;
if (boneIds[i] >= 4) {
totalPosition = vec4(aPos, 1.f);
break;
}
vec4 localPosition = finalBonesMatrices[boneIds[i]] * vec4(aPos, 1.f);
totalPosition += localPosition * weights[i];
vec3 localNormal = mat3(finalBonesMatrices[boneIds[i]]) * aNormal;
}
FragPos = vec3(model * vec4(aPos, 1.f));
TexCoords = aTexCoords;
mat3 normalMatrix = transpose(inverse(mat3(model)));
vec3 T = normalize(normalMatrix * aTangent);
vec3 N = normalize(normalMatrix * aNormal);
T = normalize(T - dot(T, N) * N);
vec3 B = cross(N, T);
TBN = transpose(mat3(T, B, N));
// TangentLightPos = TBN * lightPos;
TangentViewPos = TBN * viewPos;
TangentFragPos = TBN * FragPos;
FragPosLightSpace = lightSpaceMatrix * vec4(FragPos, 1.f);
gl_Position = projection * view * model * totalPosition;
}

7
shaders/outline.glsl Executable file
View file

@ -0,0 +1,7 @@
#version 330 core
out vec4 FragColor;
void main()
{
FragColor = vec4(0.92f, 0.86f, 0.68f, 1.0f);
}

15
shaders/outlinevert.glsl Executable file
View file

@ -0,0 +1,15 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
layout (std140) uniform Matrices {
mat4 projection;
mat4 view;
};
uniform mat4 model;
void main()
{
gl_Position = projection * view * model * vec4(aPos + (aNormal * 2.f), 1.f);
}

58
shaders/postfrag.glsl Executable file
View file

@ -0,0 +1,58 @@
#version 330 core
out vec4 FragColor;
in vec2 TexCoords;
uniform sampler2D screenTexture;
const float offset = 1.0 / 300.0;
void main()
{
FragColor = texture(screenTexture, TexCoords);
//Invert color
//FragColor = vec4(vec3(1.0 - texture(screenTexture, TexCoords)), 1.0);
//Grayscale
//FragColor = texture(screenTexture, TexCoords);
//float average = 0.2126 * FragColor.r + 0.7152 * FragColor.g + 0.0722 * FragColor.b;
//FragColor = vec4(average, average, average, 1.0);
//Blur
// vec2 offsets[9] = vec2[](
// vec2(-offset, offset), // top-left
// vec2( 0.0f, offset), // top-center
// vec2( offset, offset), // top-right
// vec2(-offset, 0.0f), // center-left
// vec2( 0.0f, 0.0f), // center-center
// vec2( offset, 0.0f), // center-right
// vec2(-offset, -offset), // bottom-left
// vec2( 0.0f, -offset), // bottom-center
// vec2( offset, -offset) // bottom-right
// );
// Sharpen kernel
// float kernel[9] = float[](
// -1, -1, -1,
// -1, 9, -1,
// -1, -1, -1
// );
// Blur kernel
// float kernel[9] = float[](
// 1.0 / 16, 2.0 / 16, 1.0 / 16,
// 2.0 / 16, 4.0 / 16, 2.0 / 16,
// 1.0 / 16, 2.0 / 16, 1.0 / 16
// );
// vec3 sampleTex[9];
// for(int i = 0; i < 9; i++)
// {
// sampleTex[i] = vec3(texture(screenTexture, TexCoords.st + offsets[i]));
// }
// vec3 col = vec3(0.0);
// for(int i = 0; i < 9; i++)
// col += sampleTex[i] * kernel[i];
// FragColor = vec4(col, 1.0);
}

11
shaders/postvert.glsl Executable file
View file

@ -0,0 +1,11 @@
#version 330 core
layout (location = 0) in vec2 aPos;
layout (location = 1) in vec2 aTexCoords;
out vec2 TexCoords;
void main()
{
gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0);
TexCoords = aTexCoords;
}

6
shaders/shadowfrag.glsl Executable file
View file

@ -0,0 +1,6 @@
#version 330 core
void main()
{
// gl_FragDepth = gl_FragCoord.z;
}

10
shaders/shadowvert.glsl Executable file
View file

@ -0,0 +1,10 @@
#version 330 core
layout (location = 0) in vec3 aPos;
uniform mat4 lightSpaceMatrix;
uniform mat4 model;
void main()
{
gl_Position = lightSpaceMatrix * model * vec4(aPos, 1.0);
}

19
shaders/simplevert.glsl Executable file
View file

@ -0,0 +1,19 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 2) in vec2 aTexCoords;
layout (std140) uniform Matrices {
mat4 projection;
mat4 view;
};
out vec2 TexCoords;
uniform mat4 model;
void main()
{
TexCoords = aTexCoords;
gl_Position = projection * view * model * vec4(aPos, 1.f);
}

11
shaders/skyfrag.glsl Executable file
View file

@ -0,0 +1,11 @@
#version 330 core
out vec4 FragColor;
in vec3 TexCoords;
uniform samplerCube skybox;
void main()
{
FragColor = texture(skybox, TexCoords);
}

18
shaders/skyvert.glsl Executable file
View file

@ -0,0 +1,18 @@
#version 330 core
layout (location = 0) in vec3 aPos;
out vec3 TexCoords;
layout (std140) uniform Matrices {
mat4 projection;
mat4 view;
};
uniform mat4 skyview;
void main()
{
TexCoords = aPos;
vec4 pos = projection * skyview * vec4(aPos, 1.0);
gl_Position = pos.xyww;
}

14
shaders/spritefrag.glsl Executable file
View file

@ -0,0 +1,14 @@
#version 330 core
in vec2 texcoords;
out vec4 color;
uniform sampler2D image;
uniform vec3 spriteColor;
void main()
{
color = vec4(spriteColor, 1.f) * texture(image, texcoords);
if (color.a <= 0.1f)
discard;
}

16
shaders/spritevert.glsl Executable file
View file

@ -0,0 +1,16 @@
#version 330 core
layout (location = 0) in vec2 vertex;
out vec2 texcoords;
layout (std140) uniform Projection
{
mat4 projection;
};
uniform mat4 model;
void main()
{
texcoords = vertex.xy;
gl_Position = projection * model * vec4(vertex.xy, 0.0, 1.0);
}

12
shaders/textfrag.glsl Executable file
View file

@ -0,0 +1,12 @@
#version 330 core
in vec2 TexCoords;
out vec4 color;
uniform sampler2D text;
uniform vec3 textColor;
void main()
{
vec4 sampled = vec4(1.0, 1.0, 1.0, texture(text, TexCoords).r);
color = vec4(textColor, 1.0) * sampled;
}

11
shaders/textvert.glsl Executable file
View file

@ -0,0 +1,11 @@
#version 330 core
layout (location = 0) in vec4 vertex; // <vec2 pos, vec2 tex>
out vec2 TexCoords;
uniform mat4 projection;
void main()
{
gl_Position = projection * vec4(vertex.xy, 0.0, 1.0);
TexCoords = vertex.zw;
}

22
shaders/vertex.glsl Executable file
View file

@ -0,0 +1,22 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aNormal;
layout (location = 2) in vec2 aTexCoords;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
out vec3 Normal;
out vec3 FragPos;
out vec2 TexCoords;
void main()
{
FragPos = vec3(model * vec4(aPos, 1.f));
Normal = mat3(transpose(inverse(model))) * aNormal;
TexCoords = aTexCoords;
gl_Position = projection * view * model * vec4(aPos, 1.0f); // see how we directly give a vec3 to vec4's constructor
}

22
shaders/videofrag.glsl Executable file
View file

@ -0,0 +1,22 @@
#version 330 core
in vec2 TexCoords;
out vec4 color;
uniform sampler2D texture_y;
uniform sampler2D texture_cb;
uniform sampler2D texture_cr;
uniform vec3 spriteColor;
mat4 rec601 = mat4(
1.16438, 0.00000, 1.59603, -0.87079,
1.16438, -0.39176, -0.81297, 0.52959,
1.16438, 2.01723, 0.00000, -1.08139,
0, 0, 0, 1
);
void main() {
float y = texture2D(texture_y, TexCoords).r;
float cb = texture2D(texture_cb, TexCoords).r;
float cr = texture2D(texture_cr, TexCoords).r;
color = vec4(y, cb, cr, 1.f) * rec601 * vec4(spriteColor, 1.f);
}

12
shaders/videovert.glsl Executable file
View file

@ -0,0 +1,12 @@
#version 330 core
layout (location = 0) in vec4 vertex;
out vec2 TexCoords;
uniform mat4 model;
uniform mat4 projection;
void main() {
TexCoords = vertex.zw;
gl_Position = projection * model * vec4(vertex.xy, 0.0, 1.0);
}

View file

@ -6079,7 +6079,6 @@ NK_LIB void nk_property(struct nk_context *ctx, const char *name, struct nk_prop
#define STB_RECT_PACK_IMPLEMENTATION #define STB_RECT_PACK_IMPLEMENTATION
#define STB_TRUETYPE_IMPLEMENTATION #define STB_TRUETYPE_IMPLEMENTATION
/* Allow consumer to define own STBTT_malloc/STBTT_free, and use the font atlas' allocator otherwise */ /* Allow consumer to define own STBTT_malloc/STBTT_free, and use the font atlas' allocator otherwise */
#ifndef STBTT_malloc #ifndef STBTT_malloc
static void* static void*
@ -15095,6 +15094,7 @@ STBTT_DEF unsigned char *stbtt_GetGlyphBitmapSubpixel(const stbtt_fontinfo *info
stbtt_Rasterize(&gbm, 0.35f, vertices, num_verts, scale_x, scale_y, shift_x, shift_y, ix0, iy0, 1, info->userdata); stbtt_Rasterize(&gbm, 0.35f, vertices, num_verts, scale_x, scale_y, shift_x, shift_y, ix0, iy0, 1, info->userdata);
} }
}
STBTT_free(vertices, info->userdata); STBTT_free(vertices, info->userdata);
return gbm.pixels; return gbm.pixels;
} }

View file

@ -416,7 +416,7 @@ static void edit_mouse_cb(GLFWwindow *w, int button, int action, int mods)
} }
} }
struct nk_context *nkctx; struct nk_context *ctx;
struct nk_glfw nkglfw = {0}; struct nk_glfw nkglfw = {0};
void editor_init(struct mSDLWindow *window) void editor_init(struct mSDLWindow *window)
@ -433,8 +433,13 @@ void editor_init(struct mSDLWindow *window)
fclose(feditor); fclose(feditor);
} }
nkctx = nk_glfw3_init(&nkglfw, window->window, NK_GLFW3_INSTALL_CALLBACKS); ctx = nk_glfw3_init(&nkglfw, window->window, NK_GLFW3_INSTALL_CALLBACKS);
//set_style(nkctx, THEME_WHITE);
struct nk_font_atlas *atlas;
nk_glfw3_font_stash_begin(&nkglfw, &atlas);
struct nk_font *droid = nk_font_atlas_add_from_file(atlas, "fonts/notosans.tff", 14, 0);
nk_glfw3_font_stash_end(&nkglfw);
glfwSetKeyCallback(window->window, edit_input_cb); glfwSetKeyCallback(window->window, edit_input_cb);
glfwSetMouseButtonCallback(window->window, edit_mouse_cb); glfwSetMouseButtonCallback(window->window, edit_mouse_cb);
@ -442,18 +447,18 @@ void editor_init(struct mSDLWindow *window)
void editor_input() void editor_input()
{ {
//io = &ImGui::GetIO();
} }
int editor_wantkeyboard() int editor_wantkeyboard()
{ {
/*
if (io == NULL) return 0;
return io->WantCaptureKeyboard;
*/
return 0; return 0;
} }
const int nuk_std = NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE;
const struct nk_rect nk_rect_std = {250, 250, 250, 250};
void editor_project_gui() void editor_project_gui()
{ {
/* Grid, etc */ /* Grid, etc */
@ -471,17 +476,55 @@ void editor_project_gui()
*/ */
} }
static char text[3][64];
static int text_len[3];
static const char *items[] = {"Item 0","item 1","item 2"};
static int selected_item = 0;
static int check = 1;
int i;
if (nk_begin(ctx, "Grid Demo", nk_rect(600, 350, 275, 250),
NK_WINDOW_TITLE|NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|
NK_WINDOW_NO_SCROLLBAR))
{
nk_layout_row_dynamic(ctx, 30, 2);
nk_label(ctx, "Floating point:", NK_TEXT_RIGHT);
nk_edit_string(ctx, NK_EDIT_FIELD, text[0], &text_len[0], 64, nk_filter_float);
nk_label(ctx, "Hexadecimal:", NK_TEXT_RIGHT);
nk_edit_string(ctx, NK_EDIT_FIELD, text[1], &text_len[1], 64, nk_filter_hex);
nk_label(ctx, "Binary:", NK_TEXT_RIGHT);
nk_edit_string(ctx, NK_EDIT_FIELD, text[2], &text_len[2], 64, nk_filter_binary);
nk_label(ctx, "Checkbox:", NK_TEXT_RIGHT);
nk_checkbox_label(ctx, "Check me", &check);
nk_label(ctx, "Combobox:", NK_TEXT_RIGHT);
if (nk_combo_begin_label(ctx, items[selected_item], nk_vec2(nk_widget_width(ctx), 200))) {
nk_layout_row_dynamic(ctx, 25, 1);
for (i = 0; i < 3; ++i)
if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT))
selected_item = i;
nk_combo_end(ctx);
}
}
nk_end(ctx);
if (nk_begin(ctx, "Menu Demo", nk_rect(600, 350, 275, 250), nuk_std)) {
nk_menubar_begin(ctx);
nk_layout_row_dynamic(ctx, 30, 4);
char bbbuf[256];
snprintf(bbbuf, 256, "Current level: %s", current_level[0] == '\0' ? "Level not saved!" : current_level);
nk_label(ctx, bbbuf, NK_TEXT_LEFT);
if (nk_menu_begin_text(ctx, "Windows", 7, NK_TEXT_LEFT, nk_vec2(100, 30))) {
nk_layout_row_dynamic(ctx, 30, 1);
if (nk_button_label(ctx, "Resources")) editor.showAssetMenu = !editor.showAssetMenu;
if (nk_button_label(ctx, "Hierarchy")) editor.showHierarchy = !editor.showHierarchy;
/* /*
if (ImGui::BeginMainMenuBar()) {
ImGui::Text("Current level: %s",
current_level[0] ==
'\0' ? "Level not saved!" : current_level);
if (ImGui::BeginMenu("Windows")) {
ImGui::MenuItem("Resources", "F2", &editor.showAssetMenu);
ImGui::MenuItem("Hierarchy", "F4", &editor.showHierarchy);
ImGui::MenuItem("Lighting", "F5", &editor.showLighting); ImGui::MenuItem("Lighting", "F5", &editor.showLighting);
ImGui::MenuItem("Game Settings", "F6", ImGui::MenuItem("Game Settings", "F6",
&editor.showGameSettings); &editor.showGameSettings);
@ -490,68 +533,67 @@ void editor_project_gui()
ImGui::MenuItem("Export", "F9", &editor.showExport); ImGui::MenuItem("Export", "F9", &editor.showExport);
ImGui::MenuItem("Level", "F10", &editor.showLevel); ImGui::MenuItem("Level", "F10", &editor.showLevel);
ImGui::MenuItem("REPL", "`", &editor.showREPL); ImGui::MenuItem("REPL", "`", &editor.showREPL);
ImGui::EndMenu();
*/
} }
if (ImGui::BeginMenu("Levels")) { if (nk_menu_begin_text(ctx, "Levels", 100, 0, nk_vec2(100, 50))) {
if (ImGui::Button("New")) {
if (nk_button_label(ctx, "New")) {
new_level(); new_level();
current_level[0] = '\0'; current_level[0] = '\0';
} }
if (nk_button_label(ctx, "Save")) {
if (ImGui::Button("Save")) {
save_level(current_level); save_level(current_level);
get_levels(); get_levels();
} }
if (ImGui::Button("Save as")) { if (nk_button_label(ctx, "Save as")) {
save_level(levelname); save_level(levelname);
strcpy(current_level, levelname); strcpy(current_level, levelname);
levelname[0] = '\0'; levelname[0] = '\0';
get_levels(); get_levels();
} }
ImGui::SameLine(); // ImGui::InputText("", levelname, MAXNAME);
ImGui::InputText("", levelname, MAXNAME);
vec_walk(levels, (void (*)(void *)) &editor_level_btn); vec_walk(levels, (void (*)(void *)) &editor_level_btn);
ImGui::EndMenu();
} }
ImGui::EndMainMenuBar(); nk_menubar_end(ctx);
}
nk_end(ctx);
if (editor.showExport && nk_begin(ctx, "Export and Bake", nk_rect_std, nuk_std)) {
if (nk_button_label(ctx, "Bake")) {
}
if (nk_button_label(ctx, "Build")) {
} }
if (editor.showExport) { nk_end(ctx);
ImGui::Begin("Export and Bake", &editor.showExport);
if (ImGui::Button("Bake")) {
}
if (ImGui::Button("Build")) {
}
ImGui::End();
} }
// Shadow map vars // Shadow map vars
if (editor.showLighting) { if (editor.showLighting && nk_begin(ctx, "Lighting options", nk_rect_std, nuk_std)) {
ImGui::Begin("Lighting options", &editor.showLighting); nk_layout_row_dynamic(ctx, 25, 1);
if (ImGui::CollapsingHeader("Directional shadow map")) { if (nk_combo_begin_text(ctx, "Directional shadow map", 50, nk_vec2(nk_widget_width(ctx), 400))) {
ImGui::SliderFloat("Near plane", &near_plane, -200.f, 200.f, nk_slider_float(ctx, -200.f, &near_plane, 200.f, 1.f);
NULL, 1.f); nk_slider_float(ctx, -200.f, &far_plane, 200.f, 1.f);
ImGui::SliderFloat("Far plane", &far_plane, -200.f, 200.f, nk_slider_float(ctx, 0.f, &shadowLookahead, 100.f, 1.f);
NULL, 1.f); nk_slider_float(ctx, 0.f, &plane_size, 100.f, 1.f);
ImGui::SliderFloat("Shadow Lookahead", &shadowLookahead, 0.f,
100.f, NULL, 1.f);
ImGui::SliderFloat("Plane size", &plane_size, 0.f, 100.f, NULL,
1.f);
} }
ImGui::End(); nk_end(ctx);
} }
/*
if (editor.showGameSettings) { if (editor.showGameSettings) {
ImGui::Begin("Game settings", &editor.showGameSettings); ImGui::Begin("Game settings", &editor.showGameSettings);
@ -775,13 +817,50 @@ void editor_render()
{ {
nk_glfw3_new_frame(&nkglfw); nk_glfw3_new_frame(&nkglfw);
struct nk_colorf bg;
bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f;
if (cur_project) if (cur_project)
editor_project_gui(); editor_project_gui();
else else
editor_proj_select_gui(); editor_proj_select_gui();
editor_project_gui();
if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
enum {EASY, HARD};
static int op = EASY;
static int property = 20;
nk_layout_row_static(ctx, 30, 80, 1);
if (nk_button_label(ctx, "button"))
fprintf(stdout, "button pressed\n");
nk_layout_row_dynamic(ctx, 30, 2);
if (nk_option_label(ctx, "easy", op == EASY)) op = EASY;
if (nk_option_label(ctx, "hard", op == HARD)) op = HARD;
nk_layout_row_dynamic(ctx, 25, 1);
nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1);
nk_layout_row_dynamic(ctx, 20, 1);
nk_label(ctx, "background:", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 25, 1);
if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) {
nk_layout_row_dynamic(ctx, 120, 1);
bg = nk_color_picker(ctx, bg, NK_RGBA);
nk_layout_row_dynamic(ctx, 25, 1);
bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f);
bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f);
bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f);
bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f);
nk_combo_end(ctx);
}
}
nk_end(ctx);
nk_end(nkctx);
nk_glfw3_render(&nkglfw, NK_ANTI_ALIASING_ON, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER); nk_glfw3_render(&nkglfw, NK_ANTI_ALIASING_ON, MAX_VERTEX_BUFFER, MAX_ELEMENT_BUFFER);
} }
@ -812,12 +891,12 @@ int is_allowed_extension(const char *ext)
void editor_level_btn(char *level) void editor_level_btn(char *level)
{ {
/*
if (ImGui::Button(level)) { if (nk_button_label(ctx, level)) {
load_level(level); load_level(level);
strcpy(current_level, level); strcpy(current_level, level);
} }
*/
} }
void editor_selectasset(struct fileasset *asset) void editor_selectasset(struct fileasset *asset)

View file

@ -105,9 +105,9 @@ void openglInit()
debugdraw_init(); debugdraw_init();
stdFont = MakeFont("notosans.ttf", 300); //stdFont = MakeFont("notosans.ttf", 300);
text_settype(stdFont); //text_settype(stdFont);
//glEnable(GL_STENCIL_TEST); //glEnable(GL_STENCIL_TEST);
glClearColor(editorClearColor[0], editorClearColor[1], glClearColor(editorClearColor[0], editorClearColor[1],