Rescale backgrounds when resizing window.
This commit is contained in:
parent
12a3fcdbab
commit
840b7fbd30
|
@ -386,6 +386,7 @@ void engine_cleanup()
|
||||||
{
|
{
|
||||||
gfx_free();
|
gfx_free();
|
||||||
SDL_FreeSurface(gfx_background);
|
SDL_FreeSurface(gfx_background);
|
||||||
|
SDL_FreeSurface(gfx_unscaledBackground);
|
||||||
audio_free();
|
audio_free();
|
||||||
engine_resetLists();
|
engine_resetLists();
|
||||||
free(engine.bulletHead);
|
free(engine.bulletHead);
|
||||||
|
|
28
src/gfx.c
28
src/gfx.c
|
@ -33,6 +33,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "weapons.h"
|
#include "weapons.h"
|
||||||
|
|
||||||
|
SDL_Surface *gfx_unscaledBackground;
|
||||||
SDL_Surface *gfx_background;
|
SDL_Surface *gfx_background;
|
||||||
SDL_Surface *gfx_sprites[SP_MAX];
|
SDL_Surface *gfx_sprites[SP_MAX];
|
||||||
SDL_Surface *gfx_faceSprites[FS_MAX];
|
SDL_Surface *gfx_faceSprites[FS_MAX];
|
||||||
|
@ -496,21 +497,34 @@ void gfx_free()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void gfx_loadBackground(const char *filename)
|
void gfx_scaleBackground()
|
||||||
{
|
{
|
||||||
SDL_Surface *new_bg;
|
|
||||||
|
|
||||||
if (gfx_background != NULL)
|
if (gfx_background != NULL)
|
||||||
{
|
{
|
||||||
SDL_FreeSurface(gfx_background);
|
SDL_FreeSurface(gfx_background);
|
||||||
gfx_background = NULL;
|
gfx_background = NULL;
|
||||||
}
|
}
|
||||||
new_bg = gfx_loadImage(filename);
|
|
||||||
SDL_SetColorKey(new_bg, 0, 0);
|
|
||||||
gfx_background = gfx_createSurface(screen->w, screen->h);
|
gfx_background = gfx_createSurface(screen->w, screen->h);
|
||||||
|
if (gfx_background == NULL)
|
||||||
|
engine_error("Failed to create surface for scaled background");
|
||||||
|
|
||||||
SDL_SetColorKey(gfx_background, 0, 0);
|
SDL_SetColorKey(gfx_background, 0, 0);
|
||||||
SDL_BlitScaled(new_bg, NULL, gfx_background, NULL);
|
SDL_BlitScaled(gfx_unscaledBackground, NULL, gfx_background, NULL);
|
||||||
SDL_FreeSurface(new_bg);
|
}
|
||||||
|
|
||||||
|
void gfx_loadBackground(const char *filename)
|
||||||
|
{
|
||||||
|
if (gfx_unscaledBackground != NULL)
|
||||||
|
{
|
||||||
|
SDL_FreeSurface(gfx_unscaledBackground);
|
||||||
|
gfx_unscaledBackground = NULL;
|
||||||
|
}
|
||||||
|
gfx_unscaledBackground = gfx_loadImage(filename);
|
||||||
|
if (gfx_unscaledBackground == NULL)
|
||||||
|
engine_error("Failed to load unscaled background image");
|
||||||
|
|
||||||
|
SDL_SetColorKey(gfx_unscaledBackground, 0, 0);
|
||||||
|
gfx_scaleBackground();
|
||||||
}
|
}
|
||||||
|
|
||||||
void gfx_loadSprites()
|
void gfx_loadSprites()
|
||||||
|
|
|
@ -25,6 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
#include "structs.h"
|
#include "structs.h"
|
||||||
|
|
||||||
|
extern SDL_Surface *gfx_unscaledBackground;
|
||||||
extern SDL_Surface *gfx_background;
|
extern SDL_Surface *gfx_background;
|
||||||
extern SDL_Surface *gfx_sprites[SP_MAX];
|
extern SDL_Surface *gfx_sprites[SP_MAX];
|
||||||
extern SDL_Surface *gfx_faceSprites[FS_MAX];
|
extern SDL_Surface *gfx_faceSprites[FS_MAX];
|
||||||
|
@ -48,6 +49,7 @@ SDL_Surface *gfx_createAlphaRect(int width, int height, Uint8 red, Uint8 green,
|
||||||
void gfx_createMessageBox(SDL_Surface *face, const char *message, int transparent);
|
void gfx_createMessageBox(SDL_Surface *face, const char *message, int transparent);
|
||||||
SDL_Surface *gfx_loadImage(const char *filename);
|
SDL_Surface *gfx_loadImage(const char *filename);
|
||||||
void gfx_free();
|
void gfx_free();
|
||||||
|
void gfx_scaleBackground();
|
||||||
void gfx_loadBackground(const char *filename);
|
void gfx_loadBackground(const char *filename);
|
||||||
void gfx_loadSprites();
|
void gfx_loadSprites();
|
||||||
void gfx_loadFont();
|
void gfx_loadFont();
|
||||||
|
|
|
@ -339,6 +339,7 @@ void player_getInput()
|
||||||
{
|
{
|
||||||
screen_adjustDimensions(engine.event.window.data1, engine.event.window.data2);
|
screen_adjustDimensions(engine.event.window.data1, engine.event.window.data2);
|
||||||
renderer_reset();
|
renderer_reset();
|
||||||
|
gfx_scaleBackground();
|
||||||
screen_clear(black);
|
screen_clear(black);
|
||||||
renderer_update();
|
renderer_update();
|
||||||
screen_clear(black);
|
screen_clear(black);
|
||||||
|
|
|
@ -51,7 +51,8 @@ Draws the background surface that has been loaded
|
||||||
*/
|
*/
|
||||||
void screen_drawBackground()
|
void screen_drawBackground()
|
||||||
{
|
{
|
||||||
screen_blit(gfx_background, 0, 0);
|
if (gfx_background != NULL)
|
||||||
|
screen_blit(gfx_background, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void screen_addBuffer(int x, int y, int w, int h)
|
void screen_addBuffer(int x, int y, int w, int h)
|
||||||
|
|
Loading…
Reference in New Issue