#include "draw.h" #include #include "gif.h" #include "file.h" namespace draw { SDL_Window *sdl_window {nullptr}; // La finestra de SDL SDL_Renderer *sdl_renderer {nullptr}; // El renderer de SDL SDL_Texture *sdl_texture {nullptr}; // La textura a la que ho renderitze tot SDL_Texture *sdl_source {nullptr}; void init(const char *titol, const uint16_t width, const uint16_t height) { sdl_window = SDL_CreateWindow(titol, width, height, SDL_WINDOW_RESIZABLE); if (!sdl_window) { SDL_LogCritical(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize window!\n"); exit(1); } printf("AVAILABLE RENDER DRIVERS:\n"); for (int i=0; i>16)&0xff, (col>>8)&0xff, (col)&0xff, (col>>24)&0xff); } void cls(const uint32_t color) { setColor(color); SDL_RenderClear(sdl_renderer); } void line(const int x1, const int y1, const int x2, const int y2) { SDL_RenderLine(sdl_renderer, x1, y1, x2, y2); } void fillrect(const int x, const int y, const int w, const int h) { SDL_FRect rect {float(x), float(y), float(w),float(h)}; SDL_RenderFillRect(sdl_renderer, &rect); } void rect(const int x, const int y, const int w, const int h) { SDL_FRect rect {float(x), float(y), float(w),float(h)}; SDL_RenderRect(sdl_renderer, &rect); } void draw(const SDL_Rect source, const SDL_Rect dest, const SDL_FlipMode flip) { if (!sdl_source) return; SDL_FRect src {float(source.x), float(source.y), float(source.w),float(source.h)}; SDL_FRect dst {float(dest.x), float(dest.y), float(dest.w),float(dest.h)}; SDL_RenderTextureRotated(sdl_renderer, sdl_source, &src, &dst, 0.0, nullptr, flip); } /* void draw(const int dx, const int dy, const int w, const int h, const int sx, const int sy, const int zoom) { // Si no hi ha superficie d'oritge especificada, no fem res, o petarà el mame if (source == nullptr) return; for (int y=0; yw, source->h, 0, 0); } // Pinta tota la superficie "source" en la superficie "destination", posició (0,0) void draw() { draw(0,0,source->w, source->h, 0, 0); } // Carrega la superficie especificada en "source" i la pinta tota en la superficie "destination", posició (0,0). void draw(SDL_Texture* surf) { setSource(surf); draw(); } */ // Refresca la pantalla void render() { SDL_SetRenderTarget(sdl_renderer, nullptr); SDL_RenderTexture(sdl_renderer, sdl_texture, nullptr, nullptr); SDL_RenderPresent(sdl_renderer); SDL_SetRenderTarget(sdl_renderer, sdl_texture); } }