Skip to content

Commit f10dee0

Browse files
committed
2024.4
new: integrated PBR renderer (@zpl-zak) new: --nocook (@zpl-zak) new: 3rd_luaffi.h new: add shadertoy material in demos (@zpl-zak) new: add update command (PLUG.bat) new: added skybox_pbr() method to load IBL maps (@zpl-zak) new: animlist() (@zpl-zak) new: camera_fps2() (@zpl-zak) new: font_wrap(), font_clip(), font_scale(), FONT_JUSTIFY (@zpl-zak) new: fx_order() support (@zpl-zak) new: implemented shader uniform caching (@zpl-zak) new: object_anim() (@zpl-zak) new: TEXTURE_ANISOTROPY, MODEL_NO_FILTERING flags (@zpl-zak) new: window_has_debug() + window_debug() to show/hide debug UI (@zpl-zak) chg: add @filelists support (PLUG.bat) chg: compute brdf lut (@zpl-zak) chg: COOK_DISABLED > ENABLE_COOK chg: COOK_INI_PATHFILE chg: do not use openmp in retail builds chg: improved shader preprocessing logic (@zpl-zak) chg: made --cook-on-demand=1 by default chg: move PLUG.bat into plugins/ folder chg: move tonemap shaders to engine art/ dir (@zpl-zak) chg: moved font shaders to art/ folder (@zpl-zak) chg: promoted allocate_texture_unit() to public texture_unit() method (@zpl-zak) chg: remove iqm macros (@zpl-zak) chg: renderers are renderstate_t driven now (@zpl-zak) chg: script push/pop methods chg: update gamecontrollerdb.txt chg: update roadmap chg: updated docs chg: upgrade enet (@zpl-zak) chg: upgrade font demo (@zpl-zak) fix: expired discord invite link (@rubenrookd) fix: fix compilation error in demos/physics/ samples fix: fixed broken luajit+python bindings since objv2 api fix: font align adjustments (@zpl-zak) fix: handled restartappifneeded steam case (@zpl-zak) fix: linux compilation (_alloca symbol) fix: set viewport while rendering shadertoys on a texture (@zpl-zak) fix: steam init ordering (demos/99-steam.c) (@zpl-zak) fix: texture units are now cycled each bind (prevents texture unit exhaustion) (@zpl-zak) fix: tweak sphere_to_polar() shader function (@zpl-zak) fix: ubuntu16+gcc compilation error fix: updated glfw3 swap buffer and interval funcs to match upstream (improves pacing) (@zpl-zak) fix: win32 guards within Steam code (@zpl-zak) fix: win32 timing in fps_timing_thread by replacing Sleep() call with sleep_ns() (uses WaitableTimer instead) (@zpl-zak) fix: wrong normals when rendering instanced models (@zpl-zak) lab: PLUG manager
1 parent ed7365c commit f10dee0

File tree

2,179 files changed

+2357240
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,179 files changed

+2357240
-0
lines changed

2024.4/MAKE.bat

Lines changed: 913 additions & 0 deletions
Large diffs are not rendered by default.

2024.4/README.md

Lines changed: 414 additions & 0 deletions
Large diffs are not rendered by default.

2024.4/demos/00-loop.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "fwk.h" // Minimal C sample
2+
3+
int main() {
4+
window_create(75.0, 0); // 75% size, no extra flags
5+
6+
while( window_swap() && !input(KEY_ESC) ) { // game loop
7+
puts("hello FWK from C!");
8+
}
9+
}

2024.4/demos/00-script.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "fwk.h"
2+
3+
#define SCRIPT(...) #__VA_ARGS__
4+
5+
#if 0 // teal
6+
script_run("local tl=require(\"tl\")\ntl.loader()");
7+
script_run("addsub = require(\"s2\"); print (addsub.add(10, 20))");
8+
s2.tl:
9+
local function add(a: number, b: number): number
10+
return a + b
11+
end
12+
local s = add(1,2)
13+
print(s)
14+
#endif
15+
16+
int main() {
17+
script_init();
18+
19+
script_run(SCRIPT(
20+
window_create(75.0,0);
21+
while window_swap() do
22+
ddraw_grid(10);
23+
if ui_panel("Hello from Lua!", 0) then
24+
ui_panel_end();
25+
end;
26+
end;
27+
));
28+
29+
// script test (lua)
30+
script_run( "-- Bye.lua\nio.write(\"script test: Bye world!, from \", _VERSION, \"\\n\")" );
31+
}

