aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2012-08-14 15:31:00 +0200
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2012-08-14 15:31:00 +0200
commit34c25eab5d1258d8b51e2c7963fdab03408b8eb2 (patch)
treefec8c5076b60efbc296fafbc02553cafd306170b
parent73b19833e03bcc73660e6b68a6425a8a4a2d4684 (diff)
downloadosc-graphics-34c25eab5d1258d8b51e2c7963fdab03408b8eb2.tar.gz
preliminary SDL_image integration
-rw-r--r--Makefile7
-rw-r--r--effect-pad.c19
2 files changed, 23 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index 00f72ad..a639132 100644
--- a/Makefile
+++ b/Makefile
@@ -3,9 +3,12 @@ CC := gcc
SDL_CFLAGS := $(shell sdl-config --cflags)
SDL_LDFLAGS := $(shell sdl-config --libs)
+SDL_IMAGE_CFLAGS := $(shell pkg-config SDL_image --cflags)
+SDL_IMAGE_LDFLAGS := $(shell pkg-config SDL_image --libs)
+
CFLAGS := -std=c99 -Wall -g -O0 \
- $(SDL_CFLAGS)
-LDFLAGS := $(SDL_LDFLAGS)
+ $(SDL_CFLAGS) $(SDL_IMAGE_CFLAGS)
+LDFLAGS := $(SDL_LDFLAGS) $(SDL_IMAGE_LDFLAGS)
all : effect-pad
diff --git a/effect-pad.c b/effect-pad.c
index 702b372..dae1a02 100644
--- a/effect-pad.c
+++ b/effect-pad.c
@@ -1,7 +1,9 @@
#include <stdio.h>
#include <stdlib.h>
+#include <assert.h>
#include <SDL.h>
+#include <SDL_image.h>
#define NARRAY(ARRAY) \
(sizeof(ARRAY) / sizeof(ARRAY[0]))
@@ -21,6 +23,11 @@
__FILE__, __LINE__, ##__VA_ARGS__, SDL_GetError()); \
} while (0)
+#define SDL_IMAGE_ERROR(FMT, ...) do { \
+ fprintf(stderr, "%s(%d): " FMT ": %s\n", \
+ __FILE__, __LINE__, ##__VA_ARGS__, IMG_GetError()); \
+} while (0)
+
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
@@ -166,6 +173,7 @@ int
main(int argc, char **argv)
{
SDL_Surface *fire_surface;
+ SDL_Surface *image_surface;
if (SDL_Init(SDL_INIT_VIDEO)) {
SDL_ERROR("SDL_Init");
@@ -182,6 +190,13 @@ main(int argc, char **argv)
return EXIT_FAILURE;
}
+ image_surface = IMG_Load("image_1.jpg");
+ if (image_surface == NULL) {
+ SDL_IMAGE_ERROR("IMG_Load");
+ return EXIT_FAILURE;
+ }
+ assert(image_surface->w == screen->w && image_surface->h == screen->h);
+
fire_surface = effect_fire_init();
for (;;) {
@@ -190,11 +205,13 @@ main(int argc, char **argv)
SDL_FillRect(screen, NULL,
SDL_MapRGB(screen->format, 0, 0, 0));
+ SDL_BlitSurface(image_surface, NULL, screen, NULL);
+
effect_fire_update(fire_surface);
SDL_BlitSurface(fire_surface, NULL, screen, NULL);
SDL_Flip(screen);
- SDL_Delay(50);
+ SDL_Delay(1000/20);
}
/* never reached */