Compare commits

...

7 Commits

Author SHA1 Message Date
3f7f516e5c make shaders work with textures 2025-05-01 14:19:34 +03:00
dc6fd0a73c edit ui drawing 2025-05-01 14:19:25 +03:00
bf9968201c pass sokol events to input module 2025-05-01 14:19:16 +03:00
e670e10415 add input module to main loop 2025-05-01 14:06:15 +03:00
cf2948af51 fix read me 2025-05-01 14:05:46 +03:00
9406ffab2c link stb image 2025-05-01 14:05:43 +03:00
3f297834d6 temp storage add 2025-05-01 14:05:20 +03:00
8 changed files with 201 additions and 73 deletions

View File

@ -1,2 +1,2 @@
# trueno game engine # trueno game engine
A sokol based Jai game engine focused on rendering 16x16x16 voxex blocks. Jai game engine focused on rendering 16x16x16 voxel blocks.

View File

@ -87,6 +87,7 @@
args := string.[ args := string.[
"emcc", "emcc",
"src/platform_specific/main.c", "dist/main.o", "modules/sokol-jai/sokol/gfx/sokol_gfx_wasm_gl_debug.a", "modules/sokol-jai/sokol/log/sokol_log_wasm_gl_debug.a", "modules/sokol-jai/sokol/time/sokol_time_wasm_gl_debug.a", "modules/sokol-jai/sokol/app/sokol_app_wasm_gl_debug.a", "modules/sokol-jai/sokol/glue/sokol_glue_wasm_gl_debug.a", "modules/sokol-jai/sokol/fetch/sokol_fetch_wasm_gl_debug.a", "modules/sokol-jai/sokol/gl/sokol_gl_wasm_gl_debug.a", "modules/sokol-jai/sokol/fontstash/sokol_fontstash_wasm_gl_debug.a", "src/platform_specific/main.c", "dist/main.o", "modules/sokol-jai/sokol/gfx/sokol_gfx_wasm_gl_debug.a", "modules/sokol-jai/sokol/log/sokol_log_wasm_gl_debug.a", "modules/sokol-jai/sokol/time/sokol_time_wasm_gl_debug.a", "modules/sokol-jai/sokol/app/sokol_app_wasm_gl_debug.a", "modules/sokol-jai/sokol/glue/sokol_glue_wasm_gl_debug.a", "modules/sokol-jai/sokol/fetch/sokol_fetch_wasm_gl_debug.a", "modules/sokol-jai/sokol/gl/sokol_gl_wasm_gl_debug.a", "modules/sokol-jai/sokol/fontstash/sokol_fontstash_wasm_gl_debug.a",
"modules/sokol-jai/sokol/stbi/stb_image.a",
"-o", "dist/index.html", "-o", "dist/index.html",
"-sERROR_ON_UNDEFINED_SYMBOLS=1", "-sMEMORY64", "-sMAX_WEBGL_VERSION=2", "-sERROR_ON_UNDEFINED_SYMBOLS=1", "-sMEMORY64", "-sMAX_WEBGL_VERSION=2",
"--js-library=src/platform_specific/runtime.js", "--js-library=src/platform_specific/runtime.js",

View File

@ -1,9 +1,29 @@
mpos : Vector2; mpos : Vector2;
handle_event :: (e: *sapp_event) { Queued_State_Set :: struct {
if e.type == .MOUSE_MOVE { code : Input.Key_Code;
mpos.x = e.mouse_x; state : Input.Key_Current_State;
mpos.y = e.mouse_y; ticks : int;
} };
state_set_queue : [..]Queued_State_Set;
state_set_queue_add :: (qss: Queued_State_Set) {
array_add(*state_set_queue, qss);
}
handle_event :: (e: *sapp_event) {
handle_sokol_event(xx,force e);
// if e.type == .MOUSE_MOVE {
// mpos.x = e.mouse_x;
// mpos.y = e.mouse_y;
// }
// if e.type == .MOUSE_DOWN {
// GR.set_state_for_key(Input.Key_Code.MOUSE_BUTTON_LEFT, .START);
// state_set_queue_add(.{Input.Key_Code.MOUSE_BUTTON_LEFT, .DOWN, 2});
// }
// if e.type == .MOUSE_UP {
// GR.set_state_for_key(Input.Key_Code.MOUSE_BUTTON_LEFT, .END);
// state_set_queue_add(.{Input.Key_Code.MOUSE_BUTTON_LEFT, .NONE, 2});
// }
} }

View File

@ -8,6 +8,10 @@
#load "load.jai"; #load "load.jai";
#load "./shaders/jai/shader_triangle.jai"; #load "./shaders/jai/shader_triangle.jai";
#import "Input";
stbi :: #import "stb_image";
state: struct { state: struct {
pass_action: sg_pass_action; pass_action: sg_pass_action;
dpi_scale: float; dpi_scale: float;
@ -57,12 +61,8 @@ init :: () {
})); }));
state.fons = fons_context; state.fons = fons_context;
state.font_default = FONS_INVALID; state.font_default = FONS_INVALID;
// file_data := read_entire_file("./");
// state.font_default = fonsAddFontMem(state.fons, "sans", *file_data[0], xx file_data.count, 0);
create_pipelines(); create_pipelines();
// a pass action to clear framebuffer to black
state.pass_action.colors[0] = .{ load_action = .CLEAR, clear_value = .{ r = 0.5, g = 0.5, b = 0.9, a = 1 } }; state.pass_action.colors[0] = .{ load_action = .CLEAR, clear_value = .{ r = 0.5, g = 0.5, b = 0.9, a = 1 } };
init_ui(); init_ui();
init_font_loads(); init_font_loads();
@ -74,10 +74,13 @@ frame :: () {
sfetch_dowork(); sfetch_dowork();
fonsClearState(state.fons); fonsClearState(state.fons);
for event: Input.events_this_frame {
GR.getrect_handle_event(event);
}
sgl_defaults(); sgl_defaults();
sgl_matrix_mode_projection(); sgl_matrix_mode_projection();
sgl_ortho(0.0, sapp_widthf(), sapp_heightf(), 0.0, -1.0, +1.0); sgl_ortho(0.0, sapp_widthf(), sapp_heightf(), 0.0, -1.0, +1.0);
black := sfons_rgba(0, 0, 0, 255);
tick_ui(); tick_ui();
sg_begin_pass(*(sg_pass.{ action = state.pass_action, swapchain = cast,force(sg_swapchain) sglue_swapchain() })); sg_begin_pass(*(sg_pass.{ action = state.pass_action, swapchain = cast,force(sg_swapchain) sglue_swapchain() }));
@ -88,6 +91,7 @@ frame :: () {
sg_end_pass(); sg_end_pass();
sg_commit(); sg_commit();
input_per_frame_event_and_flag_update();
reset_temporary_storage(); reset_temporary_storage();
} }

