- Trabajando en la creación y destrucción de la ventana
- FIX: la clase screen no liberaba la textura gameCanvas al finalizar
This commit is contained in:
@@ -44,10 +44,76 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
|
||||
notifyActive = false;
|
||||
}
|
||||
|
||||
// Crea la ventana
|
||||
void Screen::createDisplay()
|
||||
{
|
||||
window = SDL_CreateWindow(WINDOW_CAPTION, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth * options->windowSize, windowHeight * options->windowSize, SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||
if (window == nullptr)
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Window could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Crea un renderizador para la ventana. El vsync se activa en funcion de las opciones
|
||||
if (options->vSync)
|
||||
{
|
||||
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||
}
|
||||
else
|
||||
{
|
||||
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||
}
|
||||
|
||||
if (renderer == nullptr)
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "Renderer could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Inicializa el color de renderizado
|
||||
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
|
||||
|
||||
// Establece el tamaño del buffer de renderizado
|
||||
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
||||
|
||||
// Establece el modo de mezcla
|
||||
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
|
||||
|
||||
// Muestra el puntero
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
|
||||
// Crea la textura donde se dibujan los graficos del juego
|
||||
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
|
||||
if (gameCanvas == nullptr)
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Destruye la ventana
|
||||
void Screen::destroyDisplay()
|
||||
{
|
||||
SDL_DestroyTexture(gameCanvas);
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Screen::~Screen()
|
||||
{
|
||||
delete notify;
|
||||
SDL_DestroyTexture(gameCanvas);
|
||||
}
|
||||
|
||||
// Limpia la pantalla
|
||||
@@ -86,11 +152,8 @@ void Screen::blit()
|
||||
// Establece el modo de video
|
||||
void Screen::setVideoMode(int videoMode)
|
||||
{
|
||||
// Muestra el puntero
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
|
||||
// Aplica el modo de video
|
||||
SDL_SetWindowFullscreen(window, videoMode);
|
||||
// Destruye la ventana
|
||||
destroyDisplay();
|
||||
|
||||
// Si está activo el modo ventana quita el borde
|
||||
if (videoMode == 0)
|
||||
@@ -109,9 +172,19 @@ void Screen::setVideoMode(int videoMode)
|
||||
dest = {0, 0, gameCanvasWidth, gameCanvasHeight};
|
||||
}
|
||||
|
||||
// Modifica el tamaño del renderizador y de la ventana
|
||||
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
||||
SDL_SetWindowSize(window, windowWidth * options->windowSize, windowHeight * options->windowSize);
|
||||
createDisplay();
|
||||
|
||||
/*
|
||||
// Modifica el tamaño del renderizador y de la ventana
|
||||
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
||||
// SDL_SetWindowSize(window, windowWidth * options->windowSize, windowHeight * options->windowSize);
|
||||
|
||||
// Muestra el puntero
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
*/
|
||||
|
||||
// Aplica el modo de video
|
||||
SDL_SetWindowFullscreen(window, videoMode);
|
||||
}
|
||||
|
||||
// Si está activo el modo de pantalla completa añade el borde
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "asset.h"
|
||||
#include "notify.h"
|
||||
#include "utils.h"
|
||||
#include "../const.h"
|
||||
#include <vector>
|
||||
|
||||
#ifndef SCREEN_H
|
||||
@@ -45,6 +46,12 @@ private:
|
||||
int spectrumFadeLenght; // Duración del fade spectrum
|
||||
std::vector<color_t> spectrumColor; // Colores para el fade spectrum
|
||||
|
||||
// Crea la ventana
|
||||
void createDisplay();
|
||||
|
||||
// Destruye la ventana
|
||||
void destroyDisplay();
|
||||
|
||||
// Inicializa las variables para el fade
|
||||
void iniFade();
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ Director::Director(int argc, char *argv[])
|
||||
section->subsection = SUBSECTION_LOGO_TO_INTRO;
|
||||
|
||||
#ifdef DEBUG
|
||||
section->name = SECTION_PROG_LOGO;
|
||||
section->name = SECTION_PROG_GAME;
|
||||
#endif
|
||||
|
||||
// Crea e inicializa las opciones del programa
|
||||
|
||||
@@ -21,6 +21,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
||||
const int x = 25;
|
||||
const int y = 13;
|
||||
spawnPoint = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
||||
debug->setEnabled(true);
|
||||
#else
|
||||
currentRoom = "03.room";
|
||||
const int x = 25;
|
||||
|
||||
Reference in New Issue
Block a user