Compare commits

..

No commits in common. "3f7f516e5ce21b9461b7717ceda834c7b8ff0578" and "c212e5ce1e74a1bbe041d4c3364e62e8d7687edd" have entirely different histories.

8 changed files with 72 additions and 200 deletions

View File

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

View File

@ -87,7 +87,6 @@
args := string.[
"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",
"modules/sokol-jai/sokol/stbi/stb_image.a",
"-o", "dist/index.html",
"-sERROR_ON_UNDEFINED_SYMBOLS=1", "-sMEMORY64", "-sMAX_WEBGL_VERSION=2",
"--js-library=src/platform_specific/runtime.js",

View File

@ -1,29 +1,9 @@
mpos : Vector2;
Queued_State_Set :: struct {
code : Input.Key_Code;
state : Input.Key_Current_State;
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});
// }
if e.type == .MOUSE_MOVE {
mpos.x = e.mouse_x;
mpos.y = e.mouse_y;
}
}

View File

@ -8,10 +8,6 @@
#load "load.jai";
#load "./shaders/jai/shader_triangle.jai";
#import "Input";
stbi :: #import "stb_image";
state: struct {
pass_action: sg_pass_action;
dpi_scale: float;
@ -61,8 +57,12 @@ init :: () {
}));
state.fons = fons_context;
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();
// 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 } };
init_ui();
init_font_loads();
@ -74,13 +74,10 @@ frame :: () {
sfetch_dowork();
fonsClearState(state.fons);
for event: Input.events_this_frame {
GR.getrect_handle_event(event);
}
sgl_defaults();
sgl_matrix_mode_projection();
sgl_ortho(0.0, sapp_widthf(), sapp_heightf(), 0.0, -1.0, +1.0);
black := sfons_rgba(0, 0, 0, 255);
tick_ui();
sg_begin_pass(*(sg_pass.{ action = state.pass_action, swapchain = cast,force(sg_swapchain) sglue_swapchain() }));
@ -91,7 +88,6 @@ frame :: () {
sg_end_pass();
sg_commit();
input_per_frame_event_and_flag_update();
reset_temporary_storage();
}

View File

@ -11,16 +11,7 @@
default_context: #Context;
temporary_storage: Temporary_Storage;
temporary_storage_data: [TEMPORARY_STORAGE_SIZE] u8 #align 64;
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;
context.logger = logger;

View File

@ -17,34 +17,23 @@
ATTR_triangle_color0 => 1
ATTR_triangle_uv => 2
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_color0 :: 1;
ATTR_triangle_uv :: 2;
IMG_tex :: 0;
SMP_smp :: 0;
/*
#version 430
layout(location = 0) in vec4 position;
layout(location = 0) out vec4 color;
layout(location = 1) in vec4 color0;
layout(location = 1) out vec4 texcoord;
layout(location = 2) in vec4 uv;
void main()
{
gl_Position = position;
color = color0;
texcoord = uv;
color.x = fma(9.9999999392252902907785028219223e-09, uv.x, color.x);
}
*/
@ -58,48 +47,39 @@ vs_source_glsl430 := u8.[
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,
0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,
0x20,0x31,0x29,0x20,0x6f,0x75,0x74,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,0x32,0x29,0x20,0x69,0x6e,0x20,0x76,
0x65,0x63,0x34,0x20,0x75,0x76,0x3b,0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,
0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,
0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,
0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,
0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20,0x20,0x20,0x74,0x65,0x78,0x63,0x6f,
0x6f,0x72,0x64,0x20,0x3d,0x20,0x75,0x76,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
0x20,0x32,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x76,0x3b,0x0a,
0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,
0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,
0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,
0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,
0x20,0x20,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x20,0x3d,0x20,0x66,0x6d,0x61,
0x28,0x39,0x2e,0x39,0x39,0x39,0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32,0x35,0x32,
0x39,0x30,0x32,0x39,0x30,0x37,0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31,0x39,0x32,
0x32,0x33,0x65,0x2d,0x30,0x39,0x2c,0x20,0x75,0x76,0x2e,0x78,0x2c,0x20,0x63,0x6f,
0x6c,0x6f,0x72,0x2e,0x78,0x29,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
];
/*
#version 430
layout(binding = 16) uniform sampler2D tex_smp;
layout(location = 0) out vec4 frag_color;
layout(location = 1) in vec4 texcoord;
layout(location = 0) in vec4 color;
void main()
{
frag_color = texture(tex_smp, texcoord.xy);
frag_color = color;
}
*/
fs_source_glsl430 := u8.[
0x23,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x34,0x33,0x30,0x0a,0x0a,0x6c,0x61,
0x79,0x6f,0x75,0x74,0x28,0x62,0x69,0x6e,0x64,0x69,0x6e,0x67,0x20,0x3d,0x20,0x31,
0x36,0x29,0x20,0x75,0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x73,0x61,0x6d,0x70,0x6c,
0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x3b,0x0a,0x0a,0x6c,
0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,
0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,
0x67,0x5f,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,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,
0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,
0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,
0x5f,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,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,0x63,0x6f,0x6c,0x6f,
0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
];
/*
#version 300 es
@ -107,14 +87,13 @@ fs_source_glsl430 := u8.[
layout(location = 0) in vec4 position;
out vec4 color;
layout(location = 1) in vec4 color0;
out vec4 texcoord;
layout(location = 2) in vec4 uv;
void main()
{
gl_Position = position;
color = color0;
texcoord = uv;
color.x = 9.9999999392252902907785028219223e-09 * uv.x + color.x;
}
*/
@ -125,31 +104,30 @@ vs_source_glsl300es := u8.[
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,
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,0x6f,0x75,0x74,
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,0x32,0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x76,0x3b,
0x0a,0x0a,0x76,0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,
0x20,0x20,0x20,0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,
0x3d,0x20,0x70,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,
0x63,0x6f,0x6c,0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,
0x20,0x20,0x20,0x20,0x74,0x65,0x78,0x63,0x6f,0x6f,0x72,0x64,0x20,0x3d,0x20,0x75,
0x76,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
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,0x20,0x32,
0x29,0x20,0x69,0x6e,0x20,0x76,0x65,0x63,0x34,0x20,0x75,0x76,0x3b,0x0a,0x0a,0x76,
0x6f,0x69,0x64,0x20,0x6d,0x61,0x69,0x6e,0x28,0x29,0x0a,0x7b,0x0a,0x20,0x20,0x20,
0x20,0x67,0x6c,0x5f,0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x3d,0x20,0x70,
0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x3b,0x0a,0x20,0x20,0x20,0x20,0x63,0x6f,0x6c,
0x6f,0x72,0x20,0x3d,0x20,0x63,0x6f,0x6c,0x6f,0x72,0x30,0x3b,0x0a,0x20,0x20,0x20,
0x20,0x63,0x6f,0x6c,0x6f,0x72,0x2e,0x78,0x20,0x3d,0x20,0x39,0x2e,0x39,0x39,0x39,
0x39,0x39,0x39,0x39,0x33,0x39,0x32,0x32,0x35,0x32,0x39,0x30,0x32,0x39,0x30,0x37,
0x37,0x38,0x35,0x30,0x32,0x38,0x32,0x31,0x39,0x32,0x32,0x33,0x65,0x2d,0x30,0x39,
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
precision mediump float;
precision highp int;
uniform highp sampler2D tex_smp;
layout(location = 0) out highp vec4 frag_color;
in highp vec4 texcoord;
in highp vec4 color;
void main()
{
frag_color = texture(tex_smp, texcoord.xy);
frag_color = color;
}
*/
@ -157,20 +135,14 @@ fs_source_glsl300es := u8.[
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,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,0x75,
0x6e,0x69,0x66,0x6f,0x72,0x6d,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x73,0x61,0x6d,
0x70,0x6c,0x65,0x72,0x32,0x44,0x20,0x74,0x65,0x78,0x5f,0x73,0x6d,0x70,0x3b,0x0a,
0x0a,0x6c,0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,
0x20,0x3d,0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x68,0x69,0x67,0x68,0x70,0x20,
0x76,0x65,0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,0x3b,
0x0a,0x69,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,0x63,0x34,0x20,0x74,
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,
0x6f,0x6e,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x69,0x6e,0x74,0x3b,0x0a,0x0a,0x6c,
0x61,0x79,0x6f,0x75,0x74,0x28,0x6c,0x6f,0x63,0x61,0x74,0x69,0x6f,0x6e,0x20,0x3d,
0x20,0x30,0x29,0x20,0x6f,0x75,0x74,0x20,0x68,0x69,0x67,0x68,0x70,0x20,0x76,0x65,
0x63,0x34,0x20,0x66,0x72,0x61,0x67,0x5f,0x63,0x6f,0x6c,0x6f,0x72,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,0x63,0x6f,0x6c,0x6f,0x72,0x3b,0x0a,0x7d,0x0a,0x0a,0x00,
];
triangle_shader_desc :: (backend: sg_backend) -> sg_shader_desc {
desc: sg_shader_desc;
@ -187,16 +159,6 @@ triangle_shader_desc :: (backend: sg_backend) -> sg_shader_desc {
desc.attrs[1].glsl_name = "color0";
desc.attrs[2].base_type = .FLOAT;
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;
desc.vertex_func.source = xx *vs_source_glsl300es;
desc.vertex_func.entry = "main";
@ -208,16 +170,6 @@ triangle_shader_desc :: (backend: sg_backend) -> sg_shader_desc {
desc.attrs[1].glsl_name = "color0";
desc.attrs[2].base_type = .FLOAT;
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;
}

View File

@ -4,34 +4,20 @@ in vec4 color0;
in vec4 uv;
out vec4 color;
out vec4 texcoord;
void main() {
gl_Position = position;
color = color0;
texcoord = uv;
color.x += 0.00000001 * uv.x;
}
@end
@fs fs
in vec4 color;
in vec4 texcoord;
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() {
// if(near(texcoord.x, -4) && near(texcoord.y, -2)) {
// frag_color = color;
// } else {
frag_color = texture(sampler2D(tex, smp), texcoord.xy);
// }
frag_color = color;
}
@end

View File

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