Fixed an issue with clipping the render rectangle
This commit is contained in:
1 parent
2eb8d83dc0
commit
c1659dcf88
5 files changed
+99
-39
No files matched your search
+16
-7
@@ -58,8 +58,8 @@ void fill_rect(const Renderer *renderer, SDL_Color color, float x, float y,
|
||||
SDL_RenderFillRectF(renderer->SDL_base_renderer, &dest);
|
||||
}
|
||||
|
||||
void render_surface(const Renderer *renderer, SDL_Surface *surface, float x,
|
||||
float y, float w, float h) {
|
||||
void render_surface(const Renderer *renderer, SDL_Surface *surface,
|
||||
const RenderRect *dest) {
|
||||
SDL_Texture *texture =
|
||||
SDL_CreateTextureFromSurface(renderer->SDL_base_renderer, surface);
|
||||
|
||||
@@ -67,23 +67,32 @@ void render_surface(const Renderer *renderer, SDL_Surface *surface, float x,
|
||||
return;
|
||||
}
|
||||
|
||||
render_texture(renderer, texture, x, y, w, h);
|
||||
render_texture(renderer, texture, NULL, dest);
|
||||
|
||||
SDL_DestroyTexture(texture);
|
||||
texture = NULL;
|
||||
}
|
||||
|
||||
void render_texture(const Renderer *renderer, SDL_Texture *texture, float x,
|
||||
float y, float w, float h) {
|
||||
void render_texture(const Renderer *renderer, SDL_Texture *texture,
|
||||
const RenderRect *src, const RenderRect *dest) {
|
||||
if (!renderer || !texture) {
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_FRect dest = {x, y, w, h};
|
||||
SDL_Rect src_frect;
|
||||
if (src) {
|
||||
src_frect.x = src->x;
|
||||
src_frect.y = src->y;
|
||||
src_frect.w = src->width;
|
||||
src_frect.h = src->height;
|
||||
}
|
||||
|
||||
SDL_FRect dest_frect = {dest->x, dest->y, dest->width, dest->height};
|
||||
|
||||
// TODO (Abdelrahman): Look into using the SDL_RenderCopyExF instead to
|
||||
// support rotating the texture
|
||||
SDL_RenderCopyF(renderer->SDL_base_renderer, texture, NULL, &dest);
|
||||
SDL_RenderCopyF(renderer->SDL_base_renderer, texture, &src_frect,
|
||||
&dest_frect);
|
||||
}
|
||||
|
||||
void swap_buffers(const Renderer *renderer) {
|
||||
|
||||
Reference in new issue
Block a user