From af121493c84c116b06f2572846535293a827d089 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sat, 20 Jun 2009 13:56:20 -0400 Subject: Embedded images into executable file --- Makefile | 18 ++++++++++++------ htpstate.cpp | 12 +++++++++--- includes.h | 1 + resources.h | 20 ++++++++++++++++++++ titlestate.cpp | 8 ++++++-- 5 files changed, 48 insertions(+), 11 deletions(-) create mode 100644 resources.h diff --git a/Makefile b/Makefile index 7f503ba..a4fe8ff 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,15 @@ -OBJS = mazeoflife.o titlestate.o htpstate.o gamestate.o +SOURCES = mazeoflife.cpp titlestate.cpp htpstate.cpp gamestate.cpp +OBJS = $(SOURCES:.cpp=.cpp.o) +IMAGES = title.bmp pointer.bmp htp1.bmp htp2.bmp +CIMAGES = $(IMAGES:.bmp=.bmp.o) CC = g++ CFLAGS = `pkg-config sdl --cflags` LIBS = `pkg-config sdl --libs` -mazeoflife: $(OBJS) - $(CC) $(OBJS) $(LIBS) -o mazeoflife +mazeoflife: $(OBJS) $(CIMAGES) + $(CC) $(OBJS) $(CIMAGES) $(LIBS) -o mazeoflife -%.o: %.cpp +%.cpp.o: %.cpp $(CC) -c $< $(CFLAGS) -o $@ %.d: %.cpp @@ -15,7 +18,10 @@ mazeoflife: $(OBJS) sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ rm -f $@.$$$$ -include $(OBJS:.o=.d) +%.bmp.o: %.bmp + objcopy --input binary --output elf32-i386 -B i386 $< $@ + +include $(OBJS:.cpp.o=.d) clean: - rm -rdfv $(OBJS) $(OBJS:.o=.d) mazeoflife + rm -rdfv $(OBJS) $(OBJS:.cpp.o=.d) $(CIMAGES) mazeoflife diff --git a/htpstate.cpp b/htpstate.cpp index ad830da..30d58a2 100644 --- a/htpstate.cpp +++ b/htpstate.cpp @@ -2,9 +2,15 @@ HowToPlayState::HowToPlayState() { - background1 = SDL_LoadBMP("htp1.bmp"); - background2 = SDL_LoadBMP("htp2.bmp"); - pointer = SDL_LoadBMP("pointer.bmp"); + SDL_RWops *rw = SDL_RWFromMem(&_binary_htp1_bmp_start, (int) &_binary_htp1_bmp_size); + background1 = SDL_LoadBMP_RW(rw, 1); + + rw = SDL_RWFromMem(&_binary_htp2_bmp_start, (int) &_binary_htp2_bmp_size); + background2 = SDL_LoadBMP_RW(rw, 1); + + rw = SDL_RWFromMem(&_binary_pointer_bmp_start, (int) &_binary_pointer_bmp_size); + pointer = SDL_LoadBMP_RW(rw, 1); + secondPage = false; selection = 0; diff --git a/includes.h b/includes.h index fa6abeb..5b0895d 100644 --- a/includes.h +++ b/includes.h @@ -4,6 +4,7 @@ #include #include "state.h" #include "mazeoflife.h" +#include "resources.h" #include "titlestate.h" #include "htpstate.h" #include "gamestate.h" diff --git a/resources.h b/resources.h new file mode 100644 index 0000000..4e01a90 --- /dev/null +++ b/resources.h @@ -0,0 +1,20 @@ +#ifndef RESOURCES_H +#define RESOURCES_H + +// title.bmp +extern int* _binary_title_bmp_start; +extern int* _binary_title_bmp_size; + +// pointer.bmp +extern int* _binary_pointer_bmp_start; +extern int* _binary_pointer_bmp_size; + +// htp1.bmp +extern int* _binary_htp1_bmp_start; +extern int* _binary_htp1_bmp_size; + +// htp2.bmp +extern int* _binary_htp2_bmp_start; +extern int* _binary_htp2_bmp_size; + +#endif diff --git a/titlestate.cpp b/titlestate.cpp index 425e4ca..c011480 100644 --- a/titlestate.cpp +++ b/titlestate.cpp @@ -2,8 +2,12 @@ TitleState::TitleState() { - background = SDL_LoadBMP("title.bmp"); - pointer = SDL_LoadBMP("pointer.bmp"); + SDL_RWops *rw = SDL_RWFromMem(&_binary_title_bmp_start, (int) &_binary_title_bmp_size); + background = SDL_LoadBMP_RW(rw, 1); + + rw = SDL_RWFromMem(&_binary_pointer_bmp_start, (int) &_binary_pointer_bmp_size); + pointer = SDL_LoadBMP_RW(rw, 1); + selection = 0; SDL_WM_SetCaption("Maze Of Life", NULL); -- cgit 1.4.1