Trabajando en integrar la clase screen
This commit is contained in:
63
source/screen.cpp
Normal file
63
source/screen.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "screen.h"
|
||||
#include "const.h"
|
||||
|
||||
// Constructor
|
||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||
{
|
||||
// Inicializa variables
|
||||
mWindow = window;
|
||||
mRenderer = renderer;
|
||||
|
||||
mScreenWidth = 320;//REAL_SCREEN_WIDTH;
|
||||
mScreenHeight = 240;//REAL_SCREEN_HEIGHT;
|
||||
mGameCanvasWidth = 256;//SCREEN_WIDTH;
|
||||
mGameCanvasHeight = 192;//SCREEN_HEIGHT;
|
||||
mGameCanvasPosX = 0;//(REAL_SCREEN_WIDTH - SCREEN_WIDTH) / 2;
|
||||
mGameCanvasPosY = 0;//(REAL_SCREEN_HEIGHT - SCREEN_HEIGHT) / 2;
|
||||
|
||||
mBorderColor = {0x27, 0x27, 0x36};
|
||||
|
||||
// Crea la textura donde se dibujan los graficos del juego
|
||||
mGameCanvas = SDL_CreateTexture(mRenderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, mGameCanvasWidth, mGameCanvasHeight);
|
||||
if (mGameCanvas == NULL)
|
||||
printf("TitleSurface could not be created!\nSDL Error: %s\n", SDL_GetError());
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Screen::~Screen()
|
||||
{
|
||||
mRenderer = nullptr;
|
||||
}
|
||||
|
||||
// Limpia la pantalla
|
||||
void Screen::clean(color_t color)
|
||||
{
|
||||
SDL_SetRenderDrawColor(mRenderer, color.r, color.g, color.b, 0xFF);
|
||||
SDL_RenderClear(mRenderer);
|
||||
}
|
||||
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
void Screen::start()
|
||||
{
|
||||
SDL_SetRenderTarget(mRenderer, mGameCanvas);
|
||||
}
|
||||
|
||||
// Vuelca el contenido del renderizador en pantalla
|
||||
void Screen::blit()
|
||||
{
|
||||
// Vuelve a dejar el renderizador en modo normal
|
||||
SDL_SetRenderTarget(mRenderer, NULL);
|
||||
|
||||
// Borra el contenido previo
|
||||
SDL_SetRenderDrawColor(mRenderer, mBorderColor.r, mBorderColor.g, mBorderColor.b, 0xFF);
|
||||
SDL_RenderClear(mRenderer);
|
||||
|
||||
// Rectangulo de destino donde se dibujarà la textura con el juego
|
||||
SDL_Rect dest = {mGameCanvasPosX, mGameCanvasPosY, mGameCanvasWidth, mGameCanvasHeight};
|
||||
|
||||
// Copia la textura de juego en el renderizador en la posición adecuada
|
||||
SDL_RenderCopy(mRenderer, mGameCanvas, NULL, &dest);
|
||||
|
||||
// Muestra por pantalla el renderizador
|
||||
SDL_RenderPresent(mRenderer);
|
||||
}
|
||||
Reference in New Issue
Block a user