Skip to content

Commit

Permalink
Immediate Mode GUI + general fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
asbott committed Apr 7, 2024
1 parent 33fdfe3 commit 31d8a48
Show file tree
Hide file tree
Showing 17 changed files with 2,538 additions and 60 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ ols.json

*.vs

*.sln
*.sln

*.obj
27 changes: 20 additions & 7 deletions app/app.odin
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app

import "jamgine:gfx"
import "jamgine:gfx/imm"
import igui "jamgine:gfx/imm/gui"
import "jamgine:gfx/text"
import "jamgine:console"
import "jamgine:input"
Expand All @@ -10,6 +11,8 @@ import "jamgine:lin"

import "core:fmt"
import "core:time"
import "core:mem"
import "core:os"

import "vendor:glfw"

Expand Down Expand Up @@ -40,10 +43,13 @@ run :: proc() {

context.logger = console.create_console_logger();

gfx.init_and_open_window("Majs");
gfx.init_and_open_window("Jamgine App");

imm.init();
imm.make_and_set_context();

igui.make_and_set_gui_context();

console.init(imm.get_current_context());
input.init(gfx.window);

Expand All @@ -60,6 +66,8 @@ run :: proc() {
time.stopwatch_start(&elapsed_stopwatch);
for !glfw.WindowShouldClose(gfx.window) && running {

mem.free_all(context.temp_allocator);

frame_duration = time.stopwatch_duration(frame_stopwatch);
delta_seconds = cast(f32)time.duration_seconds(frame_duration);
elapsed_duration = time.stopwatch_duration(elapsed_stopwatch);
Expand All @@ -68,19 +76,22 @@ run :: proc() {
time.stopwatch_start(&frame_stopwatch);

gfx.collect_window_events();

console.update(delta_seconds);
input.update();

igui.new_frame();
if sim_proc != nil && !sim_proc() {
running = false;
break;
}



if draw_proc != nil && !draw_proc() {
running = false;
break;
}

igui.update(delta_seconds);
input.update();

if should_draw_stats {
imm.set_render_target(gfx.window_surface);
Expand All @@ -90,8 +101,9 @@ run :: proc() {
stats_string := fmt.tprintf(
`imm Vertices: %i,
imm Indices: %i
Frametime: %f.
FPS: %f `, imm_stats.num_vertices, imm_stats.num_indices, delta_seconds, 1.0/delta_seconds);
imm Scissors: %i
Frametime: %fms.
FPS: %f `, imm_stats.num_vertices, imm_stats.num_indices, imm_stats.num_scissors, delta_seconds*1000, 1.0/delta_seconds);

text_size := text.measure(imm.get_current_context().default_font, stats_string);
imm.text(stats_string, { 5+1, 5-1, 0 } + lin.v3(text_size / 2.0), color=gfx.BLACK);
Expand All @@ -111,6 +123,7 @@ FPS: %f `, imm_stats.num_vertices, imm_stats.num_indices, delta_seconds, 1.0/del
if shutdown_proc != nil do shutdown_proc();

console.shutdown();
igui.destroy_current_context();
imm.delete_current_context();
imm.shutdown();
gfx.shutdown();
Expand Down
10 changes: 6 additions & 4 deletions console/console.odin
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ TOGGLE_SPEED :: 6.0;
CLOSED_POS :: 0.0;
HALF_POS :: 0.3;
FULL_POS :: 0.9;
BASE_COLOR :: lin.Vector4{ 0.0, 0.0, 0.0, 0.50 };
PROMPT_COLOR :: lin.Vector4{ 0.0, 0.0, 0.0, 0.8 };
BASE_COLOR :: lin.Vector4{ 0.0, 0.0, 0.0, 0.85 };
PROMPT_COLOR :: lin.Vector4{ 0.03, 0.03, 0.03, 0.9 };
USER_ENTRY_COLOR :: lin.Vector4{ .3, .6, .8, 1.0 };
DEFAULT_FONT_SIZE :: 18;
VERTICAL_PADDING :: 0.25;
Expand Down Expand Up @@ -1001,8 +1001,10 @@ update :: proc(dt : f32) {
}
}
case gfx.Window_Resize_Event: {
rerender_all();

rerender_all();
}
case gfx.Window_Mouse_Move_Event: {
gfx.window_events[i].handled = v.ypos >= gfx.get_window_size().y-(current_pos * gfx.get_window_size().y);
}
}
}
Expand Down
27 changes: 25 additions & 2 deletions gfx/gfx.odin
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ env : struct {
max_texture_size : int,
};
window : glfw.WindowHandle;
CURSOR_HRESIZE : glfw.CursorHandle;
CURSOR_VRESIZE : glfw.CursorHandle;
CURSOR_ARROW : glfw.CursorHandle;
CURSOR_IBEAM : glfw.CursorHandle;
CURSOR_HAND : glfw.CursorHandle;
CURSOR_CROSSHAIR : glfw.CursorHandle;
window_surface : ^jvk.Draw_Surface;
default_context : runtime.Context;
clear_color := lin.Vector4{0.2, 0.2, 0.3, 1.0};
Expand All @@ -133,8 +139,7 @@ set_window_event_callbacks :: proc() {
glfw.SetFramebufferSizeCallback(window, proc "c" (window: glfw.WindowHandle, width, height: i32) {
context = default_context;

// #Incomplete
/*gl.Viewport(0, 0, width, height);*/
//jvk.resize_draw_surface(window_surface, cast(uint)width, cast(uint)height);

append(&window_events, make_window_event(Window_Resize_Event{cast(f32)width, cast(f32)height}));
});
Expand Down Expand Up @@ -188,8 +193,26 @@ init_and_open_window :: proc(title : cstring = "JAMGINE GAME by CMQV", width :=

set_window_event_callbacks();

CURSOR_HRESIZE = glfw.CreateStandardCursor(glfw.HRESIZE_CURSOR);
CURSOR_VRESIZE = glfw.CreateStandardCursor(glfw.VRESIZE_CURSOR);
CURSOR_ARROW = glfw.CreateStandardCursor(glfw.ARROW_CURSOR);
CURSOR_IBEAM = glfw.CreateStandardCursor(glfw.IBEAM_CURSOR);
CURSOR_HAND = glfw.CreateStandardCursor(glfw.HAND_CURSOR);
CURSOR_CROSSHAIR = glfw.CreateStandardCursor(glfw.CROSSHAIR_CURSOR);

return true;
}
take_window_event :: proc($T : typeid) -> (^T) {
for e,i in window_events {
if e.handled do continue;
#partial switch v in e.variant {
case T: {
return &window_events[i].variant.(T);
}
}
}
return nil;
}


collect_window_events :: proc() {
Expand Down
Loading

0 comments on commit 31d8a48

Please sign in to comment.