update demos

main
Dominik Madarász 2023-12-10 17:08:22 +01:00
parent 3008fb5b65
commit eebe5238f6
8 changed files with 195 additions and 30 deletions

View File

@ -29,9 +29,9 @@ void demo_kids(vec3 offs) {
float position[3] = {pos[i].x,pos[i].y,pos[i].y}, offset[2]={0,0}, scale[2]={0.5,0.5}; float position[3] = {pos[i].x,pos[i].y,pos[i].y}, offset[2]={0,0}, scale[2]={0.5,0.5};
float spritesheet[3]={num_frame,4,4}; float spritesheet[3]={num_frame,4,4};
sprite_sheet(kids, sprite_sheet(kids,
spritesheet, // num_frame in a 4x4 spritesheet spritesheet, // num_frame in a 4x4 spritesheet
position, 0, // position(x,y,depth:sort-by-Y), angle position, 0, // position(x,y,depth:sort-by-Y), angle
offset, scale, // offset(x,y), scale(x,y) offset, scale, // offset(x,y), scale(x,y)
WHITE, 0 // tint_color, no flags WHITE, 0 // tint_color, no flags
); );
} }

View File

@ -5,7 +5,7 @@ int main() {
window_create(25, WINDOW_SQUARE); window_create(25, WINDOW_SQUARE);
window_title(__FILE__); window_title(__FILE__);
unsigned program = shader_geom(vfs_read("shaders/geom-test/line.glsl"), vfs_read("shaders/geom-test/line-vs.glsl"), vfs_read("shaders/geom-test/line-fs.glsl"), "aPos", "FragColor", NULL ); unsigned program = shader_geom(vfs_read("shaders/geom-test/line.glsl"), vfs_read("shaders/geom-test/line-vs.glsl"), vfs_read("shaders/geom-test/line-fs.glsl"), "aPos", "FragColor", NULL);
float points[] = { float points[] = {
-0.5f, 0.5f, // top-left -0.5f, 0.5f, // top-left

59
demos/99-gizmo.c 100644
View File

@ -0,0 +1,59 @@
#include "v4k.h"
void gizmo2(float *pos, float *rot, float *sca, float *pivot) {
vec3 p = ptr3(pos);
vec3 r = ptr3(rot);
vec3 s = ptr3(sca);
gizmo(&p, &r, &s);
if(pivot) compose44(pivot, p, eulerq(r), s);
memcpy(pos, &p, sizeof(p));
memcpy(rot, &r, sizeof(r));
memcpy(sca, &s, sizeof(s));
}
int main() {
argvadd("--cook-on-demand");
window_create(0.75, 0);
// setup cam
camera_t cam = camera();
cam.fov = 60;
cam.position = vec3(10,10,10);
camera_enable(&cam);
while( window_swap() ) {
// fps camera
bool active = ui_active() || ui_hover() || gizmo_active() ? false : input(MOUSE_L) || input(MOUSE_M) || input(MOUSE_R);
if( active ) cam.speed = clampf(cam.speed + input_diff(MOUSE_W) / 10, 0.05f, 5.0f);
vec2 mouse = scale2(vec2(input_diff(MOUSE_X), -input_diff(MOUSE_Y)), 0.2f * active);
vec3 wasdecq = scale3(vec3(input(KEY_D)-input(KEY_A),input(KEY_E)-(input(KEY_C)||input(KEY_Q)),input(KEY_W)-input(KEY_S)), cam.speed);
camera_moveby(&cam, wasdecq);
camera_fps(&cam, mouse.x,mouse.y);
window_cursor( !active );
static vec3 min = {0,0,0}, max = {1,1,1};
ddraw_aabb( min, max );
ddraw_ground(0);
ddraw_flush();
static model_t mdl;
do_once mdl = model("meshes/gizmo.fbx", 0);
shader_bind(mdl.program);
vec3 color = {0,0,0};
vec3 coeff[9] = { color,color,color,color,color,color,color,color,color, };
shader_vec3v("u_coefficients_sh", 9, coeff);
shader_int("u_textured", false);
model_render(mdl, cam.proj, cam.view, mdl.pivot, 0);
static mat44 pivot = {0};
static int do_showgizmo = 1;
if( do_showgizmo ) {
static vec3 p = {0,0,0}, r = {0,-90,0}, s = {1,1,1};
gizmo2(&p.x, &r.x, &s.x, mdl.pivot);
}
// debug
font_print(va(FONT_RIGHT "%d(%d)", gizmo_active(), gizmo_hover()));
}
}

View File

@ -1,10 +1,10 @@
#include "v4k.h" #include "v4k.h"
int main() { int main() {
window_create(65.0, 0 ); window_create(75.0, 0 );
gui_pushskin(gui_skinned("golden.ase", 4.0f)); gui_pushskin(gui_skinned("golden.ase", 3.0f)); // x3 scale
skinned_t *skinned = C_CAST(skinned_t*, gui_userdata()); skinned_t *skinned = (skinned_t*)gui_userdata();
vec4 pos = vec4(400,400,100, 30); vec4 pos = vec4(400,400,100, 30);
@ -12,8 +12,7 @@ int main() {
float testval2=7.5f; float testval2=7.5f;
while( window_swap() && !input(KEY_ESC) ) { // game loop while( window_swap() && !input(KEY_ESC) ) { // game loop
vec4 panel_pos = vec4(0, 0, window_width(), window_height());
if (ui_panel("Atlas", 0)) { if (ui_panel("Atlas", 0)) {
ui_atlas(&skinned->atlas); ui_atlas(&skinned->atlas);
ui_panel_end(); ui_panel_end();
@ -25,6 +24,12 @@ int main() {
ui_panel_end(); ui_panel_end();
} }
if (ui_panel("Fonts", 0)) {
ui_font();
ui_panel_end();
}
if (input_down(MOUSE_R)) { if (input_down(MOUSE_R)) {
pos.x = input(MOUSE_X); pos.x = input(MOUSE_X);
pos.y = input(MOUSE_Y); pos.y = input(MOUSE_Y);
@ -34,26 +39,37 @@ int main() {
pos.w = input(MOUSE_Y)-pos.y; pos.w = input(MOUSE_Y)-pos.y;
} }
// // font
do_once font_face(FONT_FACE2, "lilita_one_regular.ttf", 48.0f, FONT_EU | FONT_2048);
do_once font_color(FONT_COLOR9, WHITE);
font_print(va(FONT_MIDDLE FONT_CENTER FONT_FACE2 FONT_COLOR9 "%s", "Hello"));
// background
vec4 panel_pos = vec4(0, 0, window_width(), window_height());
gui_panel(panel_pos, "panel"); gui_panel(panel_pos, "panel");
if (gui_button_label(FONT_H1 "PRESS", pos, 0)) {
// button
if (gui_button_label(FONT_FACE2 "PRESS", pos, 0)) {
printf("%s\n", "Button pressed!"); printf("%s\n", "Button pressed!");
} }
// vials
gui_rect(vec4(40,140, 320, 20*skinned->scale), "vial"); gui_rect(vec4(40,140, 320, 20*skinned->scale), "vial");
gui_rect(vec4(40,140, 200, 14*skinned->scale), "hp"); gui_rect(vec4(40,140, 200, 14*skinned->scale), "hp");
gui_rect(vec4(40,240, 240, 20*skinned->scale), "vial"); gui_rect(vec4(40,240, 240, 20*skinned->scale), "vial");
gui_rect(vec4(40,240, 160, 14*skinned->scale), "mp"); gui_rect(vec4(40,240, 160, 14*skinned->scale), "mp");
vec2 badge_size = gui_getskinsize("badge", 0); // buttons
vec2 badge_size = gui_getskinsize("badge", NULL);
badge_size.x += 2; // padding badge_size.x += 2; // padding
gui_rect(vec4(60+badge_size.x*0,320, 1, 1), "badge"); gui_rect(vec4(60+badge_size.x*0,320, 1, 1), "badge");
gui_rect(vec4(60+badge_size.x*1,320, 1, 1), "badge"); gui_rect(vec4(60+badge_size.x*1,320, 1, 1), "badge");
gui_rect(vec4(60+badge_size.x*2,320, 1, 1), "badge_empty"); gui_rect(vec4(60+badge_size.x*2,320, 1, 1), "badge_empty");
vec2 slider_size = gui_getskinsize("slider", 0); // sliders
gui_slider(vec4(60, 480, 80*skinned->scale, 1), 0, 0.0f, 15.0f, 1.0f, &testval); vec2 slider_size = gui_getskinsize("slider", NULL);
gui_slider_label(va(FONT_H1 "%.02f", testval2), vec4(60, 480+slider_size.y+10, 120*skinned->scale, 1), 0, -5.0f, 20.0f, 0.0f, &testval2); gui_slider(vec4(60, 420, 80*skinned->scale, 1), 0, 0.0f, 15.0f, 1.0f, &testval);
gui_slider_label(va(FONT_FACE2 "%.02f", testval2), vec4(60, 420+slider_size.y+10, 120*skinned->scale, 1), 0, -5.0f, 20.0f, 0.0f, &testval2);
gui_panel_end(); gui_panel_end();
} }

View File

@ -1,13 +1,11 @@
#include "v4k.h" #include "v4k.h"
skybox_t sky;
model_t litm; model_t litm;
lightmap_t baker;
void bakedrawmodel(lightmap_t *lm, model_t *m, float *view, float *proj, void *userdata) { void bakedrawmodel(lightmap_t *lm, model_t *m, float *view, float *proj, void *userdata) {
shader_bind(lm->shader); shader_bind(lm->shader);
model_render(*m, proj, view, m->pivot, lm->shader); model_render(*m, proj, view, m->pivot, lm->shader);
shader_float("u_litboost", 8.0); shader_float("u_litboost", 4.0);
model_render(litm, proj, view, litm.pivot, lm->shader); model_render(litm, proj, view, litm.pivot, lm->shader);
} }
@ -26,13 +24,11 @@ int main()
window_create(0.5, 0); window_create(0.5, 0);
window_title(__FILE__); window_title(__FILE__);
camera_t cam = camera(); camera_t cam = camera();
sky = skybox(0, 0); skybox_mie_calc_sh(&sky, 2.0f); skybox_t sky = skybox(0, 0); skybox_mie_calc_sh(&sky, 2.0f);
model_t mdl = model("gazebo.obj", 0); model_t mdl = model(option("--model","gazebo.obj"), 0);
litm = model("kgirls01.fbx", 0); litm = model("cube.obj", MODEL_MATCAPS);
{ {
mat44 lp; id44(lp); mat44 lp; scaling44(lp, 0.3, 0.3, 0.3); translate44(lp, 8,4,0);
// scaling44(lp, 10, 10, 10);
translate44(lp, 0,2,0);
copy44(litm.pivot, lp); copy44(litm.pivot, lp);
} }
rotate44(mdl.pivot, -90, 1, 0, 0); rotate44(mdl.pivot, -90, 1, 0, 0);
@ -41,11 +37,11 @@ int main()
shader_vec3v("u_coefficients_sh", 9, sky.cubemap.sh); shader_vec3v("u_coefficients_sh", 9, sky.cubemap.sh);
// shader_bool("u_texmod", 0); // shader_bool("u_texmod", 0);
// unsigned char emissive[] = { 255, 180, 0, 255 }; unsigned char emissive[] = { 255, 180, 0, 255 };
// texture_t emission = texture_create(1,1,4,emissive,TEXTURE_LINEAR); texture_t emission = texture_create(1,1,4,emissive,TEXTURE_LINEAR);
// model_set_texture(litm, emission); model_set_texture(litm, emission);
baker = lightmap(64, 0.01, 100, vec3(0,0,0), 2, 0.01, -1.0); lightmap_t baker = lightmap(64, 0.01, 100, vec3(0,0,0), 2, 0.01, 0.0);
lightmap_setup(&baker, 512, 512); lightmap_setup(&baker, 512, 512);
array_push(baker.models, &mdl); array_push(baker.models, &mdl);
@ -69,7 +65,7 @@ int main()
ui_label2("Freecam", "Mouse + W/A/S/D/E/Q keys"); ui_label2("Freecam", "Mouse + W/A/S/D/E/Q keys");
ui_label("Warning " ICON_MD_WARNING "@This will take a few seconds and bake a lightmap illuminated by: The mesh itself (initially black) + A white sky (1.0f, 1.0f, 1.0f)"); ui_label("Warning " ICON_MD_WARNING "@This will take a few seconds and bake a lightmap illuminated by: The mesh itself (initially black) + A white sky (1.0f, 1.0f, 1.0f)");
ui_int("Bounces", &b); ui_int("Bounces", &b);
if( ui_button(va("Bake %d light bounce", b)) ) { if( ui_button(va("Bake %d light bounce(s)", b)) ) {
do_bake=1; do_bake=1;
} }
ui_panel_end(); ui_panel_end();

View File

@ -15,7 +15,7 @@ int main() {
// load static scene // load static scene
model_t sponza; model_t sponza;
sponza = model("sponza.obj", 0); // MODEL_NO_TEXTURES); sponza = model(option("--model","sponza.obj"), 0); // MODEL_NO_TEXTURES);
translation44(sponza.pivot, 0,-1,0); translation44(sponza.pivot, 0,-1,0);
rotate44(sponza.pivot, -90,1,0,0); rotate44(sponza.pivot, -90,1,0,0);
scale44(sponza.pivot, 10,10,10); scale44(sponza.pivot, 10,10,10);

View File

@ -0,0 +1,94 @@
Copyright (c) 2011 Juan Montoreano (juan@remolacha.biz),
with Reserved Font Name Lilita
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

Binary file not shown.