primera faeneta
This commit is contained in:
1 parent
2cd3f807ec
commit
6961986ad2
9 files changed
+194
-1
No files matched your search
@@ -0,0 +1,65 @@
|
||||
#include "rendering/video.hpp"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
Video::Video(Config config)
|
||||
: config_(config) {
|
||||
initSDL();
|
||||
}
|
||||
|
||||
Video::~Video() {
|
||||
cleanup();
|
||||
}
|
||||
|
||||
void Video::cleanup() {
|
||||
SDL_DestroyTexture(game_texture_);
|
||||
game_texture_ = nullptr;
|
||||
|
||||
SDL_DestroyRenderer(renderer_);
|
||||
renderer_ = nullptr;
|
||||
|
||||
SDL_DestroyWindow(window_);
|
||||
window_ = nullptr;
|
||||
}
|
||||
|
||||
auto Video::initSDL() -> int {
|
||||
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
||||
SDL_Log("No se pudo inicializar SDL: %s", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
window_ = SDL_CreateWindow("Mi ventana", config_.width, config_.height, 0);
|
||||
if (window_ == nullptr) {
|
||||
SDL_Log("No se pudo crear la ventana: %s", SDL_GetError());
|
||||
cleanup();
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
renderer_ = SDL_CreateRenderer(window_, nullptr);
|
||||
if (renderer_ == nullptr) {
|
||||
SDL_Log("No se pudo crear el renderer: %s", SDL_GetError());
|
||||
cleanup();
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// SDL_SetRenderVSync(renderer_, config_.vsync ? 1 : 0);
|
||||
// SDL_SetRenderLogicalPresentation(renderer_, GameCanvas::WIDTH, GameCanvas::HEIGHT, toSdlPresentation(config_.scaling_mode));
|
||||
|
||||
game_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, config_.width, config_.height);
|
||||
if (game_texture_ == nullptr) {
|
||||
SDL_Log("No se pudo crear la textura de juego: %s", SDL_GetError());
|
||||
cleanup();
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
//SDL_SetTextureScaleMode(game_texture_, toSdlScaleMode(config_.texture_filter));
|
||||
|
||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Video subsystem initialized successfully");
|
||||
|
||||
SDL_Delay(1000);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
class Video {
|
||||
public:
|
||||
struct Config {
|
||||
bool fullscreen{false};
|
||||
float zoom{1.0F};
|
||||
float width{320.0F};
|
||||
float height{240.0F};
|
||||
};
|
||||
|
||||
Video(Config config);
|
||||
~Video();
|
||||
|
||||
private:
|
||||
Config config_;
|
||||
|
||||
SDL_Window* window_{nullptr};
|
||||
SDL_Renderer* renderer_{nullptr};
|
||||
SDL_Texture* game_texture_{nullptr};
|
||||
|
||||
auto initSDL() -> int;
|
||||
void cleanup();
|
||||
};
|
||||
Reference in new issue
Block a user