From b20a12dc4ee29f24fda44e8f2d1d42e7b0fb6021 Mon Sep 17 00:00:00 2001 From: Oliver Bock <oliver.bock@aei.mpg.de> Date: Sat, 29 Mar 2008 17:46:20 +0100 Subject: [PATCH] Integrating the new resource management harness * Resource management files added to Makefile * Makefile automatically invokes ORC when needed * The main font is now loaded from a compiled-in font resource * More resources can be added easily by adding them to resources.orc --- Makefile | 21 ++++++++++++++++++--- main.C | 38 ++++++++++++++++++++++++++++---------- resources.orc | 3 +++ 3 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 resources.orc diff --git a/Makefile b/Makefile index 394e6d1..2957253 100644 --- a/Makefile +++ b/Makefile @@ -7,15 +7,16 @@ CXX ?= g++ LIBS = -L${BOINC_PREFIX}/lib -Bstatic $(shell sdl-config --static-libs) -lfreetype -lftgl -Wl,-Bdynamic -lGL -lGLU CPPFLAGS = -I/usr/include $(shell sdl-config --cflags) $(shell pkg-config --cflags ftgl) DEPS = Makefile starsphere.h -OBJS = starlist.o snr_list.o user_text.o pulsar_list.o search_info.o starsphere.o +OBJS = starlist.o snr_list.o user_text.o pulsar_list.o search_info.o starsphere.o ${RESOURCESPEC}.o Resource.o ResourceFactory.o DEBUGFLAGSCPP = -DDEBUG -pg -ggdb -O0 +RESOURCESPEC = resources # primary role based tagets default: release debug: starsphere memcheck: starsphere callgrind: starsphere -release: clean starsphere +release: clean starsphere # target specific options debug: CPPFLAGS += $(DEBUGFLAGSCPP) @@ -45,7 +46,21 @@ pulsar_list.o: $(DEPS) pulsar_list.C search_info.o: $(DEPS) search_info.C $(CXX) -g ${CPPFLAGS} -c search_info.C + + +# resource compiler +ResourceFactory.o: ${RESOURCESPEC}.o Resource.o ResourceFactory.cpp ResourceFactory.h + $(CXX) -g ${CPPFLAGS} -c ResourceFactory.cpp -o ResourceFactory.o +Resource.o: Resource.cpp Resource.h + $(CXX) -g ${CPPFLAGS} -c Resource.cpp -o Resource.o + +${RESOURCESPEC}.o: ${RESOURCESPEC}.orc + orc/orc ${RESOURCESPEC}.orc ${RESOURCESPEC}.cpp + $(CXX) -g ${CPPFLAGS} -c ${RESOURCESPEC}.cpp -o ${RESOURCESPEC}.o + + +# tools memcheck: valgrind --tool=memcheck --track-fds=yes --time-stamp=yes --log-file=${PWD}/memcheck.out.%p --leak-check=full ${PWD}/starsphere @@ -53,5 +68,5 @@ callgrind: valgrind --tool=callgrind --track-fds=yes --time-stamp=yes ${PWD}/starsphere clean: - rm -f ${OBJS} starsphere + rm -f ${RESOURCESPEC}.cpp *.o starsphere diff --git a/main.C b/main.C index dc762fb..693cfa7 100644 --- a/main.C +++ b/main.C @@ -30,7 +30,8 @@ #include <stdexcept> #include <SDL.h> -#include "starsphere.h" +#include "starsphere.h" +#include "ResourceFactory.h" // ugly globals, will eventually factored out into private members SDL_Surface *m_DisplaySurface = NULL; @@ -250,15 +251,31 @@ int main(int argc, char **argv) { } SDL_WM_SetCaption("Einstein@Home", "Icon"); - //SDL_WM_SetIcon(SDL_LoadBMP("icon.png"), NULL); + //SDL_WM_SetIcon(SDL_LoadBMP("icon.png"), NULL); - char fontFile[] = "arial.ttf"; -// font = new FTGLBitmapFont(fontFile); - font = new FTGLPixmapFont(fontFile); -// font = new FTGLOutlineFont(fontFile); -// font = new FTGLPolygonFont(fontFile); -// font = new FTGLExtrdFont(fontFile); -// font = new FTGLTextureFont(fontFile); + // prepare resource factory + ResourceFactory factory; + + // create font resource instance + const Resource *fontResource = factory.createInstance("FontSansSerif"); + + if(fontResource == NULL) { + cerr << "Font resource could not be loaded!" << endl; + exit(1); + } + + if(fontResource->Data()->size() == 0) { + cerr << "Font resource could not be loaded!" << endl; + exit(1); + } + + // create font instance using font resource (base address + size) +// font = new FTGLBitmapFont((&fontResource->Data()->at(0)), fontResource->Data()->size()); + font = new FTGLPixmapFont((&fontResource->Data()->at(0)), fontResource->Data()->size()); +// font = new FTGLOutlineFont((&fontResource->Data()->at(0)), fontResource->Data()->size()); +// font = new FTGLPolygonFont((&fontResource->Data()->at(0)), fontResource->Data()->size()); +// font = new FTGLExtrdFont((&fontResource->Data()->at(0)), fontResource->Data()->size()); +// font = new FTGLTextureFont((&fontResource->Data()->at(0)), fontResource->Data()->size()); font->CharMap(ft_encoding_unicode); @@ -277,6 +294,7 @@ int main(int argc, char **argv) { eventLoop(); if (font) delete font; + delete fontResource; - return(0); + exit(0); } diff --git a/resources.orc b/resources.orc new file mode 100644 index 0000000..49b1a7c --- /dev/null +++ b/resources.orc @@ -0,0 +1,3 @@ +# Resource specification of: Einstein@Home graphics application + +FontSansSerif|LiberationSans-Regular.ttf \ No newline at end of file -- GitLab