Ya se dibuja el gif en pantalla

This commit is contained in:
2024-02-07 16:59:25 +01:00
parent 2d045642ff
commit 8e612aaa2e
4 changed files with 92 additions and 42 deletions

View File

@@ -39,6 +39,12 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *
}
SDL_SetTextureBlendMode(bgTexture, SDL_BLENDMODE_BLEND);
// Carga la surface con los gráficos de la pantalla de carga
pInit(renderer, 256, 192);
loading_screen = pLoadSurface("data/title/loading_screen_color.gif");
pLoadPal("data/title/loading_screen_color.gif");
pSetSource(loading_screen);
// Inicializa variables
counter = 0;
section->name = SECTION_TITLE;
@@ -48,6 +54,7 @@ Title::Title(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *
marqueeSpeed = 3;
initMarquee();
showCheevos = false;
state = show_loading_screen;
// Crea y rellena la textura para mostrar los logros
createCheevosTexture();
@@ -69,6 +76,7 @@ Title::~Title()
delete cheevosTexture;
delete text;
delete infoText;
pDeleteSurface(loading_screen);
SDL_DestroyTexture(bgTexture);
}
@@ -264,15 +272,30 @@ void Title::update()
// Comprueba las entradas
checkInput();
// Actualiza las notificaciones
screen->updateNotifier();
// Incrementa el contador
counter++;
switch (state)
{
case show_loading_screen:
if (counter == 500)
{
counter = 0;
state = show_menu;
}
break;
case fade_loading_screen:
break;
case show_menu:
// Actualiza la marquesina
updateMarquee();
// Actualiza las notificaciones
screen->updateNotifier();
// Si el contador alcanza cierto valor, termina la seccion
if (counter == 2200)
{
@@ -282,6 +305,11 @@ void Title::update()
section->subsection = 0;
}
}
break;
default:
break;
}
}
}
@@ -291,6 +319,21 @@ void Title::render()
// Prepara para empezar a dibujar en la textura de juego
screen->start();
switch (state)
{
case show_loading_screen:
// Dibuja la textura de fondo
SDL_RenderCopy(renderer, bgTexture, nullptr, nullptr);
// Dibuja la pantalla de carga
pBlit(0, 0, 0, 0, 256, 192);
pFlip(renderer);
break;
case fade_loading_screen:
break;
case show_menu:
// Dibuja la textura de fondo
SDL_RenderCopy(renderer, bgTexture, nullptr, nullptr);
@@ -302,6 +345,11 @@ void Title::render()
{
cheevosSprite->render();
}
break;
default:
break;
}
// Vuelca el contenido del renderizador en pantalla
screen->blit();

View File

@@ -7,6 +7,7 @@
#include "jail_engine/input.h"
#include "jail_engine/jail_audio.h"
#include "jail_engine/resource.h"
#include "jail_engine/paleta.h"
#include "jail_engine/screen.h"
#include "jail_engine/sprite.h"
#include "jail_engine/text.h"
@@ -28,6 +29,13 @@ private:
bool enabled; // Solo se escriben y mueven si estan habilitadas
};
enum states_e
{
show_loading_screen,
fade_loading_screen,
show_menu
};
// Objetos y punteros
SDL_Renderer *renderer; // El renderizador de la ventana
Screen *screen; // Objeto encargado de dibujar en pantalla
@@ -57,6 +65,8 @@ private:
int marqueeSpeed; // Velocidad de desplazamiento de la marquesina
bool showCheevos; // Indica si se muestra por pantalla el listado de logros
SDL_Rect cheevosTextureView; // Zona visible de la textura con el listado de logros
states_e state; // Estado en el que se encuentra el bucle principal
jSurface loading_screen; // Surface con los gráficos de la pantalla de carga
// Actualiza las variables
void update();

View File

@@ -8,8 +8,6 @@ struct jSurface_s
Uint16 w, h;
};
static SDL_Window *jWin = NULL;
static SDL_Renderer *jRen = NULL;
static SDL_Texture *jTex = NULL;
static jSurface jScreen;
static jSurface jDestSurf;
@@ -17,9 +15,17 @@ static jSurface jSourceSurf = NULL;
static Uint32 paleta[256];
static int jWidth = 320;
static int jHeight = 240;
static int jZoom = 2;
static int transparentColor = 0;
void pInit(SDL_Renderer *renderer, int w, int h)
{
jWidth = w;
jHeight = h;
jTex = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, w, h);
jScreen = pNewSurface(w, h);
jDestSurf = jScreen;
}
jSurface pNewSurface(int w, int h)
{
jSurface surf = (jSurface)malloc(sizeof(jSurface_s));
@@ -115,20 +121,6 @@ void pLoadPal(const char *filename)
}
}
void pInit(const char *titol, int w, int h, int z)
{
SDL_Init(SDL_INIT_EVERYTHING);
jWidth = w;
jHeight = h;
jZoom = z;
jWin = SDL_CreateWindow(titol, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w * z, h * z, SDL_WINDOW_SHOWN);
jRen = SDL_CreateRenderer(jWin, -1, 0);
SDL_RenderSetLogicalSize(jRen, w, h);
jTex = SDL_CreateTexture(jRen, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, w, h);
jScreen = pNewSurface(w, h);
jDestSurf = jScreen;
}
void pSetPal(int index, Uint32 color)
{
paleta[index] = color;
@@ -140,7 +132,7 @@ void pCls(Uint8 color)
jDestSurf->data[i] = color;
}
void pFlip()
void pFlip(SDL_Renderer *renderer)
{
Uint32 *pixels;
int pitch;
@@ -148,8 +140,8 @@ void pFlip()
for (int i = 0; i < jWidth * jHeight; ++i)
pixels[i] = paleta[jScreen->data[i]];
SDL_UnlockTexture(jTex);
SDL_RenderCopy(jRen, jTex, NULL, NULL);
SDL_RenderPresent(jRen);
SDL_RenderCopy(renderer, jTex, NULL, NULL);
//SDL_RenderPresent(jRen);
}
void pPutPixel(int x, int y, Uint8 color)

View File

@@ -15,11 +15,11 @@ Uint8 pGetPixel(int x, int y);
void pBlit(int dx, int dy, int sx, int sy, int w, int h);
void pInit(const char *titol, int w, int h, int z);
void pInit(SDL_Renderer *renderer, int w, int h);
void pSetPal(int index, Uint32 color);
void pLoadPal(const char *filename);
void pCls(Uint8 color);
void pFlip();
void pFlip(SDL_Renderer *renderer);