View File

@ -11,7 +11,16 @@
default_context: #Context; default_context: #Context;
temporary_storage: Temporary_Storage;
temporary_storage_data: [TEMPORARY_STORAGE_SIZE] u8 #align 64;
sapp_init :: () { sapp_init :: () {
default_context.temporary_storage = *temporary_storage;
temporary_storage.data = temporary_storage_data.data;
temporary_storage.size = temporary_storage_data.count;
temporary_storage.original_data = temporary_storage_data.data;
temporary_storage.original_size = temporary_storage_data.count;
push_context,defer_pop default_context; push_context,defer_pop default_context;
context.logger = logger; context.logger = logger;

View File

@ -17,23 +17,34 @@
ATTR_triangle_color0 => 1 ATTR_triangle_color0 => 1
ATTR_triangle_uv => 2 ATTR_triangle_uv => 2
Bindings: Bindings:
Image 'tex':
Image type: ._2D
Sample type: .FLOAT
Multisampled: false
Bind slot: IMG_tex => 0
Sampler 'smp':
Type: .FILTERING
Bind slot: SMP_smp => 0
*/ */
ATTR_triangle_position :: 0; ATTR_triangle_position :: 0;
ATTR_triangle_color0 :: 1; ATTR_triangle_color0 :: 1;
ATTR_triangle_uv :: 2; ATTR_triangle_uv :: 2;
IMG_tex :: 0;
SMP_smp :: 0;
/* /*
#version 430 #version 430
layout(location = 0) in vec4 position; layout(location = 0) in vec4 position;
layout(location = 0) out vec4 color; layout(location = 0) out vec4 color;
layout(location = 1) in vec4 color0; layout(location = 1) in vec4 color0;
layout(location = 1) out vec4 texcoord;
layout(location = 2) in vec4 uv; layout(location = 2) in vec4 uv;
void main() void main()
{ {
gl_Position = position; gl_Position = position;
color = color0; color = color0;
color.x = fma(9.9999999392252902907785028219223e-09, uv.x, color.x); texcoord = uv;
} }
*/ */
@ -47,39 +58,48 @@ vs_source_glsl430 := u8.[
0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69, 0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,
0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x6c, 0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x6c,
0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,
0x20,0x32,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x76,0x3b,0x0a, 0x20,0x31,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x74,0x65,0x78,
0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20, 0x63,0x6f,0x6f,0x72,0x64,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,
0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d, 0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32,0x29,0x20,0x69,0x6e,0x20,0x76,
0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63, 0x65,0x63,0x34,0x20,0x75,0x76,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,
0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20, 0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,
0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x20,0x3d,0x20,0x66,0x6d,0x61, 0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,
0x28,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32,0x35,0x32, 0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,
0x39,0x30,0x32,0x39,0x30,0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31,0x39,0x32, 0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x74,0x65,0x78,0x63,0x6f,
0x32,0x33,0x65,0x2d,0x30,0x39,0x2c,0x20,0x75,0x76,0x2e,0x78,0x2c,0x20,0x63,0x6f, 0x6f,0x72,0x64,0x20,0x3d,0x20,0x75,0x76,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
0x6c,0x6f,0x72,0x2e,0x78,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
]; ];
/* /*
#version 430 #version 430
layout(binding = 16) uniform sampler2D tex_smp;
layout(location = 0) out vec4 frag_color; layout(location = 0) out vec4 frag_color;
layout(location = 1) in vec4 texcoord;
layout(location = 0) in vec4 color; layout(location = 0) in vec4 color;
void main() void main()
{ {
frag_color = color; frag_color = texture(tex_smp, texcoord.xy);
} }
*/ */
fs_source_glsl430 := u8.[ fs_source_glsl430 := u8.[
0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61, 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61,
0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20, 0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x31,
0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67, 0x36,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,
0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, 0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x0a,0x6c,
0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20, 0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,
0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69, 0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,
0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66, 0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,
0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f, 0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,
0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 0x20,0x76,0x65,0x63,0x34,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x3b,0x0a,
0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,
0x3d,0x20,0x30,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,
0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,
0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,
0x72,0x20,0x3d,0x20,0x74,0x65,0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,
0x73,0x6d,0x70,0x2c,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,
0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
]; ];
/* /*
#version 300 es #version 300 es
@ -87,13 +107,14 @@ fs_source_glsl430 := u8.[
layout(location = 0) in vec4 position; layout(location = 0) in vec4 position;
out vec4 color; out vec4 color;
layout(location = 1) in vec4 color0; layout(location = 1) in vec4 color0;
out vec4 texcoord;
layout(location = 2) in vec4 uv; layout(location = 2) in vec4 uv;
void main() void main()
{ {
gl_Position = position; gl_Position = position;
color = color0; color = color0;
color.x = 9.9999999392252902907785028219223e-09 * uv.x + color.x; texcoord = uv;
} }
*/ */
@ -104,30 +125,31 @@ vs_source_glsl300es := u8.[
0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34, 0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,
0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c, 0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,
0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20, 0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x31,0x29,0x20,0x69,0x6e,0x20,
0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x6c,0x61,0x79, 0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x6f,0x75,0x74,
0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x32, 0x20,0x76,0x65,0x63,0x34,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x3b,0x0a,
0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x76,0x3b,0x0a,0x0a,0x76, 0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,
0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20, 0x3d,0x20,0x32,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x76,0x3b,
0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x70, 0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,
0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c, 0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,
0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20,0x20, 0x3d,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,
0x20,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x20,0x3d,0x20,0x39,0x2e,0x39,0x39,0x39, 0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,
0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32,0x35,0x32,0x39,0x30,0x32,0x39,0x30,0x37, 0x20,0x20,0x20,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x20,0x3d,0x20,0x75,
0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31,0x39,0x32,0x32,0x33,0x65,0x2d,0x30,0x39, 0x76,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
0x20,0x2a,0x20,0x75,0x76,0x2e,0x78,0x20,0x2b,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x2e,
0x78,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
]; ];
/* /*
#version 300 es #version 300 es
precision mediump float; precision mediump float;
precision highp int; precision highp int;
uniform highp sampler2D tex_smp;
layout(location = 0) out highp vec4 frag_color; layout(location = 0) out highp vec4 frag_color;
in highp vec4 texcoord;
in highp vec4 color; in highp vec4 color;
void main() void main()
{ {
frag_color = color; frag_color = texture(tex_smp, texcoord.xy);
} }
*/ */
@ -135,14 +157,20 @@ fs_source_glsl300es := u8.[
0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a, 0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x33,0x30,0x30,0x20,0x65,0x73,0x0a,
0x70,0x72,0x65,0x63,0x69,0x73,0x69,0x6f,0x6e,0x20,0x6d,0x65,0x64,0x69,0x75,0x6d, 0x70,0x72,0x65,0x63,0x69,0x73,0x69,0x6f,0x6e,0x20,0x6d,0x65,0x64,0x69,0x75,0x6d,
0x70,0x20,0x66,0x6c,0x6f,0x61,0x74,0x3b,0x0a,0x70,0x72,0x65,0x63,0x69,0x73,0x69, 0x70,0x20,0x66,0x6c,0x6f,0x61,0x74,0x3b,0x0a,0x70,0x72,0x65,0x63,0x69,0x73,0x69,
0x6f,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x69,0x6e,0x74,0x3b,0x0a,0x0a,0x6c, 0x6f,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x69,0x6e,0x74,0x3b,0x0a,0x0a,0x75,
0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d, 0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x73,0x61,0x6d,
0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65, 0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x3b,0x0a,
0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x69, 0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,
0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c, 0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x68,0x69,0x67,0x68,0x70,0x20,
0x6f,0x72,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29, 0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,
0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f, 0x0a,0x69,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x34,0x20,0x74,
0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00, 0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x3b,0x0a,0x69,0x6e,0x20,0x68,0x69,0x67,0x68,
0x70,0x20,0x76,0x65,0x63,0x34,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x0a,0x76,
0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,
0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x74,0x65,
0x78,0x74,0x75,0x72,0x65,0x28,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x2c,0x20,0x74,
0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x2e,0x78,0x79,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,
0x00,
]; ];
triangle_shader_desc :: (backend: sg_backend) -> sg_shader_desc { triangle_shader_desc :: (backend: sg_backend) -> sg_shader_desc {
desc: sg_shader_desc; desc: sg_shader_desc;
@ -159,6 +187,16 @@ triangle_shader_desc :: (backend: sg_backend) -> sg_shader_desc {
desc.attrs[1].glsl_name = "color0"; desc.attrs[1].glsl_name = "color0";
desc.attrs[2].base_type = .FLOAT; desc.attrs[2].base_type = .FLOAT;
desc.attrs[2].glsl_name = "uv"; desc.attrs[2].glsl_name = "uv";
desc.images[0].stage = .FRAGMENT;
desc.images[0].multisampled = false;
desc.images[0].image_type = ._2D;
desc.images[0].sample_type = .FLOAT;
desc.samplers[0].stage = .FRAGMENT;
desc.samplers[0].sampler_type = .FILTERING;
desc.image_sampler_pairs[0].stage = .FRAGMENT;
desc.image_sampler_pairs[0].image_slot = 0;
desc.image_sampler_pairs[0].sampler_slot = 0;
desc.image_sampler_pairs[0].glsl_name = "tex_smp";
case .GLES3; case .GLES3;
desc.vertex_func.source = xx *vs_source_glsl300es; desc.vertex_func.source = xx *vs_source_glsl300es;
desc.vertex_func.entry = "main"; desc.vertex_func.entry = "main";
@ -170,6 +208,16 @@ triangle_shader_desc :: (backend: sg_backend) -> sg_shader_desc {
desc.attrs[1].glsl_name = "color0"; desc.attrs[1].glsl_name = "color0";
desc.attrs[2].base_type = .FLOAT; desc.attrs[2].base_type = .FLOAT;
desc.attrs[2].glsl_name = "uv"; desc.attrs[2].glsl_name = "uv";
desc.images[0].stage = .FRAGMENT;
desc.images[0].multisampled = false;
desc.images[0].image_type = ._2D;
desc.images[0].sample_type = .FLOAT;
desc.samplers[0].stage = .FRAGMENT;
desc.samplers[0].sampler_type = .FILTERING;
desc.image_sampler_pairs[0].stage = .FRAGMENT;
desc.image_sampler_pairs[0].image_slot = 0;
desc.image_sampler_pairs[0].sampler_slot = 0;
desc.image_sampler_pairs[0].glsl_name = "tex_smp";
} }
return desc; return desc;
} }

