diff options
author | P. J. McDermott <pjm@nac.net> | 2013-02-19 00:13:20 (EST) |
---|---|---|
committer | P. J. McDermott <pjm@nac.net> | 2013-02-19 00:16:48 (EST) |
commit | 79c6f91e7533f842a0f67770a641fceb5ad278e0 (patch) | |
tree | 13c97410318ee1ce1fac7863aa54cfcc2ce2d574 | |
parent | d97803995c8512738297dcff27ceec60bd023405 (diff) | |
download | overworld-rpg-79c6f91e7533f842a0f67770a641fceb5ad278e0.zip overworld-rpg-79c6f91e7533f842a0f67770a641fceb5ad278e0.tar.gz overworld-rpg-79c6f91e7533f842a0f67770a641fceb5ad278e0.tar.bz2 |
Fix graphics glitch with negative viewport coords.
-rw-r--r-- | src/area.c | 47 | ||||
-rw-r--r-- | src/area.h | 2 |
2 files changed, 34 insertions, 15 deletions
@@ -118,35 +118,54 @@ render_area_to_viewport(struct area *area, struct viewport *vp) void render_area_to_surface(struct area *area, SDL_Rect *arearect, - SDL_Surface *dst, SDL_Rect *dstrect) + SDL_Surface *surface, SDL_Rect *surfacerect) { - debug("Rendering %dx%d area rect at (%d,%d) " - "onto %dx%d surface rect at (%d,%d)...", - arearect->w, arearect->h, arearect->x, arearect->y, - dstrect->w, dstrect->h, dstrect->x, dstrect->y); + SDL_Rect srcrect, dstrect; + + memcpy(&srcrect, arearect, sizeof(srcrect)); + memcpy(&dstrect, surfacerect, sizeof(dstrect)); /* Fast fill with black to avoid artifacts in off-map pixels. */ /* NB: This is gray, at least temporarily. */ - SDL_FillRect(dst, dstrect, SDL_MapRGB(dst->format, 63, 63, 63)); + SDL_FillRect(surface, &dstrect, + SDL_MapRGB(surface->format, 63, 63, 63)); + + /* Avoid fun glitches due to negative coordinates in source + * rectangles. */ + if (srcrect.x < 0) { + srcrect.x = 0; + dstrect.x = surfacerect->x - arearect->x; + } + if (srcrect.y < 0) { + srcrect.y = 0; + dstrect.y = surfacerect->y - arearect->y; + } + +#if 0 + debug("Rendering %dx%d area rect at (%d,%d) " + "onto %dx%d surface rect at (%d,%d)...", + srcrect.w, srcrect.h, srcrect.x, srcrect.y, + dstrect.w, dstrect.h, dstrect.x, dstrect.y); +#endif /* Blit ground layer. */ - SDL_BlitSurface(area->map_layers[AREA_LAYER_GROUND], arearect, - dst, dstrect); + SDL_BlitSurface(area->map_layers[AREA_LAYER_GROUND], &srcrect, + surface, &dstrect); /* Blit low objects layer. */ - SDL_BlitSurface(area->map_layers[AREA_LAYER_OBJ_LOW], arearect, - dst, dstrect); + SDL_BlitSurface(area->map_layers[AREA_LAYER_OBJ_LOW], &srcrect, + surface, &dstrect); /* return;*/ /* TODO: Blit low sprites. */ /* Blit middle objects layer. */ - SDL_BlitSurface(area->map_layers[AREA_LAYER_OBJ_MID], arearect, - dst, dstrect); + SDL_BlitSurface(area->map_layers[AREA_LAYER_OBJ_MID], &srcrect, + surface, &dstrect); /* TODO: Blit high sprites. */ /* Blit high objects layer. */ - SDL_BlitSurface(area->map_layers[AREA_LAYER_OBJ_HIGH], arearect, - dst, dstrect); + SDL_BlitSurface(area->map_layers[AREA_LAYER_OBJ_HIGH], &srcrect, + surface, &dstrect); } @@ -13,6 +13,6 @@ struct area { struct area *area_new(struct map *map); void render_area_to_viewport(struct area *area, struct viewport *vp); void render_area_to_surface(struct area *area, SDL_Rect *arearect, - SDL_Surface *dst, SDL_Rect *dstrect); + SDL_Surface *surface, SDL_Rect *surfacerect); #endif |