demo: Quality of Life updates

- Meaningful titles across all Demos
- Switch to CTRL+Q to exit the demos
This commit is contained in:
Robert Winkler
2026-04-20 10:07:02 -04:00
committed by GitHub
parent 409de195d1
commit 063968520f
24 changed files with 119 additions and 48 deletions
+6 -2
View File
@@ -100,6 +100,7 @@ int main(void)
al_set_mouse_wheel_precision(150);
al_install_keyboard();
al_set_new_window_title("allegro5");
al_set_new_display_flags(ALLEGRO_WINDOWED|ALLEGRO_RESIZABLE|ALLEGRO_OPENGL);
al_set_new_display_option(ALLEGRO_SAMPLE_BUFFERS, 1, ALLEGRO_SUGGEST);
al_set_new_display_option(ALLEGRO_SAMPLES, 8, ALLEGRO_SUGGEST);
@@ -133,8 +134,11 @@ int main(void)
get_event = al_wait_for_event_until(event_queue, &ev, &timeout);
if (get_event && ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) {
break;
if (get_event) {
if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE ||
(ev.keyboard.keycode == ALLEGRO_KEY_Q && ev.keyboard.modifiers & ALLEGRO_KEYMOD_CTRL)) {
break;
}
}
/* Very Important: Always do nk_input_begin / nk_input_end even if
+5 -5
View File
@@ -890,7 +890,7 @@ overview(struct nk_context *ctx)
"BOTTOM_CENTER",
"BOTTOM_RIGHT"
};
static int cur_pos = NK_TOP_LEFT;
int cur_pos = NK_TOP_LEFT;
if (!text_initialized) {
const char text_default[] = "you can customize this!";
@@ -902,7 +902,7 @@ overview(struct nk_context *ctx)
bounds = nk_widget_bounds(ctx);
nk_label(ctx, "Hover for custom tooltip (you can customize it below)", NK_TEXT_LEFT);
if (nk_input_is_mouse_hovering_rect(in, bounds)) {
nk_tooltip_offset(ctx, text_buf, cur_pos, offset);
nk_tooltip_offset(ctx, text_buf, (enum nk_tooltip_pos)cur_pos, offset);
}
nk_layout_row_dynamic(ctx, 1, 1);
nk_rule_horizontal(ctx, nk_white, nk_true);
@@ -1445,11 +1445,11 @@ overview(struct nk_context *ctx)
nk_layout_row_dynamic(ctx, 20, 2);
for (i = 0; i < NK_BUTTON_MAX; i++) {
nk_label(ctx, button_names[i], NK_TEXT_LEFT);
if (nk_input_is_mouse_pressed(in, i))
if (nk_input_is_mouse_pressed(in, (enum nk_buttons)i))
nk_label(ctx, "Pressed", NK_TEXT_LEFT);
else if (nk_input_is_mouse_down(in, i))
else if (nk_input_is_mouse_down(in, (enum nk_buttons)i))
nk_label(ctx, "Down", NK_TEXT_LEFT);
else if (nk_input_is_mouse_released(in, i))
else if (nk_input_is_mouse_released(in, (enum nk_buttons)i))
nk_label(ctx, "Released", NK_TEXT_LEFT);
else
nk_label(ctx, "Up", NK_TEXT_LEFT);
+2
View File
@@ -228,6 +228,8 @@ int main(void)
{
if (msg.message == WM_QUIT)
running = 0;
if (msg.message == WM_SYSKEYDOWN && msg.wParam == 'Q' && GetKeyState(VK_CONTROL) & (1 << 15))
running = 0;
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
+4 -2
View File
@@ -1,7 +1,7 @@
/* nuklear - 1.32.0 - public domain */
/*
* === IMPORTATE NOTE FOR D3D12 ===
* === IMPORTATE NOTE FOR D3D12 ===
*
* Due to a bug in the Windows SDK that
* was fixed in version 10.0.22000.0 the
@@ -9,7 +9,7 @@
* a minimum! Compiling with a lower version
* will result in compiler warnings and a
* crashing application!
*
*
*/
#define COBJMACROS
@@ -333,6 +333,8 @@ int main(void)
{
if (msg.message == WM_QUIT)
running = 0;
if (msg.message == WM_SYSKEYDOWN && msg.wParam == 'Q' && GetKeyState(VK_CONTROL) & (1 << 15))
running = 0;
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
+2
View File
@@ -233,6 +233,8 @@ int main(void)
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT)
running = 0;
if (msg.message == WM_SYSKEYDOWN && msg.wParam == 'Q' && GetKeyState(VK_CONTROL) & (1 << 15))
running = 0;
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
+4 -2
View File
@@ -129,9 +129,11 @@ int main(void)
MSG msg;
nk_input_begin(ctx);
if (needs_refresh == 0) {
if (GetMessageW(&msg, NULL, 0, 0) <= 0)
if (GetMessageW(&msg, NULL, 0, 0) <= 0) {
running = 0;
else {
} else if (msg.message == WM_SYSKEYDOWN && msg.wParam == 'Q' && GetKeyState(VK_CONTROL) & (1 << 15))
running = 0;
} else {
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
+2
View File
@@ -136,6 +136,8 @@ int main(void)
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
if (msg.message == WM_QUIT)
running = 0;
if (msg.message == WM_SYSKEYDOWN && msg.wParam == 'Q' && GetKeyState(VK_CONTROL) & (1 << 15))
running = 0;
TranslateMessage(&msg);
DispatchMessageW(&msg);
needs_refresh = 1;
+6 -1
View File
@@ -110,7 +110,7 @@ int main(void)
fprintf(stdout, "[GFLW] failed to init!\n");
exit(1);
}
win = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Demo", NULL, NULL);
win = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "glfw_opengl2", NULL, NULL);
glfwMakeContextCurrent(win);
glfwGetWindowSize(win, &width, &height);
@@ -154,6 +154,11 @@ int main(void)
{
/* Input */
glfwPollEvents();
if (glfwGetKey(win, GLFW_KEY_Q) == GLFW_PRESS &&
(glfwGetKey(win, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS ||
glfwGetKey(win, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS)) {
glfwSetWindowShouldClose(win, nk_true);
}
nk_glfw3_new_frame();
/* GUI */
+6 -1
View File
@@ -107,7 +107,7 @@ int main(void)
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
win = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Demo", NULL, NULL);
win = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "glfw_opengl3", NULL, NULL);
glfwMakeContextCurrent(win);
glfwGetWindowSize(win, &width, &height);
@@ -139,6 +139,11 @@ int main(void)
{
/* Input */
glfwPollEvents();
if (glfwGetKey(win, GLFW_KEY_Q) == GLFW_PRESS &&
(glfwGetKey(win, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS ||
glfwGetKey(win, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS)) {
glfwSetWindowShouldClose(win, nk_true);
}
nk_glfw3_new_frame(&glfw);
/* GUI */
+6 -1
View File
@@ -107,7 +107,7 @@ int main(void)
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
#endif
win = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Demo", NULL, NULL);
win = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "glfw_opengl4", NULL, NULL);
glfwMakeContextCurrent(win);
glfwGetWindowSize(win, &width, &height);
@@ -149,6 +149,11 @@ int main(void)
{
/* Input */
glfwPollEvents();
if (glfwGetKey(win, GLFW_KEY_Q) == GLFW_PRESS &&
(glfwGetKey(win, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS ||
glfwGetKey(win, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS)) {
glfwSetWindowShouldClose(win, nk_true);
}
nk_glfw3_new_frame();
/* GUI */
+17 -12
View File
@@ -818,7 +818,7 @@ bool create_swap_chain(struct vulkan_demo *demo) {
}
create_info.preTransform = swap_chain_support.capabilities.currentTransform;
if(swap_chain_support.capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR) {
create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
} else if(swap_chain_support.capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR) {
@@ -828,7 +828,7 @@ bool create_swap_chain(struct vulkan_demo *demo) {
} else if(swap_chain_support.capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR) {
create_info.compositeAlpha = VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR;
}
create_info.presentMode = present_mode;
create_info.clipped = VK_TRUE;
@@ -1504,12 +1504,12 @@ bool create_semaphores(struct vulkan_demo *demo) {
VkSemaphoreCreateInfo semaphore_info;
VkResult result;
uint32_t i;
demo->image_available = (VkSemaphore*)malloc(MAX_IN_FLIGHT_FRAMES * sizeof(VkSemaphore));
demo->render_finished = (VkSemaphore*)malloc(demo->swap_chain_images_len * sizeof(VkSemaphore));
memset(&semaphore_info, 0, sizeof(VkSemaphoreCreateInfo));
semaphore_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
for(i = 0; i < MAX_IN_FLIGHT_FRAMES; i++) {
result = vkCreateSemaphore(demo->device, &semaphore_info, NULL,
&demo->image_available[i]);
@@ -1533,13 +1533,13 @@ bool create_fence(struct vulkan_demo *demo) {
VkResult result;
VkFenceCreateInfo fence_create_info;
uint32_t i;
demo->render_fence = (VkFence*)malloc(MAX_IN_FLIGHT_FRAMES * sizeof(VkFence));
memset(&fence_create_info, 0, sizeof(VkFenceCreateInfo));
fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fence_create_info.flags = VK_FENCE_CREATE_SIGNALED_BIT;
for(i = 0; i < MAX_IN_FLIGHT_FRAMES; i++) {
result = vkCreateFence(demo->device, &fence_create_info, NULL,
&demo->render_fence[i]);
@@ -2056,22 +2056,22 @@ bool cleanup(struct vulkan_demo *demo) {
MAX_IN_FLIGHT_FRAMES, demo->command_buffers);
vkDestroyCommandPool(demo->device, demo->command_pool, NULL);
vkDestroySampler(demo->device, demo->sampler, NULL);
for(i = 0; i < demo->swap_chain_images_len; i++)
vkDestroySemaphore(demo->device, demo->render_finished[i], NULL);
if(demo->render_finished)
free(demo->render_finished);
for(i = 0; i < MAX_IN_FLIGHT_FRAMES; i++)
vkDestroySemaphore(demo->device, demo->image_available[i], NULL);
if(demo->image_available)
free(demo->image_available);
for(i = 0; i < MAX_IN_FLIGHT_FRAMES; i++)
vkDestroyFence(demo->device, demo->render_fence[i], NULL);
if(demo->render_fence)
free(demo->render_fence);
vkDestroyImage(demo->device, demo->demo_texture_image, NULL);
vkDestroyImageView(demo->device, demo->demo_texture_image_view, NULL);
vkFreeMemory(demo->device, demo->demo_texture_memory, NULL);
@@ -2144,7 +2144,7 @@ int main(void) {
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
memset(&demo, 0, sizeof(struct vulkan_demo));
demo.win =
glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Demo", NULL, NULL);
glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "glfw_vulkan", NULL, NULL);
glfwSetWindowUserPointer(demo.win, &demo);
glfwSetFramebufferSizeCallback(demo.win, glfw_framebuffer_resize_callback);
@@ -2183,6 +2183,11 @@ int main(void) {
while (!glfwWindowShouldClose(demo.win)) {
/* Input */
glfwPollEvents();
if (glfwGetKey(demo.win, GLFW_KEY_Q) == GLFW_PRESS &&
(glfwGetKey(demo.win, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS ||
glfwGetKey(demo.win, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS)) {
glfwSetWindowShouldClose(demo.win, nk_true);
}
nk_glfw3_new_frame();
/* GUI */
@@ -2252,7 +2257,7 @@ int main(void) {
result = vkWaitForFences(demo.device, 1, &demo.render_fence[demo.current_in_flight_frame], VK_TRUE,
UINT64_MAX);
if (result != VK_SUCCESS) {
fprintf(stderr, "vkWaitForFences failed: %d\n", result);
return false;
+2 -1
View File
@@ -170,7 +170,7 @@ int main(int argc, char **argv)
printf("desktop display mode %d %d\n", dm.w, dm.h);
window = SDL_CreateWindow("Puzzle", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, dm.w-200,dm.h-200, SDL_WINDOW_OPENGL);
window = SDL_CreateWindow("rawfb sdl", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, dm.w-200,dm.h-200, SDL_WINDOW_OPENGL);
if (!window)
{
printf("can't open window!\n");
@@ -207,6 +207,7 @@ int main(int argc, char **argv)
exit(0);
break;
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_q && SDL_GetModState() & KMOD_CTRL) exit(0);
nk_input_key(&(context->ctx), translate_sdl_key(&event.key.keysym), 1);
break;
case SDL_KEYUP:
+8 -1
View File
@@ -188,7 +188,7 @@ main(void)
XDefaultDepth(xw.dpy, xw.screen), InputOutput,
xw.vis, CWEventMask | CWColormap, &xw.swa);
XStoreName(xw.dpy, xw.win, "X11");
XStoreName(xw.dpy, xw.win, "rawfb X11");
XMapWindow(xw.dpy, xw.win);
XGetWindowAttributes(xw.dpy, xw.win, &xw.attr);
xw.width = (unsigned int)xw.attr.width;
@@ -209,6 +209,12 @@ main(void)
started = timestamp();
nk_input_begin(&rawfb->ctx);
while (XCheckWindowEvent(xw.dpy, xw.win, xw.swa.event_mask, &evt)) {
if (evt.type == ClientMessage) goto cleanup;
if (evt.type == KeyPress) {
int ret;
KeySym *code = XGetKeyboardMapping(xw.dpy, (KeyCode)evt.xkey.keycode, 1, &ret);
if (*code == 'q' && (evt.xkey.state & ControlMask)) goto cleanup;
}
if (XFilterEvent(&evt, xw.win)) continue;
nk_xlib_handle_event(xw.dpy, xw.screen, xw.win, &evt, rawfb);
}
@@ -266,6 +272,7 @@ main(void)
sleep_for(DTIME - dt);
}
cleanup:
nk_rawfb_shutdown(rawfb);
nk_xlib_shutdown();
XUnmapWindow(xw.dpy, xw.win);
+5
View File
@@ -300,6 +300,11 @@ SDL_AppEvent(void *appstate, SDL_Event* event)
switch (event->type) {
case SDL_EVENT_QUIT:
return SDL_APP_SUCCESS;
case SDL_EVENT_KEY_DOWN:
if (event->key.key == SDLK_Q && event->key.mod & SDL_KMOD_CTRL) {
return SDL_APP_SUCCESS;
}
break;
case SDL_EVENT_WINDOW_DISPLAY_SCALE_CHANGED:
/* You may wish to rescale the renderer and Nuklear during this event.
* Without this the UI and Font could appear too small or too big.
+2 -1
View File
@@ -104,7 +104,7 @@ main(int argc, char *argv[])
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
win = SDL_CreateWindow("Demo",
win = SDL_CreateWindow("sdl_opengl2",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN|SDL_WINDOW_ALLOW_HIGHDPI);
glContext = SDL_GL_CreateContext(win);
@@ -134,6 +134,7 @@ main(int argc, char *argv[])
nk_input_begin(ctx);
while (SDL_PollEvent(&evt)) {
if (evt.type == SDL_QUIT) goto cleanup;
if (evt.type == SDL_KEYDOWN && evt.key.keysym.sym == SDLK_q && SDL_GetModState() & KMOD_CTRL) goto cleanup;
nk_sdl_handle_event(&evt);
}
nk_sdl_handle_grab(); /* optional grabbing behavior */
+2 -1
View File
@@ -107,7 +107,7 @@ int main(int argc, char *argv[])
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
win = SDL_CreateWindow("Demo",
win = SDL_CreateWindow("sdl_opengl3",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN|SDL_WINDOW_ALLOW_HIGHDPI);
glContext = SDL_GL_CreateContext(win);
@@ -158,6 +158,7 @@ int main(int argc, char *argv[])
nk_input_begin(ctx);
while (SDL_PollEvent(&evt)) {
if (evt.type == SDL_QUIT) goto cleanup;
if (evt.type == SDL_KEYDOWN && evt.key.keysym.sym == SDLK_q && SDL_GetModState() & KMOD_CTRL) goto cleanup;
nk_sdl_handle_event(&evt);
}
nk_sdl_handle_grab(); /* optional grabbing behavior */
+2 -1
View File
@@ -99,6 +99,7 @@ MainLoop(void* loopArg){
nk_input_begin(ctx);
while (SDL_PollEvent(&evt)) {
if (evt.type == SDL_QUIT) running = nk_false;
if (evt.type == SDL_KEYDOWN && evt.key.keysym.sym == SDLK_q && SDL_GetModState() & KMOD_CTRL) running = nk_false;
nk_sdl_handle_event(&evt);
}
nk_sdl_handle_grab(); /* optional grabbing behavior */
@@ -198,7 +199,7 @@ int main(int argc, char* argv[])
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
win = SDL_CreateWindow("Demo",
win = SDL_CreateWindow("sdl_opengles2",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN|SDL_WINDOW_ALLOW_HIGHDPI);
glContext = SDL_GL_CreateContext(win);
+2 -1
View File
@@ -97,7 +97,7 @@ main(void)
SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "0");
SDL_Init(SDL_INIT_VIDEO);
win = SDL_CreateWindow("Demo",
win = SDL_CreateWindow("sdl_renderer",
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_SHOWN|SDL_WINDOW_ALLOW_HIGHDPI);
@@ -173,6 +173,7 @@ main(void)
nk_input_begin(ctx);
while (SDL_PollEvent(&evt)) {
if (evt.type == SDL_QUIT) goto cleanup;
if (evt.type == SDL_KEYDOWN && evt.key.keysym.sym == SDLK_q && SDL_GetModState() & KMOD_CTRL) goto cleanup;
nk_sdl_handle_event(&evt);
}
nk_sdl_handle_grab(); /* optional grabbing behavior */
+13 -12
View File
@@ -811,7 +811,7 @@ bool create_swap_chain(struct vulkan_demo *demo) {
}
create_info.preTransform = swap_chain_support.capabilities.currentTransform;
if(swap_chain_support.capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR) {
create_info.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
} else if(swap_chain_support.capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR) {
@@ -821,7 +821,7 @@ bool create_swap_chain(struct vulkan_demo *demo) {
} else if(swap_chain_support.capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR) {
create_info.compositeAlpha = VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR;
}
create_info.presentMode = present_mode;
create_info.clipped = VK_TRUE;
@@ -1497,7 +1497,7 @@ bool create_semaphores(struct vulkan_demo *demo) {
VkSemaphoreCreateInfo semaphore_info;
VkResult result;
uint32_t i;
demo->image_available = (VkSemaphore*)malloc(MAX_IN_FLIGHT_FRAMES * sizeof(VkSemaphore));
demo->render_finished = (VkSemaphore*)malloc(demo->swap_chain_images_len * sizeof(VkSemaphore));
memset(&semaphore_info, 0, sizeof(VkSemaphoreCreateInfo));
@@ -1525,13 +1525,13 @@ bool create_fence(struct vulkan_demo *demo) {
VkResult result;
VkFenceCreateInfo fence_create_info;
uint32_t i;
demo->render_fence = (VkFence*)malloc(MAX_IN_FLIGHT_FRAMES * sizeof(VkFence));
memset(&fence_create_info, 0, sizeof(VkFenceCreateInfo));
fence_create_info.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fence_create_info.flags = VK_FENCE_CREATE_SIGNALED_BIT;
for(i = 0; i < MAX_IN_FLIGHT_FRAMES; i++) {
result = vkCreateFence(demo->device, &fence_create_info, NULL,
&demo->render_fence[i]);
@@ -2032,7 +2032,7 @@ destroy_debug_utils_messenger_ext(VkInstance instance,
bool cleanup(struct vulkan_demo *demo) {
VkResult result;
uint32_t i;
printf("cleaning up\n");
result = vkDeviceWaitIdle(demo->device);
if (result != VK_SUCCESS) {
@@ -2046,22 +2046,22 @@ bool cleanup(struct vulkan_demo *demo) {
MAX_IN_FLIGHT_FRAMES, demo->command_buffers);
vkDestroyCommandPool(demo->device, demo->command_pool, NULL);
vkDestroySampler(demo->device, demo->sampler, NULL);
for(i = 0; i < demo->swap_chain_images_len; i++)
vkDestroySemaphore(demo->device, demo->render_finished[i], NULL);
if(demo->render_finished)
free(demo->render_finished);
for(i = 0; i < MAX_IN_FLIGHT_FRAMES; i++)
vkDestroySemaphore(demo->device, demo->image_available[i], NULL);
if(demo->image_available)
free(demo->image_available);
for(i = 0; i < MAX_IN_FLIGHT_FRAMES; i++)
vkDestroyFence(demo->device, demo->render_fence[i], NULL);
if(demo->render_fence)
free(demo->render_fence);
vkDestroyImage(demo->device, demo->demo_texture_image, NULL);
vkDestroyImageView(demo->device, demo->demo_texture_image_view, NULL);
vkFreeMemory(demo->device, demo->demo_texture_memory, NULL);
@@ -2137,7 +2137,7 @@ int main(void) {
memset(&demo, 0, sizeof(struct vulkan_demo));
demo.win = SDL_CreateWindow(
"Demo", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WINDOW_WIDTH,
"sdl_vulkan", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WINDOW_WIDTH,
WINDOW_HEIGHT,
SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
@@ -2180,6 +2180,7 @@ int main(void) {
while (SDL_PollEvent(&evt)) {
if (evt.type == SDL_QUIT)
goto cleanup;
if (evt.type == SDL_KEYDOWN && evt.key.keysym.sym == SDLK_q && SDL_GetModState() & KMOD_CTRL) goto cleanup;
if (evt.type == SDL_WINDOWEVENT &&
evt.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)
recreate_swap_chain(&demo);
@@ -2255,7 +2256,7 @@ int main(void) {
result = vkWaitForFences(demo.device, 1, &demo.render_fence[demo.current_in_flight_frame], VK_TRUE,
UINT64_MAX);
if (result != VK_SUCCESS) {
fprintf(stderr, "vkWaitForFences failed: %d\n", result);
return false;
+3 -1
View File
@@ -79,7 +79,7 @@ int main(void)
{
/* Platform */
sf::ContextSettings settings(24, 8, 4, 2, 2);
sf::Window win(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Demo", sf::Style::Default, settings);
sf::Window win(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "sfml_opengl2", sf::Style::Default, settings);
win.setVerticalSyncEnabled(true);
win.setActive(true);
glViewport(0, 0, win.getSize().x, win.getSize().y);
@@ -116,6 +116,8 @@ int main(void)
while(win.pollEvent(evt)) {
if(evt.type == sf::Event::Closed)
win.close();
else if (evt.type == sf::Event::KeyPressed && evt.key.code == sf::Keyboard::Q && evt.key.control)
win.close();
else if(evt.type == sf::Event::Resized)
glViewport(0, 0, evt.size.width, evt.size.height);
nk_sfml_handle_event(&evt);
+3 -1
View File
@@ -81,7 +81,7 @@ int main(void)
{
/* Platform */
sf::ContextSettings settings(24, 8, 4, 3, 3);
sf::Window win(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "Demo", sf::Style::Default, settings);
sf::Window win(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "sfml_opengl3", sf::Style::Default, settings);
win.setVerticalSyncEnabled(true);
win.setActive(true);
if(!gladLoadGL()) { /* Load OpenGL extensions */
@@ -122,6 +122,8 @@ int main(void)
while(win.pollEvent(evt)) {
if(evt.type == sf::Event::Closed)
win.close();
else if (evt.type == sf::Event::KeyPressed && evt.key.code == sf::Keyboard::Q && evt.key.control)
win.close();
else if(evt.type == sf::Event::Resized)
glViewport(0, 0, evt.size.width, evt.size.height);
+5
View File
@@ -177,6 +177,11 @@ main(void)
while (XPending(xw.dpy)) {
XNextEvent(xw.dpy, &evt);
if (evt.type == ClientMessage) goto cleanup;
if (evt.type == KeyPress) {
int ret;
KeySym *code = XGetKeyboardMapping(xlib.surf->dpy, (KeyCode)evt.xkey.keycode, 1, &ret);
if (*code == 'q' && (evt.xkey.state & ControlMask)) goto cleanup;
}
if (XFilterEvent(&evt, xw.win)) continue;
nk_xlib_handle_event(xw.dpy, xw.screen, xw.win, &evt);
}
+6 -1
View File
@@ -206,7 +206,7 @@ int main(void)
win.vis->visual, CWBorderPixel|CWColormap|CWEventMask, &win.swa);
if (!win.win) die("[X11]: Failed to create window\n");
XFree(win.vis);
XStoreName(win.dpy, win.win, "Demo");
XStoreName(win.dpy, win.win, "x11_opengl2");
XMapWindow(win.dpy, win.win);
win.wm_delete_window = XInternAtom(win.dpy, "WM_DELETE_WINDOW", False);
XSetWMProtocols(win.dpy, win.win, &win.wm_delete_window, 1);
@@ -275,6 +275,11 @@ int main(void)
while (XPending(win.dpy)) {
XNextEvent(win.dpy, &evt);
if (evt.type == ClientMessage) goto cleanup;
if (evt.type == KeyPress) {
int ret;
KeySym *code = XGetKeyboardMapping(x11.dpy, (KeyCode)evt.xkey.keycode, 1, &ret);
if (*code == 'q' && (evt.xkey.state & ControlMask)) goto cleanup;
}
if (XFilterEvent(&evt, win.win)) continue;
nk_x11_handle_event(&evt);
}
+6 -1
View File
@@ -204,7 +204,7 @@ int main(void)
win.vis->visual, CWBorderPixel|CWColormap|CWEventMask, &win.swa);
if (!win.win) die("[X11]: Failed to create window\n");
XFree(win.vis);
XStoreName(win.dpy, win.win, "Demo");
XStoreName(win.dpy, win.win, "x11_opengl3");
XMapWindow(win.dpy, win.win);
win.wm_delete_window = XInternAtom(win.dpy, "WM_DELETE_WINDOW", False);
XSetWMProtocols(win.dpy, win.win, &win.wm_delete_window, 1);
@@ -272,6 +272,11 @@ int main(void)
while (XPending(win.dpy)) {
XNextEvent(win.dpy, &evt);
if (evt.type == ClientMessage) goto cleanup;
if (evt.type == KeyPress) {
int ret;
KeySym *code = XGetKeyboardMapping(x11.dpy, (KeyCode)evt.xkey.keycode, 1, &ret);
if (*code == 'q' && (evt.xkey.state & ControlMask)) goto cleanup;
}
if (XFilterEvent(&evt, win.win)) continue;
nk_x11_handle_event(&evt);
}