We got decent text rendering in world now!
This commit is contained in:
parent
5c124521dc
commit
04c8f84e7d
@ -97,11 +97,11 @@ startup :: proc( live_mem : virtual.Arena, snapshot_mem : []u8, host_logger : ^
|
||||
// Basic Font Setup
|
||||
{
|
||||
font_provider_startup()
|
||||
path_rec_mono_semicasual_reg := strings.concatenate( { Path_Assets, "RecMonoSemicasual-Regular-1.084.ttf" })
|
||||
font_rec_mono_semicasual_reg = font_load( path_rec_mono_semicasual_reg, 24.0, "RecMonoSemiCasual_Regular" )
|
||||
// path_rec_mono_semicasual_reg := strings.concatenate( { Path_Assets, "RecMonoSemicasual-Regular-1.084.ttf" })
|
||||
// font_rec_mono_semicasual_reg = font_load( path_rec_mono_semicasual_reg, 24.0, "RecMonoSemiCasual_Regular" )
|
||||
|
||||
path_squidgy_slimes := strings.concatenate( { Path_Assets, "Squidgy Slimes.ttf" } )
|
||||
font_squidgy_slimes = font_load( path_squidgy_slimes, 24.0, "Squidgy_Slime" )
|
||||
// path_squidgy_slimes := strings.concatenate( { Path_Assets, "Squidgy Slimes.ttf" } )
|
||||
// font_squidgy_slimes = font_load( path_squidgy_slimes, 24.0, "Squidgy_Slime" )
|
||||
|
||||
path_firacode := strings.concatenate( { Path_Assets, "FiraCode-Regular.ttf" } )
|
||||
font_firacode = font_load( path_firacode, 24.0, "FiraCode" )
|
||||
@ -142,10 +142,10 @@ startup :: proc( live_mem : virtual.Arena, snapshot_mem : []u8, host_logger : ^
|
||||
|
||||
frame_1.color = Color_BG_TextBox
|
||||
// Frame is getting interpreted as points (It doesn't have to be, I'm just doing it...)
|
||||
box_set_size( & frame_1, { 50, 25 } * CM_Per_Point )
|
||||
box_set_size( & frame_1, { 100, 50 } * CM_Per_Point )
|
||||
|
||||
frame_2.color = Color_BG_TextBox_Green
|
||||
box_set_size( & frame_2, { 30, 50 } * CM_Per_Point )
|
||||
box_set_size( & frame_2, { 60, 100 } * CM_Per_Point )
|
||||
// frame_1.position = { 1000, 1000 }
|
||||
}
|
||||
}
|
||||
@ -196,6 +196,10 @@ reload :: proc( live_mem : virtual.Arena, snapshot_mem : []u8, host_logger : ^ L
|
||||
|
||||
context.allocator = transient_allocator()
|
||||
context.temp_allocator = temp_allocator()
|
||||
|
||||
// font_provider_data := & get_state().font_provider_data
|
||||
// font_provider_data.font_cache.allocator = arena_allocator( & font_provider_data.font_arena )
|
||||
|
||||
log("Module reloaded")
|
||||
}
|
||||
|
||||
@ -207,6 +211,9 @@ swap :: proc( a, b : ^ $Type ) -> ( ^ Type, ^ Type ) {
|
||||
@export
|
||||
tick :: proc ( delta_time : f64 ) -> b32
|
||||
{
|
||||
context.allocator = transient_allocator()
|
||||
context.temp_allocator = temp_allocator()
|
||||
|
||||
result := update( delta_time )
|
||||
render()
|
||||
return result
|
||||
|
@ -160,4 +160,5 @@ DebugData :: struct {
|
||||
last_mouse_pos : Vec2,
|
||||
|
||||
frame_1_on_top : b32,
|
||||
zoom_target : f32,
|
||||
}
|
||||
|
@ -11,7 +11,8 @@ import rl "vendor:raylib"
|
||||
Font_Arena_Size :: 32 * Megabyte
|
||||
Font_Largest_Px_Size :: 96
|
||||
|
||||
Font_Default :: ""
|
||||
// Font_Default :: ""
|
||||
Font_Default :: 0
|
||||
Font_Default_Point_Size :: 18.0
|
||||
|
||||
Font_TTF_Default_Chars_Padding :: 4
|
||||
@ -28,7 +29,8 @@ Font_Atlas_Packing_Method :: enum u32 {
|
||||
Font :: rl.Font
|
||||
|
||||
// TODO(Ed) : Use this instead of the raylib font directly
|
||||
FontID :: distinct string
|
||||
// FontID :: distinct string
|
||||
FontID :: distinct i32
|
||||
FontTag :: struct {
|
||||
key : FontID,
|
||||
point_size : f32
|
||||
@ -52,7 +54,11 @@ FontDef :: struct {
|
||||
|
||||
FontProviderData :: struct {
|
||||
font_arena : Arena,
|
||||
font_cache : ^ map [FontID] FontDef,
|
||||
|
||||
//TODO(Ed) : There is an issue with hot-reload and map allocations that I can't figure out right now..
|
||||
// font_cache : map [FontID](FontDef),
|
||||
font_cache : [10] FontDef,
|
||||
open_id : i32
|
||||
}
|
||||
|
||||
font_provider_startup :: proc()
|
||||
@ -65,7 +71,9 @@ font_provider_startup :: proc()
|
||||
|
||||
arena_init( & font_arena, data )
|
||||
|
||||
font_cache = new( type_of(font_cache ^), arena_allocator( & font_arena) )
|
||||
// font_cache = new( map[FontID](FontDef), arena_allocator( & font_arena ) )
|
||||
// font_cache = make_map( map[FontID](FontDef), capacity = 10, allocator = arena_allocator( & font_arena ) )
|
||||
open_id = 0
|
||||
log("font_cache created")
|
||||
log("font_provider initialized")
|
||||
}
|
||||
@ -74,8 +82,9 @@ font_provider_shutdown :: proc()
|
||||
{
|
||||
font_provider_data := & get_state().font_provider_data; using font_provider_data
|
||||
|
||||
for key, & value in font_cache {
|
||||
for & px_render in value.size_table {
|
||||
// for key, & def in font_cache {
|
||||
for & def in font_cache {
|
||||
for & px_render in def.size_table {
|
||||
using px_render
|
||||
rl.UnloadFontData( glyphs, count )
|
||||
rl.UnloadTexture ( texture )
|
||||
@ -86,7 +95,7 @@ font_provider_shutdown :: proc()
|
||||
|
||||
font_load :: proc ( path_file : string,
|
||||
default_size : f32 = Font_Load_Use_Default_Size,
|
||||
desired_id : FontID = Font_Load_Gen_ID
|
||||
desired_id : string = Font_Load_Gen_ID
|
||||
) -> FontID
|
||||
{
|
||||
font_provider_data := & get_state().font_provider_data; using font_provider_data
|
||||
@ -100,7 +109,8 @@ font_load :: proc ( path_file : string,
|
||||
if len(desired_id) == 0 {
|
||||
// NOTE(Ed): This should never be used except for laziness so I'll be throwing a warning everytime.
|
||||
log("desired_key not provided, using file name. Give it a proper name!")
|
||||
desired_id = cast(FontID) file_name_from_path(path_file)
|
||||
// desired_id = cast(FontID) file_name_from_path(path_file)
|
||||
desired_id = file_name_from_path(path_file)
|
||||
}
|
||||
|
||||
default_size := default_size
|
||||
@ -108,8 +118,10 @@ font_load :: proc ( path_file : string,
|
||||
default_size = Font_Default_Point_Size
|
||||
}
|
||||
|
||||
font_cache[desired_id] = {}
|
||||
def := & font_cache[desired_id];
|
||||
// font_cache[desired_id] = {}
|
||||
// def := & font_cache[desired_id];
|
||||
def := & font_cache[open_id]
|
||||
open_id += 1
|
||||
def.path_file = path_file
|
||||
def.data = font_data
|
||||
def.default_size = i32(points_to_pixels(default_size))
|
||||
@ -132,7 +144,6 @@ font_load :: proc ( path_file : string,
|
||||
|
||||
atlas := rl.GenImageFontAtlas( glyphs, & recs, count, size, padding, i32(Font_Atlas_Packing_Method.Raylib_Basic) )
|
||||
texture = rl.LoadTextureFromImage( atlas )
|
||||
rl.SetTextureFilter( texture, rl.TextureFilter.POINT )
|
||||
|
||||
// glyphs_slice := slice_ptr( glyphs, count )
|
||||
// for glyph in glyphs_slice {
|
||||
@ -148,7 +159,8 @@ font_load :: proc ( path_file : string,
|
||||
rl.UnloadImage( atlas )
|
||||
}
|
||||
|
||||
return desired_id
|
||||
// return desired_id
|
||||
return cast(FontID) open_id - 1
|
||||
}
|
||||
|
||||
Font_Use_Default_Size :: f32(0.0)
|
||||
@ -156,13 +168,13 @@ Font_Use_Default_Size :: f32(0.0)
|
||||
to_rl_Font :: proc ( id : FontID, size := Font_Use_Default_Size ) -> rl.Font {
|
||||
font_provider_data := & get_state().font_provider_data; using font_provider_data
|
||||
|
||||
size := clamp( i32(math.round(size)), 12, Font_Largest_Px_Size )
|
||||
|
||||
verify( size > Font_Largest_Px_Size, "attempt to get a font larger than the largest loaded pixel size" )
|
||||
size := clamp( i32( math.round(size * 0.5) * 2.0), 8, Font_Largest_Px_Size )
|
||||
def := & font_cache[id]
|
||||
size = size if size != i32(Font_Use_Default_Size) else def.default_size
|
||||
px_render := & def.size_table[ size - 1 ]
|
||||
|
||||
rl.SetTextureFilter( px_render.texture, rl.TextureFilter.TRILINEAR )
|
||||
|
||||
rl_font : rl.Font
|
||||
rl_font.baseSize = px_render.size
|
||||
rl_font.charsCount = px_render.count
|
||||
|
@ -42,6 +42,7 @@ tracking_allocator_init :: mem.tracking_allocator_init
|
||||
file_name_from_path :: filepath.short_stem
|
||||
OS_Type :: type_of(ODIN_OS)
|
||||
|
||||
|
||||
get_bounds :: proc {
|
||||
box_get_bounds,
|
||||
view_get_bounds,
|
||||
|
@ -14,7 +14,8 @@ debug_draw_text :: proc( content : string, pos : Vec2, size : f32, color : rl.Co
|
||||
runes := utf8.string_to_runes( content, context.temp_allocator )
|
||||
|
||||
font := font
|
||||
if ( len(font) == 0 ) {
|
||||
if font == 0 {
|
||||
// if ( len(font) == 0 ) {
|
||||
font = default_font
|
||||
}
|
||||
pos := screen_to_render(pos)
|
||||
@ -40,7 +41,8 @@ debug_draw_text_world :: proc( content : string, pos : Vec2, size : f32, color :
|
||||
runes := utf8.string_to_runes( content, context.temp_allocator )
|
||||
|
||||
font := font
|
||||
if ( len(font) == 0 ) {
|
||||
if font == 0 {
|
||||
// if len(font) == 0 {
|
||||
font = default_font
|
||||
}
|
||||
pos := world_to_screen_pos(pos)
|
||||
|
@ -136,15 +136,25 @@ update :: proc( delta_time : f64 ) -> b32
|
||||
|
||||
// Camera Manual Nav
|
||||
{
|
||||
digital_move_speed : f32 = 200.0
|
||||
zoom_sensitiviity : f32 = 0.05
|
||||
cam := & project.workspace.cam
|
||||
|
||||
cam := & project.workspace.cam
|
||||
zoom_delta := input.mouse.vertical_wheel * zoom_sensitiviity
|
||||
// zoom_delta *= f32(delta_time)
|
||||
cam.zoom *= 1 + zoom_delta
|
||||
cam.zoom = clamp( cam.zoom, 0.5, 10.0 )
|
||||
// cam.zoom = 2.0
|
||||
digital_move_speed : f32 = 200.0
|
||||
zoom_sensitivity : f32 = 0.1 // Digital
|
||||
// zoom_sensitivity : f32 = 2.0 // Smooth
|
||||
|
||||
if debug.zoom_target == 0.0 {
|
||||
debug.zoom_target = cam.zoom
|
||||
}
|
||||
|
||||
// Adjust zoom_target based on input, not the actual zoom
|
||||
zoom_delta := input.mouse.vertical_wheel * zoom_sensitivity
|
||||
debug.zoom_target *= 1 + zoom_delta //* f32(delta_time)
|
||||
debug.zoom_target = clamp(debug.zoom_target, 0.5, 10.0)
|
||||
|
||||
// Linearly interpolate cam.zoom towards zoom_target
|
||||
lerp_factor := cast(f32) 4.0 // Adjust this value to control the interpolation speed
|
||||
cam.zoom += (debug.zoom_target - cam.zoom) * lerp_factor * f32(delta_time)
|
||||
cam.zoom = clamp(cam.zoom, 0.5, 10.0) // Ensure cam.zoom stays within bounds
|
||||
|
||||
move_velocity : Vec2 = {
|
||||
- cast(f32) i32(debug_actions.cam_move_left) + cast(f32) i32(debug_actions.cam_move_right),
|
||||
|
Loading…
Reference in New Issue
Block a user