aboutsummaryrefslogtreecommitdiff
path: root/examples/text
diff options
context:
space:
mode:
authorRay <raysan5@gmail.com>2019-05-17 01:17:40 +0200
committerRay <raysan5@gmail.com>2019-05-17 01:17:40 +0200
commit970f1e8ff15424ca2d96d89bf2871f0246835e9b (patch)
treebc093a8eaee29739e52642c233d0f9102e9db7cf /examples/text
parentce87d2ced4dbe60f97d3ed48635231c222482b18 (diff)
downloadraylib-970f1e8ff15424ca2d96d89bf2871f0246835e9b.tar.gz
raylib-970f1e8ff15424ca2d96d89bf2871f0246835e9b.zip
examples review
Diffstat (limited to 'examples/text')
-rw-r--r--examples/text/resources/emoji.fnt2
-rw-r--r--examples/text/resources/emoji.png (renamed from examples/text/resources/emoji_0.png)bin244961 -> 244961 bytes
-rw-r--r--examples/text/resources/notoCJK.fnt2
-rw-r--r--examples/text/resources/notoCJK.png (renamed from examples/text/resources/notoCJK_0.png)bin92202 -> 92202 bytes
-rw-r--r--examples/text/resources/shaders/glsl100/sdf.fs23
-rw-r--r--examples/text/resources/shaders/glsl330/sdf.fs (renamed from examples/text/resources/shaders/sdf.fs)0
-rw-r--r--examples/text/text_font_sdf.c8
-rw-r--r--examples/text/text_unicode.c2
8 files changed, 33 insertions, 4 deletions
diff --git a/examples/text/resources/emoji.fnt b/examples/text/resources/emoji.fnt
index cabbdf6c..85c71968 100644
--- a/examples/text/resources/emoji.fnt
+++ b/examples/text/resources/emoji.fnt
@@ -1,6 +1,6 @@
info face="Symbola" size=-64 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=2,2 outline=2
common lineHeight=81 base=59 scaleW=1024 scaleH=1024 pages=1 packed=0 alphaChnl=0 redChnl=4 greenChnl=4 blueChnl=4
-page id=0 file="emoji_0.png"
+page id=0 file="emoji.png"
chars count=187
char id=9749 x=135 y=333 width=63 height=61 xoffset=1 yoffset=9 xadvance=65 page=0 chnl=15
char id=9752 x=366 y=396 width=57 height=59 xoffset=0 yoffset=10 xadvance=58 page=0 chnl=15
diff --git a/examples/text/resources/emoji_0.png b/examples/text/resources/emoji.png
index 82e36983..82e36983 100644
--- a/examples/text/resources/emoji_0.png
+++ b/examples/text/resources/emoji.png
Binary files differ
diff --git a/examples/text/resources/notoCJK.fnt b/examples/text/resources/notoCJK.fnt
index 235ee771..2edfb61e 100644
--- a/examples/text/resources/notoCJK.fnt
+++ b/examples/text/resources/notoCJK.fnt
@@ -1,6 +1,6 @@
info face="Noto Serif CJK JP" size=-16 bold=0 italic=0 charset="" unicode=1 stretchH=100 smooth=1 aa=1 padding=0,0,0,0 spacing=2,2 outline=1
common lineHeight=23 base=18 scaleW=512 scaleH=512 pages=1 packed=0 alphaChnl=0 redChnl=4 greenChnl=4 blueChnl=4
-page id=0 file="notoCJK_0.png"
+page id=0 file="notoCJK.png"
chars count=576
char id=32 x=507 y=185 width=3 height=3 xoffset=-1 yoffset=-1 xadvance=4 page=0 chnl=15
char id=33 x=449 y=285 width=5 height=14 xoffset=0 yoffset=5 xadvance=5 page=0 chnl=15
diff --git a/examples/text/resources/notoCJK_0.png b/examples/text/resources/notoCJK.png
index 4f5cd4b8..4f5cd4b8 100644
--- a/examples/text/resources/notoCJK_0.png
+++ b/examples/text/resources/notoCJK.png
Binary files differ
diff --git a/examples/text/resources/shaders/glsl100/sdf.fs b/examples/text/resources/shaders/glsl100/sdf.fs
new file mode 100644
index 00000000..b4214d92
--- /dev/null
+++ b/examples/text/resources/shaders/glsl100/sdf.fs
@@ -0,0 +1,23 @@
+#version 100
+
+// Input vertex attributes (from vertex shader)
+varying vec2 fragTexCoord;
+varying vec4 fragColor;
+
+// Input uniform values
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+// NOTE: Add here your custom variables
+const float smoothing = 1.0/16.0;
+
+void main()
+{
+ // Texel color fetching from texture sampler
+ // NOTE: Calculate alpha using signed distance field (SDF)
+ float distance = texture2D(texture0, fragTexCoord).a;
+ float alpha = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance);
+
+ // Calculate final fragment color
+ gl_FragColor = vec4(fragColor.rgb, fragColor.a*alpha);
+}
diff --git a/examples/text/resources/shaders/sdf.fs b/examples/text/resources/shaders/glsl330/sdf.fs
index 44d33e9b..44d33e9b 100644
--- a/examples/text/resources/shaders/sdf.fs
+++ b/examples/text/resources/shaders/glsl330/sdf.fs
diff --git a/examples/text/text_font_sdf.c b/examples/text/text_font_sdf.c
index 755b642d..69cff471 100644
--- a/examples/text/text_font_sdf.c
+++ b/examples/text/text_font_sdf.c
@@ -11,6 +11,12 @@
#include "raylib.h"
+#if defined(PLATFORM_DESKTOP)
+ #define GLSL_VERSION 330
+#else // PLATFORM_RPI, PLATFORM_ANDROID, PLATFORM_WEB
+ #define GLSL_VERSION 100
+#endif
+
int main()
{
// Initialization
@@ -47,7 +53,7 @@ int main()
UnloadImage(atlas);
// Load SDF required shader (we use default vertex shader)
- Shader shader = LoadShader(0, "resources/shaders/sdf.fs");
+ Shader shader = LoadShader(0, FormatText("resources/shaders/glsl%i/sdf.fs", GLSL_VERSION));
SetTextureFilter(fontSDF.texture, FILTER_BILINEAR); // Required for SDF font
Vector2 fontPosition = { 40, screenHeight/2 - 50 };
diff --git a/examples/text/text_unicode.c b/examples/text/text_unicode.c
index 6b456a75..f3c2612c 100644
--- a/examples/text/text_unicode.c
+++ b/examples/text/text_unicode.c
@@ -156,7 +156,7 @@ int main(int argc, char **argv)
const int screenHeight = 450;
SetConfigFlags(FLAG_MSAA_4X_HINT | FLAG_VSYNC_HINT);
- InitWindow(screenWidth, screenHeight, "raylib - unicode test");
+ InitWindow(screenWidth, screenHeight, "raylib [text] example - unicode");
// Load the font resources
// NOTE: fontAsian is for asian languages,