- A que huelen los commits?
This commit is contained in:
@@ -15,6 +15,15 @@ namespace draw
|
|||||||
SDL_Texture *sdl_texture {nullptr}; // La textura de SDL a la que pintarem la nostra superficie "screen" i que despres volcarem a pantalla
|
SDL_Texture *sdl_texture {nullptr}; // La textura de SDL a la que pintarem la nostra superficie "screen" i que despres volcarem a pantalla
|
||||||
|
|
||||||
static int screen_zoom = 1;
|
static int screen_zoom = 1;
|
||||||
|
static bool screen_fullscreen = false;
|
||||||
|
static float window_ratio = 1;
|
||||||
|
static int canvas_width;
|
||||||
|
static int canvas_height;
|
||||||
|
static int desktop_width;
|
||||||
|
static int desktop_height;
|
||||||
|
static int window_width;
|
||||||
|
static int window_height;
|
||||||
|
char window_title[256];
|
||||||
|
|
||||||
surface *screen {nullptr}; // La superficie screen, que representa la pantalla. Se crea i destrueix internament
|
surface *screen {nullptr}; // La superficie screen, que representa la pantalla. Se crea i destrueix internament
|
||||||
surface *destination {nullptr}; // Punter a la actual superficie de destí
|
surface *destination {nullptr}; // Punter a la actual superficie de destí
|
||||||
@@ -34,26 +43,72 @@ namespace draw
|
|||||||
bool fading_out = false;
|
bool fading_out = false;
|
||||||
bool fading_in = false;
|
bool fading_in = false;
|
||||||
|
|
||||||
|
void createDisplay()
|
||||||
|
{
|
||||||
|
// Ajustem el zoom i el ratio, per si tenen valors locs
|
||||||
|
if (screen_zoom <= 0) screen_zoom = 1;
|
||||||
|
if (window_ratio <= 0) window_ratio = 1;
|
||||||
|
|
||||||
|
// Ajustem el tamany de la finestra, segons el zoom i el ratio
|
||||||
|
window_width = canvas_width*screen_zoom;
|
||||||
|
window_height = window_ratio != 1 ? canvas_width*window_ratio*screen_zoom : canvas_height*screen_zoom;
|
||||||
|
|
||||||
|
// Mentres no càpiga en la pantalla, reduïm el zoom
|
||||||
|
while (window_width > desktop_width || window_height > desktop_height) {
|
||||||
|
screen_zoom--;
|
||||||
|
window_width = canvas_width*screen_zoom;
|
||||||
|
window_height = window_ratio != 1 ? canvas_width*window_ratio*screen_zoom : canvas_height*screen_zoom;
|
||||||
|
}
|
||||||
|
|
||||||
|
sdl_window = SDL_CreateWindow(window_title, window_width, window_height, SDL_WINDOW_OPENGL|(screen_fullscreen?SDL_WINDOW_FULLSCREEN:0));
|
||||||
|
if (!sdl_window) {
|
||||||
|
SDL_LogCritical(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize window!\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void destroyDisplay()
|
||||||
|
{
|
||||||
|
SDL_DestroyTexture(sdl_texture);
|
||||||
|
SDL_DestroyRenderer(sdl_renderer);
|
||||||
|
SDL_DestroyWindow(sdl_window);
|
||||||
|
}
|
||||||
|
|
||||||
// Inicialització de tot el que fa falta per a carregar gràfics i pintar en pantalla
|
// Inicialització de tot el que fa falta per a carregar gràfics i pintar en pantalla
|
||||||
void init(const char *titol, const uint16_t width, const uint16_t height, const int zoom)
|
void init(const char *titol, const uint16_t width, const uint16_t height, const int zoom, const bool fullscreen, const float ratio)
|
||||||
{
|
{
|
||||||
screen_zoom = zoom;
|
screen_zoom = zoom;
|
||||||
|
window_ratio = ratio;
|
||||||
|
canvas_width = width;
|
||||||
|
canvas_height = height;
|
||||||
|
strcpy(window_title, titol);
|
||||||
|
|
||||||
// [TODO] Incloure gestió de pantalla completa
|
const SDL_DisplayMode *dm = SDL_GetDesktopDisplayMode(SDL_GetPrimaryDisplay());
|
||||||
|
if (!dm)
|
||||||
|
{
|
||||||
|
SDL_Log("SDL_GetDesktopDisplayMode failed: %s", SDL_GetError());
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
desktop_width = dm->w;
|
||||||
|
desktop_height = dm->h;
|
||||||
|
|
||||||
// Inicialització de les estructures de SDL
|
// Inicialització de les estructures de SDL
|
||||||
sdl_window = SDL_CreateWindow(titol, width * zoom, height * zoom, 0);
|
sdl_window = SDL_CreateWindow(titol, width * zoom, height * zoom, 0);
|
||||||
if (!sdl_window) {
|
if (!sdl_window) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize window!\n"); exit(1);
|
SDL_LogCritical(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize window!\n");
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
sdl_renderer = SDL_CreateRenderer(sdl_window, NULL);
|
sdl_renderer = SDL_CreateRenderer(sdl_window, NULL);
|
||||||
if (!sdl_renderer) {
|
if (!sdl_renderer) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize renderer!\n"); exit(1);
|
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize renderer!\n");
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height);
|
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height);
|
||||||
SDL_SetTextureScaleMode(sdl_texture, SDL_SCALEMODE_NEAREST);
|
SDL_SetTextureScaleMode(sdl_texture, SDL_SCALEMODE_NEAREST);
|
||||||
if (!sdl_texture) {
|
if (!sdl_texture) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize texture!\n"); exit(1);
|
SDL_LogError(SDL_LOG_CATEGORY_VIDEO, "ERROR (draw::init): Failed to initialize texture!\n");
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creem la superficie "screen" i la establim com a superficie destinació
|
// Creem la superficie "screen" i la establim com a superficie destinació
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace draw
|
|||||||
/// @param width es el ample de la finestra "virtual"
|
/// @param width es el ample de la finestra "virtual"
|
||||||
/// @param height es el alt de la finestra "virtual"
|
/// @param height es el alt de la finestra "virtual"
|
||||||
/// @param zoom es com de grans son els pixels.
|
/// @param zoom es com de grans son els pixels.
|
||||||
void init(const char *titol, const uint16_t width, const uint16_t height, const int zoom);
|
void init(const char *titol, const uint16_t width, const uint16_t height, const int zoom, const float ratio=1.0);
|
||||||
|
|
||||||
/// @brief Finalització del sistema (tancar coses de SDL, superficies fixes, etc...)
|
/// @brief Finalització del sistema (tancar coses de SDL, superficies fixes, etc...)
|
||||||
void quit();
|
void quit();
|
||||||
|
|||||||
@@ -55,6 +55,12 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
|
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
SDL_SetLogPriorities(SDL_LOG_PRIORITY_DEBUG);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
SDL_LogInfo(SDL_LOG_CATEGORY_SYSTEM, "JAPI v%s\n", JAPI_VERSION);
|
||||||
|
|
||||||
game::windowHasFocus = true;
|
game::windowHasFocus = true;
|
||||||
game::init();
|
game::init();
|
||||||
input::init(draw::getZoom());
|
input::init(draw::getZoom());
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
#include "jaudio.h"
|
#include "jaudio.h"
|
||||||
#include "jfile.h"
|
#include "jfile.h"
|
||||||
|
|
||||||
|
#define JAPI_VERSION "0.8"
|
||||||
|
|
||||||
namespace game
|
namespace game
|
||||||
{
|
{
|
||||||
extern bool windowHasFocus;
|
extern bool windowHasFocus;
|
||||||
|
|||||||
Reference in New Issue
Block a user