- [FIX] Render final a textura, per a evitar la merda que clava la GPU si s'usa acceleració hardware
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
.vscode/*
|
||||
dilemmaker
|
||||
build/*
|
||||
build/*
|
||||
*.exe
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace draw
|
||||
{
|
||||
SDL_Window *sdl_window {nullptr}; // La finestra de SDL
|
||||
SDL_Renderer *sdl_renderer {nullptr}; // El renderer de SDL
|
||||
SDL_Texture *sdl_texture {nullptr}; // La textura a la que ho renderitze tot
|
||||
SDL_Texture *sdl_source {nullptr};
|
||||
|
||||
void init(const char *titol, const uint16_t width, const uint16_t height)
|
||||
@@ -22,9 +23,17 @@ namespace draw
|
||||
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_TARGET, width, height);
|
||||
//SDL_SetRenderDrawBlendMode(sdl_renderer, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
|
||||
void resizeSystemTexture(const uint16_t width, const uint16_t height)
|
||||
{
|
||||
SDL_DestroyTexture(sdl_texture);
|
||||
sdl_texture = SDL_CreateTexture(sdl_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_TARGET, width, height);
|
||||
}
|
||||
|
||||
void quit()
|
||||
{
|
||||
SDL_DestroyRenderer(sdl_renderer);
|
||||
@@ -82,7 +91,7 @@ namespace draw
|
||||
|
||||
void setDestination(SDL_Texture *surf)
|
||||
{
|
||||
SDL_SetRenderTarget(sdl_renderer, surf);
|
||||
SDL_SetRenderTarget(sdl_renderer, surf ? surf : sdl_texture);
|
||||
}
|
||||
|
||||
void setSource(SDL_Texture *surf)
|
||||
@@ -185,7 +194,10 @@ namespace draw
|
||||
// Refresca la pantalla
|
||||
void render()
|
||||
{
|
||||
SDL_SetRenderTarget(sdl_renderer, nullptr);
|
||||
SDL_RenderTexture(sdl_renderer, sdl_texture, nullptr, nullptr);
|
||||
SDL_RenderPresent(sdl_renderer);
|
||||
SDL_SetRenderTarget(sdl_renderer, sdl_texture);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace draw
|
||||
enum flip { none, horizontal, vertical, both };
|
||||
|
||||
void init(const char *titol, const uint16_t width, const uint16_t height);
|
||||
void resizeSystemTexture(const uint16_t width, const uint16_t height);
|
||||
void quit();
|
||||
|
||||
SDL_Texture *createSurface(const uint16_t w, const uint16_t h);
|
||||
|
||||
@@ -114,6 +114,10 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
game::windowHasFocus = false;
|
||||
}
|
||||
if (e.type == SDL_EVENT_WINDOW_RESIZED)
|
||||
{
|
||||
draw::resizeSystemTexture(e.window.data1, e.window.data2);
|
||||
}
|
||||
}
|
||||
|
||||
if (SDL_GetTicks()-current_ticks >= game::ticks_per_frame)
|
||||
|
||||
Reference in New Issue
Block a user