View File

@ -4,20 +4,34 @@ in vec4 color0;
in vec4 uv; in vec4 uv;
out vec4 color; out vec4 color;
out vec4 texcoord;
void main() { void main() {
gl_Position = position; gl_Position = position;
color = color0; color = color0;
color.x += 0.00000001 * uv.x; texcoord = uv;
} }
@end @end
@fs fs @fs fs
in vec4 color; in vec4 color;
in vec4 texcoord;
out vec4 frag_color; out vec4 frag_color;
layout(binding = 0) uniform texture2D tex;
layout(binding = 0) uniform sampler smp;
bool near(float a, float b) {
return abs(a-b) < 0.01;
}
void main() { void main() {
frag_color = color; // if(near(texcoord.x, -4) && near(texcoord.y, -2)) {
// frag_color = color;
// } else {
frag_color = texture(sampler2D(tex, smp), texcoord.xy);
// }
} }
@end @end

View File

@ -1,4 +1,5 @@
GR :: #import "GetRect_LeftHanded"()(Type_Indicator = Ui_Type_Indicator); GR :: #import "GetRect_LeftHanded"()(Type_Indicator = Ui_Type_Indicator);
Input :: #import "Input";
Ui_Font :: struct { Ui_Font :: struct {
em_width: u32 = 1; em_width: u32 = 1;
@ -6,7 +7,7 @@ Ui_Font :: struct {
} }
Ui_Texture :: struct { Ui_Texture :: struct {
name: string; tex: sg_image;
} }
Ui_Rect :: struct { Ui_Rect :: struct {
@ -27,10 +28,30 @@ defaultFont: Font;
ui_texture_counter : u32 = 0; ui_texture_counter : u32 = 0;
texture_load_from_memory :: (texture: *Ui_Texture, memory: []u8, srgb: bool, build_mipmaps: bool) -> bool { texture_load_from_memory :: (texture: *Ui_Texture, memory: []u8, srgb: bool, build_mipmaps: bool) -> bool {
// texname := tprint("ui_tex_%", ui_texture_counter); print("LOAD FROM MEMORY CALLED!!!\n");
// load_png_texture_from_memory(*GpuContext, copy_string(texname), memory); x : s32;
// ui_texture_counter += 1; y : s32;
// texture.name = copy_string(texname); channels : s32;
data := stbi.stbi_load_from_memory(memory.data, xx memory.count, *x, *y, *channels, 4);
img := sg_alloc_image();
subimg : [6][16]sg_range;
subimg[0][0] = .{
ptr = data,
size = xx (x * y * 4)
};
sg_init_image(*img, *(sg_image_desc.{
width = x,
height = y,
pixel_format = sg_pixel_format.RGBA8,
data = .{
subimage = subimg
}
}));
stbi.stbi_image_free(data);
texture.tex = img;
return true; return true;
} }
@ -53,14 +74,12 @@ clear_scissor :: () {
gCurrentTexture : *Ui_Texture = null; gCurrentTexture : *Ui_Texture = null;
set_shader_for_color :: (enable_blend := false) { set_shader_for_color :: (enable_blend := false) {
// immediate_flush(); // We want to do the flush so we can set the sampler for the entire set.
// gCurrentTexture = null; // gCurrentTexture = null;
} }
set_shader_for_images :: (texture: *Ui_Texture) { set_shader_for_images :: (texture: *Ui_Texture) {
// if ENABLE_UI_DEBUG_LOGGING { print("Setting shader for textures.."); } // gPipelines.arbtri.bind.images[0] = texture.tex;
// immediate_flush(); // We want to do the flush so we can set the sampler for the entire set.
// gCurrentTexture = texture; // gCurrentTexture = texture;
} }
@ -84,7 +103,7 @@ draw_prepared_text :: (font: *Ui_Type_Indicator.Font, x: s64, y: s64, text_color
fonsDrawText(state.fons, xx x, xx y, result, null); fonsDrawText(state.fons, xx x, xx y, result, null);
} }
get_mouse_pointer_position :: (window: Ui_Type_Indicator.Window_Type, right_handed: bool) -> (x: int, y: int, success: bool) { get_mouse_pointer_position :: (window: Ui_Type_Indicator.Window_Type, right_handed: bool) -> (x: int, y: int, success: bool) {
return xx mpos.x, xx mpos.y, true; return xx input_mouse_x, xx input_mouse_y, true;
} }
get_font_at_size :: (memory: [] u8, pixel_height: int) -> *Font { get_font_at_size :: (memory: [] u8, pixel_height: int) -> *Font {
f : *Font = New(Font); f : *Font = New(Font);
@ -134,15 +153,15 @@ immediate_flush :: () {
init_ui :: () { init_ui :: () {
dp : GR.Draw_Procs = .{ dp : GR.Draw_Procs = .{
texture_load_from_memory = texture_load_from_memory, texture_load_from_memory = texture_load_from_memory, // implemented
set_scissor = set_scissor, set_scissor = set_scissor,
clear_scissor = clear_scissor, clear_scissor = clear_scissor,
set_shader_for_color = set_shader_for_color, set_shader_for_color = set_shader_for_color, // implemented
set_shader_for_images = set_shader_for_images, set_shader_for_images = set_shader_for_images,
prepare_text = prepare_text, prepare_text = prepare_text, // implemented
draw_prepared_text = draw_prepared_text, draw_prepared_text = draw_prepared_text, // implemented
get_mouse_pointer_position = get_mouse_pointer_position, get_mouse_pointer_position = get_mouse_pointer_position, // implemented
get_font_at_size = get_font_at_size, get_font_at_size = get_font_at_size, // implemented
immediate_triangle = immediate_triangle, // implemented immediate_triangle = immediate_triangle, // implemented
immediate_quad = immediate_quad, // implemented immediate_quad = immediate_quad, // implemented
immediate_flush = immediate_flush // implemented immediate_flush = immediate_flush // implemented
@ -151,8 +170,18 @@ init_ui :: () {
GR.ui_init("", *dp); GR.ui_init("", *dp);
} }
ui_events : [..]Input.Event;
add_ui_event :: (event: Input.Event) {
array_add(*ui_events, event);
}
tick_ui :: () { tick_ui :: () {
w,h := get_window_size(); w,h := get_window_size();
for ui_events {
GR.getrect_handle_event(it);
}
array_reset_keeping_memory(*ui_events);
GR.ui_per_frame_update(1, xx w, xx h, get_time()); GR.ui_per_frame_update(1, xx w, xx h, get_time());
} }
@ -168,13 +197,16 @@ idk : bool;
render_ui :: () { render_ui :: () {
proc := GR.default_theme_procs[3]; proc := GR.default_theme_procs[3];
my_theme := proc(); my_theme := proc();
GR.set_default_theme(my_theme); // Just in case we don't explicitly pass themes sometimes...! GR.set_default_theme(my_theme);
r := GR.get_rect(10, 10, 400, 30); r := GR.get_rect(10, 10, 400, 30);
pressed := GR.button(r, "GetRect render lfg!!", *my_theme.button_theme); pressed := GR.button(r, "GetRect render lfg!!", *my_theme.button_theme);
if pressed {
}
r.y += 150; r.y += 150;
GR.base_checkbox(r, "CHECK!!!", idk, null); if GR.base_checkbox(r, "CHECK!!!", idk, null) {
}
} }