Skip to content

Commit a6b31dc

Browse files
Merge pull request #31 from RSGL/main
update web examples
2 parents c2bf9ab + 476f4c2 commit a6b31dc

File tree

6 files changed

+59
-105
lines changed

6 files changed

+59
-105
lines changed

examples/Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ else ifeq ($(CC),emcc)
6060
LINK_GL1 = -s LEGACY_GL_EMULATION -D LEGACY_GL_EMULATION -sGL_UNSAFE_OPTS=0
6161
LINK_GL3 = -s FULL_ES3
6262
LINK_GL2 = -s FULL_ES2
63-
# --preload-file [email protected]
64-
PRELOAD = --embed-file logo.png
63+
PRELOAD = --embed-file logo.png --embed-file COMICSANS.ttf
6564
EXPORTED_JS = $(PRELOAD) -s EXPORTED_RUNTIME_METHODS="['stringToNewUTF8']"
6665
LIBS = -s WASM=1 -s ASYNCIFY -s GL_SUPPORT_EXPLICIT_SWAP_CONTROL=1 $(EXPORTED_JS)
6766
EXT = .js

examples/advanced/shader.c

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
this example is designed for Opengl 3.3 GLSL shaders
1414
*/
1515

16+
#ifndef __EMSCRIPTEN__
1617
static const char* MY_VShaderCode = RSGL_MULTILINE_STR(
1718
\x23version 330 \n
1819
in vec3 vertexPosition; \n
@@ -26,7 +27,6 @@ static const char* MY_VShaderCode = RSGL_MULTILINE_STR(
2627
uniform mat4 pv; \n
2728

2829
uniform vec2 u_mouse;
29-
uniform vec2 u_resolution;
3030

3131
void main() {
3232
fragTexCoord = vertexTexCoord;
@@ -45,8 +45,56 @@ static const char* MY_FShaderCode = RSGL_MULTILINE_STR(
4545
uniform float u_time;
4646

4747
uniform vec2 pos;
48+
49+
precision mediump float;
50+
vec2 pitch = vec2(50., 50.);
51+
52+
void main() {
53+
vec2 uv = gl_FragCoord.xy / u_resolution.xy;
54+
vec3 color = 0.5 + 0.5 * cos(u_time + uv.xyx + vec3(0, 2, 4));
55+
56+
if (mod(gl_FragCoord.x, pitch[0]) < 1. ||
57+
mod(gl_FragCoord.y, pitch[1]) < 1.) {
58+
gl_FragColor = vec4(color, 1.0);
59+
} else {
60+
gl_FragColor = vec4(0, 0, 0, 1);
61+
}
62+
}
63+
);
64+
#else
65+
static const char* MY_VShaderCode = RSGL_MULTILINE_STR(
66+
\x23version 100 \n
67+
attribute vec3 vertexPosition; \n
68+
attribute vec2 vertexTexCoord; \n
69+
attribute vec4 vertexColor; \n
70+
varying vec2 fragTexCoord; \n
71+
varying vec4 fragColor; \n
72+
varying vec4 position; \n
73+
74+
uniform mat4 model; \n
75+
uniform mat4 pv; \n
76+
4877
uniform vec2 u_mouse;
4978

79+
void main() {
80+
fragTexCoord = vertexTexCoord;
81+
fragColor = vertexColor;
82+
gl_Position = model * pv * (vec4(vertexPosition, 1.0) + vec4(u_mouse.x, u_mouse.y, 0, 0));
83+
position = gl_Position;
84+
}
85+
);
86+
87+
static const char* MY_FShaderCode = RSGL_MULTILINE_STR(
88+
\x23version 100 \n
89+
precision mediump float; \n
90+
91+
varying vec4 FragColor;
92+
93+
uniform vec2 u_resolution;
94+
uniform float u_time;
95+
96+
uniform vec2 pos;
97+
5098
precision mediump float;
5199
vec2 pitch = vec2(50., 50.);
52100

@@ -62,6 +110,7 @@ static const char* MY_FShaderCode = RSGL_MULTILINE_STR(
62110
}
63111
}
64112
);
113+
#endif
65114

66115
int main(void) {
67116
RGFW_glHints* hints = RGFW_getGlobalHints_OpenGL();

index.html

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
height: 100px;
5353
background: #555;
5454
}
55-
55+
5656
.header h1 {
5757
position: relative;
5858
top: 18px;
@@ -61,8 +61,8 @@
6161
</style>
6262
</head>
6363
<body style="background-color:rgb(15, 25, 45);">
64-
65-
64+
65+
6666
<div class="header">
6767
<img src="RSGL_logo.png" alt="RSGL logo">
6868
</div>
@@ -84,8 +84,8 @@ <h2>Shapes</h2>
8484
</a>
8585

8686

87-
<a href="./webasm/basics_text.html" class="link-card">
88-
<img src="webasm/basics_text.png" alt="Text Example">
87+
<a href="./webasm/basics_rfont.html" class="link-card">
88+
<img src="webasm/basics_rfont.png" alt="RFont Example">
8989
<h2>Text</h2>
9090
</a>
9191

@@ -98,11 +98,6 @@ <h2>Textures</h2>
9898
<img src="webasm/advanced_shader.png" alt="Shader Example">
9999
<h2>Shader</h2>
100100
</a>
101-
102-
<a href="./webasm/advanced_rsoft.html" class="link-card">
103-
<img src="webasm/advanced_rsoft.png" alt="RSoft Example">
104-
<h2>RSoft</h2>
105-
</a>
106101
</div>
107102
</body>
108103
</html>

webasm/advanced_rsoft.html

Lines changed: 0 additions & 89 deletions
This file was deleted.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
<div class="header">
5252
<a href="../index.html"> <img src="../RSGL_logo.png" alt="RSGL logo"> </a>
5353
<h1>RSGL WebASM Example &nbsp;&nbsp;&nbsp;&nbsp;
54-
55-
<a href="https://github.com/ColleagueRiley/RSGL/blob/main/examples/basics/text.c">Source Code</h4> </a>
54+
55+
<a href="https://github.com/ColleagueRiley/RSGL/blob/main/examples/basics/rfont.c">Source Code</h4> </a>
5656

5757
</h1>
5858
</div>
@@ -64,7 +64,7 @@ <h1>RSGL WebASM Example &nbsp;&nbsp;&nbsp;&nbsp;
6464
</div>
6565

6666

67-
<script src="../examples/basics/text.js"> </script>
67+
<script src="../examples/basics/rfont.js"> </script>
6868

6969
<div id="log"></div>
7070

0 commit comments

Comments
 (0)