2024.4/demos/01-demo2d.c

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
// 2d demo: window, audio, camera, font, tiled, render, fx, spritesheet, input, ui. @todo: spine
2+
// - rlyeh, public domain.
3+
//
4+
// Compile with:
5+
// `make demos\01-demo2d.c` (windows)
6+
// `sh MAKE.bat demos/01-demo2d.c` (linux, osx)
7+
8+
#include "fwk.h"
9+
10+
void demo_kids(vec3 offs) {
11+
// init
12+
static texture_t kids; do_once kids = texture( "spriteSheetExample.png", TEXTURE_LINEAR );
13+
static vec3 pos[2] = {{490,362},{442,362}}, vel[2] = {0};
14+
static int row[2] = {0,3}, frame[2] = {0};
15+
static int inputs[2][4] = {{KEY_W,KEY_A,KEY_S,KEY_D},{KEY_UP,KEY_LEFT,KEY_DOWN,KEY_RIGHT}};
16+
17+
// move
18+
for( int i = 0; i < countof(pos); ++i ) {
19+
vel[i].x = input(inputs[i][3]) - input(inputs[i][1]);
20+
vel[i].y = input(inputs[i][2]) - input(inputs[i][0]);
21+
pos[i].x = fmod(pos[i].x + vel[i].x, window_width() + 128);
22+
pos[i].y = fmod(pos[i].y + vel[i].y, window_height() + 128);
23+
frame[i] += vel[i].x || vel[i].y;
24+
}
25+
26+
// render
27+
for( int i = 0; i < countof(pos); ++i ) {
28+
int col = frame[i] / 10, num_frame = row[i] * 4 + col % 4; // 4x4 tilesheet
29+
float position[3] = {pos[i].x,pos[i].y,pos[i].y}, offset[2]={0,0}, scale[2]={0.5,0.5};
30+
float spritesheet[3]={num_frame,4,4};
31+
sprite_sheet(kids,
32+
spritesheet, // num_frame in a 4x4 spritesheet
33+
position, 0, // position(x,y,depth:sort-by-Y), angle
34+
offset, scale, // offset(x,y), scale(x,y)
35+
WHITE, 0 // tint_color, no flags
36+
);
37+
}
38+
}
39+
40+
void demo_hud() {
41+
// draw pixel-art hud, 16x16 ui element, scaled and positioned in resolution-independant way
42+
static texture_t inputs; do_once inputs = texture( "prompts_tilemap_34x24_16x16x1.png", TEXTURE_LINEAR );
43+
float spritesheet[3] = {17,34,24}, offset[2] = {0, - 2*absf(sin(window_time()*5))}; // sprite cell and animation
44+
float scale[2] = {3, 3}, tile_w = 16 * scale[0], tile_h = 16 * scale[1]; // scaling
45+
float position[3] = {window_width() - tile_w, window_height() - tile_h, window_height() }; // position in screen-coordinates (x,y,z-index)
46+
sprite_sheet(inputs, spritesheet, position, 0/*deg*/, offset, scale, WHITE, SPRITE_RESOLUTION_INDEPENDANT);
47+
}
48+
49+
int main() {
50+
// window (80% sized, MSAA x4 flag)
51+
window_create(80.0, WINDOW_MSAA4);
52+
window_title(__FILE__);
53+
54+
// tiled map
55+
tiled_t tmx = tiled(vfs_read("castle.tmx"));
56+
// tmx.parallax = true;
57+
58+
// spine model
59+
//spine_t *spn = spine("goblins.json", "goblins.atlas", 0);
60+
61+
// camera 2d
62+
camera_t cam = camera();
63+
cam.position = vec3(window_width()/2, window_height()/2, 3); // at(CX,CY) zoom(x3)
64+
camera_enable(&cam);
65+
66+
// audio (both clips & streams)
67+
audio_t clip1 = audio_clip( "coin.wav" );
68+
audio_t clip2 = audio_clip( "pew.sfxr" );
69+
audio_t stream1 = audio_stream( "larry.mid" );
70+
audio_t stream2 = audio_stream( "waterworld-map.fur" );
71+
audio_t BGM = stream1;
72+
audio_play(BGM, 0);
73+
74+
// font config: faces (6 max) and colors (10 max)
75+
#define FONT_CJK FONT_FACE3
76+
#define FONT_YELLOW FONT_COLOR2
77+
#define FONT_LIME FONT_COLOR3
78+
font_face(FONT_CJK, "mplus-1p-medium.ttf", 48.f, FONT_JP|FONT_2048); // CJK|FONT_2048|FONT_OVERSAMPLE_Y);
79+
font_color(FONT_YELLOW, RGB4(255,255,0,255));
80+
font_color(FONT_LIME, RGB4(128,255,0,255));
81+
82+
// fx: load all post fx files in all subdirs. enable a few filters by default
83+
fx_load("fx**.fs");
84+
fx_enable(fx_find("fxCRT2.fs"), 1);
85+
fx_enable(fx_find("fxGrain.fs"), 1);
86+
fx_enable(fx_find("fxContrast.fs"), 1);
87+
fx_enable(fx_find("fxVignette.fs"), 1);
88+
89+
// sort them
90+
fx_order(fx_find("fxCRT2.fs"), 0);
91+
fx_order(fx_find("fxGrain.fs"), 1);
92+
fx_order(fx_find("fxContrast.fs"), 2);
93+
fx_order(fx_find("fxVignette.fs"), 3);
94+
95+
// demo loop
96+
while (window_swap() && !input_down(KEY_ESC)) {
97+
98+
// handle input
99+
if( input_down(KEY_F5) ) window_reload();
100+
if( input_down(KEY_F11) ) window_fullscreen( !window_has_fullscreen() );
101+
102+
// camera panning (x,y) & zooming (z)
103+
if( !ui_hover() && !ui_active() ) {
104+
if( input(MOUSE_L) ) cam.position.x += input_diff(MOUSE_X);
105+
if( input(MOUSE_L) ) cam.position.y += input_diff(MOUSE_Y);
106+
cam.position.z += input_diff(MOUSE_W) * 0.1;
107+
}
108+
109+
// apply post-fxs from here
110+
fx_begin();
111+
112+
profile("Rendering") {
113+
vec3 center = add3(cam.position,vec3(-window_width()/1,-window_height()/2,0));
114+
// render tiled map
115+
tiled_render(tmx, center);
116+
//
117+
demo_kids(vec3(0,0,1));
118+
demo_hud();
119+
// render spine model
120+
// spine_animate(spn, !window_has_pause() * window_delta());
121+
// spine_render(spn, vec3(cam.position.x, cam.position.y, 1), true );
122+
// sprite_flush();
123+
}
124+
125+
// subtitle sample
126+
font_print(
127+
FONT_BOTTOM FONT_CENTER
128+
FONT_CJK FONT_H1
129+
FONT_YELLOW "私はガラスを食べられます。" FONT_LIME "それは私を傷つけません。\n"
130+
);
131+
132+
// post-fxs end here
133+
fx_end();
134+
135+
// ui
136+
if( ui_panel("Audio", 0)) {
137+
if( ui_label2_toolbar("BGM: Track #1", ICON_MD_VOLUME_UP)) audio_stop(BGM), audio_play(BGM = stream1, AUDIO_SINGLE_INSTANCE);
138+
if( ui_label2_toolbar("BGM: Track #2", ICON_MD_VOLUME_UP)) audio_stop(BGM), audio_play(BGM = stream2, AUDIO_SINGLE_INSTANCE);
139+
if( ui_label2_toolbar("SFX: Coin", ICON_MD_VOLUME_UP)) audio_play(clip1, 0);
140+
if( ui_label2_toolbar("SFX: Pew", ICON_MD_VOLUME_UP)) audio_play(clip2, 0);
141+
ui_panel_end();
142+
}
143+
if( ui_panel("Tiled", 0)) {
144+
ui_float("Zoom in", &cam.position.z);
145+
ui_tiled(&tmx);
146+
ui_panel_end();
147+
}
148+
/*if( ui_panel("Spine", 0)) {
149+
ui_spine(spn);
150+
ui_panel_end();
151+
}*/
152+
}
153+
}
154+
155+
// this demo supersedes following old sources:
156+
// https://github.com/r-lyeh/FWK/blob/45e34d7890b2b8fe1f4994f4b76e496280d83cb6/demos/00-audio.c
157+
// https://github.com/r-lyeh/FWK/blob/45e34d7890b2b8fe1f4994f4b76e496280d83cb6/demos/00-font.c
158+
// https://github.com/r-lyeh/FWK/blob/45e34d7890b2b8fe1f4994f4b76e496280d83cb6/demos/00-spine.c
159+
// https://github.com/r-lyeh/FWK/blob/45e34d7890b2b8fe1f4994f4b76e496280d83cb6/demos/00-sprite.c
160+
// https://github.com/r-lyeh/FWK/blob/45e34d7890b2b8fe1f4994f4b76e496280d83cb6/demos/00-tiled.c
161+
// https://github.com/r-lyeh/FWK/blob/45e34d7890b2b8fe1f4994f4b76e496280d83cb6/demos/00-tilemap.c

