-
Notifications
You must be signed in to change notification settings - Fork 22
/
demo.c
74 lines (65 loc) · 2.08 KB
/
demo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//------------------------------------------------------------------------------
// Simple C99 cimgui+sokol starter project for Win32, Linux and macOS.
//------------------------------------------------------------------------------
#include "sokol_app.h"
#include "sokol_gfx.h"
#include "sokol_log.h"
#include "sokol_glue.h"
#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS
#include "cimgui.h"
#include "sokol_imgui.h"
static struct {
sg_pass_action pass_action;
} state;
static void init(void) {
sg_setup(&(sg_desc){
.environment = sglue_environment(),
.logger.func = slog_func,
});
simgui_setup(&(simgui_desc_t){ 0 });
// initial clear color
state.pass_action = (sg_pass_action) {
.colors[0] = { .load_action = SG_LOADACTION_CLEAR, .clear_value = { 0.0f, 0.5f, 1.0f, 1.0 } }
};
}
static void frame(void) {
simgui_new_frame(&(simgui_frame_desc_t){
.width = sapp_width(),
.height = sapp_height(),
.delta_time = sapp_frame_duration(),
.dpi_scale = sapp_dpi_scale(),
});
/*=== UI CODE STARTS HERE ===*/
igSetNextWindowPos((ImVec2){10,10}, ImGuiCond_Once, (ImVec2){0,0});
igSetNextWindowSize((ImVec2){400, 100}, ImGuiCond_Once);
igBegin("Hello Dear ImGui!", 0, ImGuiWindowFlags_None);
igColorEdit3("Background", &state.pass_action.colors[0].clear_value.r, ImGuiColorEditFlags_None);
igEnd();
/*=== UI CODE ENDS HERE ===*/
sg_begin_pass(&(sg_pass){ .action = state.pass_action, .swapchain = sglue_swapchain() });
simgui_render();
sg_end_pass();
sg_commit();
}
static void cleanup(void) {
simgui_shutdown();
sg_shutdown();
}
static void event(const sapp_event* ev) {
simgui_handle_event(ev);
}
sapp_desc sokol_main(int argc, char* argv[]) {
(void)argc;
(void)argv;
return (sapp_desc){
.init_cb = init,
.frame_cb = frame,
.cleanup_cb = cleanup,
.event_cb = event,
.window_title = "Hello Sokol + Dear ImGui",
.width = 800,
.height = 600,
.icon.sokol_default = true,
.logger.func = slog_func,
};
}