Skip to content

Commit

Permalink
Allow window resizing
Browse files Browse the repository at this point in the history
Support window resizing by automatically updating the saved width/height
of the window and rendering with that size without the need of
reallocating the internal texture.

Resolze #73
  • Loading branch information
alanjian85 committed Nov 5, 2022
1 parent e33382f commit 88650df
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/syscall_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static bool check_sdl(struct riscv_t *rv, uint32_t width, uint32_t height)
}
window = SDL_CreateWindow("rv32emu", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, width, height,
0 /* flags */);
SDL_WINDOW_RESIZABLE /* flags */);
if (!window) {
fprintf(stderr, "Window could not be created! SDL_Error: %s\n",
SDL_GetError());
Expand Down Expand Up @@ -231,7 +231,10 @@ void syscall_draw_frame(struct riscv_t *rv)
memory_read(s->mem, pixels_ptr, screen, width * height * 4);
SDL_UnlockTexture(texture);

SDL_RenderCopy(renderer, texture, NULL, &(SDL_Rect){0, 0, width, height});
int actual_width, actual_height;
SDL_GetWindowSize(window, &actual_width, &actual_height);
SDL_RenderCopy(renderer, texture, NULL,
&(SDL_Rect){0, 0, actual_width, actual_height});
SDL_RenderPresent(renderer);
}

Expand Down

0 comments on commit 88650df

Please sign in to comment.