2024.4/demos/01-easing.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#include "fwk.h"
2+
3+
struct {
4+
float (*ease)(float);
5+
const char *name;
6+
} easings[] = {
7+
{ease_zero, "ease_zero"},
8+
{ease_one, "ease_one"},
9+
{ease_linear, "ease_linear"},
10+
{ease_out_sine, "ease_out_sine"},
11+
{ease_out_quad, "ease_out_quad"},
12+
{ease_out_cubic, "ease_out_cubic"},
13+
{ease_out_quart, "ease_out_quart"},
14+
{ease_out_quint, "ease_out_quint"},
15+
{ease_out_expo, "ease_out_expo"},
16+
{ease_out_circ, "ease_out_circ"},
17+
{ease_out_back, "ease_out_back"},
18+
{ease_out_elastic, "ease_out_elastic"},
19+
{ease_out_bounce, "ease_out_bounce"},
20+
{ease_in_sine, "ease_in_sine"},
21+
{ease_in_quad, "ease_in_quad"},
22+
{ease_in_cubic, "ease_in_cubic"},
23+
{ease_in_quart, "ease_in_quart"},
24+
{ease_in_quint, "ease_in_quint"},
25+
{ease_in_expo, "ease_in_expo"},
26+
{ease_in_circ, "ease_in_circ"},
27+
{ease_in_back, "ease_in_back"},
28+
{ease_in_elastic, "ease_in_elastic"},
29+
{ease_in_bounce, "ease_in_bounce"},
30+
{ease_inout_sine, "ease_inout_sine"},
31+
{ease_inout_quad, "ease_inout_quad"},
32+
{ease_inout_cubic, "ease_inout_cubic"},
33+
{ease_inout_quart, "ease_inout_quart"},
34+
{ease_inout_quint, "ease_inout_quint"},
35+
{ease_inout_expo, "ease_inout_expo"},
36+
{ease_inout_circ, "ease_inout_circ"},
37+
{ease_inout_back, "ease_inout_back"},
38+
{ease_inout_elastic, "ease_inout_elastic"},
39+
{ease_inout_bounce, "ease_inout_bounce"},
40+
{ease_inout_perlin, "ease_inout_perlin"},
41+
};
42+
43+
int main() {
44+
window_create(0.75, WINDOW_SQUARE);
45+
while(window_swap()) {
46+
static double timer = 0; timer = fmod(timer+window_delta(), 2); // loops every 2s
47+
48+
static int open = 1;
49+
if( ui_window("ease", &open) ) {
50+
float linear_delta = timer / 2.f; // delta is [0..1]
51+
for( int i = 0; i < countof(easings); ++i) {
52+
float nonlinear_delta = easings[i].ease(linear_delta);
53+
// visualize
54+
ui_slider( easings[i].name, &nonlinear_delta );
55+
}
56+
ui_window_end();
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)