-
Notifications
You must be signed in to change notification settings - Fork 580
Rob Loach edited this page Mar 16, 2024
·
1 revision
This provides some information about how to use Nuklear with SDL.
This shows how to display an SDL_Surface
within an nk_image
:
SDL_Surface *hammer_surface;
SDL_Texture *hammer_texture;
struct nk_image hammer_image;
/* Create an SDL_Texture from an SDL_Surface, then convert it to an nk_image */
hammer_surface = SDL_LoadBMP("hammer.bmp");
if (hammer_surface == NULL) {
printf("Error SDL_LoadBMP %s\n (ensure you are running the binary from the demo/sdl_renderer/ folder)\n", SDL_GetError());
exit(-1);
}
hammer_texture = SDL_CreateTextureFromSurface(renderer, hammer_surface);
if (hammer_texture == NULL) {
printf("Error SDL_CreateTextureFromSurface %s\n", SDL_GetError());
exit(-1);
}
hammer_image = nk_image_ptr(hammer_texture);
SDL_FreeSurface(hammer_surface);
/* Display the image in a button */
nk_layout_row_dynamic(ctx, 50, 1);
if (nk_button_image_label(ctx, hammer_image, "icon button", NK_TEXT_CENTERED))
fprintf(stdout, "icon button pressed\n");
/* Cleanup */
SDL_DestroyTexture(hammer_texture);