nesemu/gui/main_window.c

49 lines
1.4 KiB
C
Raw Normal View History

2024-06-16 19:22:40 -04:00
//
// Created by william on 6/8/24.
//
#include <SDL_ttf.h>
#include "main_window.h"
#include "log.h"
#include "char_map.h"
#include "gui.h"
2024-07-25 21:22:00 -04:00
void main_window_init(NesMainWindow *window) {
2024-06-16 19:22:40 -04:00
window->sdl_context = window_init("NES Emulator", MAIN_WINDOW_WIDTH, MAIN_WINDOW_HEIGHT, MAIN_WINDOW_SCALE);
window->texture = SDL_CreateTexture(window->sdl_context.renderer, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING, MAIN_WINDOW_WIDTH, MAIN_WINDOW_HEIGHT);
}
void main_window_uninit(NesMainWindow *window) {
SDL_DestroyTexture(window->texture);
window_uninit(window->sdl_context);
}
2024-07-25 21:22:00 -04:00
#if DEBUG
2024-06-16 19:22:40 -04:00
void main_window_render_delay(SDL_Renderer *renderer) {
Uint32 delay = gui_get_frame_delay();
char buffer[5];
buffer[0] = (char) ((delay / 10) + 48);
buffer[1] = (char) ((delay % 10) + 48);
buffer[2] = ' ';
buffer[3] = 'm';
buffer[4] = 's';
char_map_render(renderer, buffer);
}
2024-07-25 21:22:00 -04:00
#endif
2024-06-16 19:22:40 -04:00
2024-08-17 17:38:15 -04:00
void main_window_render(NesMainWindow *window, pixel *pixels) {
2024-06-16 19:22:40 -04:00
SDL_RenderClear(window->sdl_context.renderer);
SDL_UpdateTexture(window->texture, NULL, pixels, 240 * sizeof(unsigned int));
2024-06-16 19:22:40 -04:00
SDL_RenderCopy(window->sdl_context.renderer, window->texture, NULL, NULL);
2024-07-25 21:22:00 -04:00
#if DEBUG
main_window_render_delay(window->sdl_context.renderer);
#endif
2024-06-16 19:22:40 -04:00
}
void main_window_present(NesMainWindow *window) {
SDL_RenderPresent(window->sdl_context.renderer);
}