This repository has been archived by the owner on Nov 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
overlay.c
140 lines (120 loc) · 5.06 KB
/
overlay.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#define _CRT_SECURE_NO_WARNINGS 1
#define UNUSED(a) (void)a
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) < (b) ? (b) : (a))
#define LEN(a) (sizeof(a) / sizeof(a)[0])
#include "overlay.h"
#include "nuklear-glfw-vulkan.h"
#include <string.h>
#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600
#define MAX_VERTEX_BUFFER 512 * 1024
#define MAX_ELEMENT_BUFFER 128 * 1024
GLFWwindow *win;
struct nk_context *ctx;
struct nk_color background;
struct nk_font_atlas *atlas;
void init_overlay(GLFWwindow *_win, VkDevice logical_device,
VkPhysicalDevice physical_device,
uint32_t graphics_queue_family_index, VkQueue graphics_queue,
VkImageView *image_views, uint32_t image_views_len,
uint32_t width, uint32_t height, VkFormat color_format) {
win = _win;
ctx = nk_glfw3_init(win, logical_device, physical_device,
graphics_queue_family_index, image_views, image_views_len,
width, height, color_format, NK_GLFW3_INSTALL_CALLBACKS);
// /* Load Fonts: if none of these are loaded a default font will be used */
// /* Load Cursor: if you uncomment cursor loading please hide the cursor */
{
nk_glfw3_font_stash_begin(&atlas);
/*struct nk_font *droid = nk_font_atlas_add_from_file(atlas,
* "../../../extra_font/DroidSans.ttf", 14, 0);*/
/*struct nk_font *roboto = nk_font_atlas_add_from_file(atlas,
* "../../../extra_font/Roboto-Regular.ttf", 14, 0);*/
/*struct nk_font *future = nk_font_atlas_add_from_file(atlas,
* "../../../extra_font/kenvector_future_thin.ttf", 13, 0);*/
/*struct nk_font *clean = nk_font_atlas_add_from_file(atlas,
* "../../../extra_font/ProggyClean.ttf", 12, 0);*/
/*struct nk_font *tiny = nk_font_atlas_add_from_file(atlas,
* "../../../extra_font/ProggyTiny.ttf", 10, 0);*/
/*struct nk_font *cousine = nk_font_atlas_add_from_file(atlas,
* "../../../extra_font/Cousine-Regular.ttf", 13, 0);*/
nk_glfw3_font_stash_end(graphics_queue);
/*nk_style_load_all_cursors(ctx, atlas->cursors);*/
/*nk_style_set_font(ctx, &droid->handle);*/
/* style.c */
/*set_style(ctx, THEME_WHITE);*/
/*set_style(ctx, THEME_RED);*/
/*set_style(ctx, THEME_BLUE);*/
/*set_style(ctx, THEME_DARK);*/
}
}
// NK_API void ;
void resize_overlay(uint32_t width, uint32_t height) {
nk_glfw3_resize(width, height);
}
VkSemaphore submit_overlay(struct overlay_settings *settings,
VkQueue graphics_queue, uint32_t buffer_index,
VkSemaphore wait_semaphore) {
struct nk_colorf background = {settings->bg_color[0], settings->bg_color[1],
settings->bg_color[2], settings->bg_color[3]};
/* Input */
glfwPollEvents();
nk_glfw3_new_frame();
/* GUI */
if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250),
NK_WINDOW_BORDER | NK_WINDOW_MOVABLE | NK_WINDOW_SCALABLE |
NK_WINDOW_MINIMIZABLE | NK_WINDOW_TITLE)) {
nk_layout_row_static(ctx, 30, 80, 1);
if (nk_button_label(ctx, "button"))
fprintf(stdout, "button pressed\n");
nk_layout_row_dynamic(ctx, 30, 2);
if (nk_option_label(ctx, "up", settings->orientation == UP))
settings->orientation = UP;
if (nk_option_label(ctx, "down", settings->orientation == DOWN))
settings->orientation = DOWN;
nk_layout_row_dynamic(ctx, 25, 1);
nk_property_int(ctx, "Zoom:", 0, &settings->zoom, 100, 10, 1);
nk_layout_row_dynamic(ctx, 20, 1);
nk_label(ctx, "background:", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 25, 1);
if (nk_combo_begin_color(ctx, nk_rgb_cf(background),
nk_vec2(nk_widget_width(ctx), 400))) {
nk_layout_row_dynamic(ctx, 120, 1);
background = nk_color_picker(ctx, background, NK_RGBA);
nk_layout_row_dynamic(ctx, 25, 1);
nk_combo_end(ctx);
}
}
nk_end(ctx);
/* -------------- EXAMPLES ---------------- */
/*calculator(ctx);*/
/*overview(ctx);*/
/*node_editor(ctx);*/
/* ----------------------------------------- */
/* Draw */
// {float bg[4];
// nk_color_fv(bg, background);
// glfwGetWindowSize(win, &width, &height);
// glViewport(0, 0, width, height);
// glClear(GL_COLOR_BUFFER_BIT);
// glClearColor(bg[0], bg[1], bg[2], bg[3]);
// /* IMPORTANT: `nk_glfw_render` modifies some global OpenGL state
// * with blending, scissor, face culling, depth test and viewport and
// * defaults everything back into a default state.
// * Make sure to either a.) save and restore or b.) reset your own state
// after
// * rendering the UI. */
// nk_glfw3_render(NK_ANTI_ALIASING_ON, MAX_VERTEX_BUFFER,
// MAX_ELEMENT_BUFFER); glfwSwapBuffers(win);}
// }
// glfwTerminate();
// return 0;
settings->bg_color[0] = background.r;
settings->bg_color[1] = background.g;
settings->bg_color[2] = background.b;
settings->bg_color[3] = background.a;
return nk_glfw3_render(NK_ANTI_ALIASING_ON, graphics_queue, buffer_index,
wait_semaphore);
}
void shutdown_overlay() { nk_glfw3_shutdown(); }