diff --git a/Unuk-QT/ImageLoader.o b/Unuk-QT/ImageLoader.o deleted file mode 100644 index 543f93a..0000000 Binary files a/Unuk-QT/ImageLoader.o and /dev/null differ diff --git a/Unuk-QT/Makefile b/Unuk-QT/Makefile index fade32f..d5f0ed3 100644 --- a/Unuk-QT/Makefile +++ b/Unuk-QT/Makefile @@ -1,6 +1,6 @@ ############################################################################# # Makefile for building: Unuk-QT -# Generated by qmake (2.01a) (Qt 4.7.3) on: Sun Nov 6 23:46:01 2011 +# Generated by qmake (2.01a) (Qt 4.7.3) on: Wed Nov 9 00:17:08 2011 # Project: Unuk-QT.pro # Template: app # Command: /usr/bin/qmake-qt4 -spec /usr/share/qt4/mkspecs/linux-g++ CONFIG+=debug -o Makefile Unuk-QT.pro @@ -16,7 +16,7 @@ CXXFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES) INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. LINK = g++ LFLAGS = -LIBS = $(SUBLIBS) -L/usr/lib -lGL -lSDL -lSDL_ttf -lGLU -lQtGui -lQtCore -lpthread +LIBS = $(SUBLIBS) -L/usr/lib -lGL -lSDL -lSDL_ttf -lSDL_image -lGLU -lQtGui -lQtCore -lpthread AR = ar cqs RANLIB = QMAKE = /usr/bin/qmake-qt4 @@ -49,14 +49,18 @@ SOURCES = ../src/libUnuk/Debug.cpp \ ../src/libUnuk/Timer.cpp \ ../src/libUnuk/Font.cpp \ ../src/libUnuk/ApplySurface.cpp \ - ../src/Unuk/Globals.cpp + ../src/Unuk/Globals.cpp \ + ../src/libUnuk/Rect.cpp \ + ../src/libUnuk/ImageLoader.cpp OBJECTS = Debug.o \ main.o \ Input.o \ Timer.o \ Font.o \ ApplySurface.o \ - Globals.o + Globals.o \ + Rect.o \ + ImageLoader.o DIST = /usr/share/qt4/mkspecs/common/g++.conf \ /usr/share/qt4/mkspecs/common/unix.conf \ /usr/share/qt4/mkspecs/common/linux.conf \ @@ -159,7 +163,7 @@ qmake: FORCE dist: @$(CHK_DIR_EXISTS) .tmp/Unuk-QT1.0.0 || $(MKDIR) .tmp/Unuk-QT1.0.0 - $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Debug.h ../src/Libs/wglext.h ../src/Libs/glxext.h ../src/libUnuk/Input.h ../src/libUnuk/Rect.h ../src/libUnuk/Timer.h ../src/libUnuk/Font.h ../Constants.h ../src/Unuk/Constants.h ../src/libUnuk/ApplySurface.h ../src/Unuk/Globals.h .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Debug.cpp ../src/Unuk/main.cpp ../src/libUnuk/Input.cpp ../src/libUnuk/Timer.cpp ../src/libUnuk/Font.cpp ../src/libUnuk/ApplySurface.cpp ../src/Unuk/Globals.cpp .tmp/Unuk-QT1.0.0/ && (cd `dirname .tmp/Unuk-QT1.0.0` && $(TAR) Unuk-QT1.0.0.tar Unuk-QT1.0.0 && $(COMPRESS) Unuk-QT1.0.0.tar) && $(MOVE) `dirname .tmp/Unuk-QT1.0.0`/Unuk-QT1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/Unuk-QT1.0.0 + $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Debug.h ../src/Libs/wglext.h ../src/Libs/glxext.h ../src/libUnuk/Input.h ../src/libUnuk/Rect.h ../src/libUnuk/Timer.h ../src/libUnuk/Font.h ../Constants.h ../src/Unuk/Constants.h ../src/libUnuk/ApplySurface.h ../src/Unuk/Globals.h ../src/libUnuk/ImageLoader.h .tmp/Unuk-QT1.0.0/ && $(COPY_FILE) --parents ../src/libUnuk/Debug.cpp ../src/Unuk/main.cpp ../src/libUnuk/Input.cpp ../src/libUnuk/Timer.cpp ../src/libUnuk/Font.cpp ../src/libUnuk/ApplySurface.cpp ../src/Unuk/Globals.cpp ../src/libUnuk/Rect.cpp ../src/libUnuk/ImageLoader.cpp .tmp/Unuk-QT1.0.0/ && (cd `dirname .tmp/Unuk-QT1.0.0` && $(TAR) Unuk-QT1.0.0.tar Unuk-QT1.0.0 && $(COMPRESS) Unuk-QT1.0.0.tar) && $(MOVE) `dirname .tmp/Unuk-QT1.0.0`/Unuk-QT1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/Unuk-QT1.0.0 clean:compiler_clean @@ -227,6 +231,17 @@ ApplySurface.o: ../src/libUnuk/ApplySurface.cpp ../src/libUnuk/ApplySurface.h \ Globals.o: ../src/Unuk/Globals.cpp ../src/Unuk/Globals.h $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Globals.o ../src/Unuk/Globals.cpp +Rect.o: ../src/libUnuk/Rect.cpp ../src/libUnuk/Rect.h \ + ../src/Unuk/Globals.h \ + ../src/libUnuk/ApplySurface.h \ + ../src/libUnuk/Debug.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o Rect.o ../src/libUnuk/Rect.cpp + +ImageLoader.o: ../src/libUnuk/ImageLoader.cpp ../src/libUnuk/ImageLoader.h \ + ../src/Unuk/Globals.h \ + ../src/libUnuk/Debug.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o ImageLoader.o ../src/libUnuk/ImageLoader.cpp + ####### Install install: FORCE diff --git a/Unuk-QT/Unuk-QT.pro b/Unuk-QT/Unuk-QT.pro index 5867265..d1affb5 100644 --- a/Unuk-QT/Unuk-QT.pro +++ b/Unuk-QT/Unuk-QT.pro @@ -1,6 +1,7 @@ LIBS += -lGL \ -lSDL \ -lSDL_ttf \ + -lSDL_image \ -lGLU RESOURCES += OTHER_FILES += ../src/libUnuk/Debug.o @@ -14,11 +15,14 @@ HEADERS += ../src/libUnuk/Debug.h \ ../Constants.h \ ../src/Unuk/Constants.h \ ../src/libUnuk/ApplySurface.h \ - ../src/Unuk/Globals.h + ../src/Unuk/Globals.h \ + ../src/libUnuk/ImageLoader.h SOURCES += ../src/libUnuk/Debug.cpp \ ../src/Unuk/main.cpp \ ../src/libUnuk/Input.cpp \ ../src/libUnuk/Timer.cpp \ ../src/libUnuk/Font.cpp \ ../src/libUnuk/ApplySurface.cpp \ - ../src/Unuk/Globals.cpp + ../src/Unuk/Globals.cpp \ + ../src/libUnuk/Rect.cpp \ + ../src/libUnuk/ImageLoader.cpp diff --git a/src/libUnuk/Font.h b/src/libUnuk/Font.h index 51a7994..8f3c0d5 100644 --- a/src/libUnuk/Font.h +++ b/src/libUnuk/Font.h @@ -6,6 +6,6 @@ #include "Debug.h" using namespace std; -TTF_Font* Font(const char*, const int); +TTF_Font* Font(const char* filename, const int size); #endif diff --git a/src/libUnuk/ImageLoader.cpp b/src/libUnuk/ImageLoader.cpp new file mode 100644 index 0000000..84de38f --- /dev/null +++ b/src/libUnuk/ImageLoader.cpp @@ -0,0 +1,37 @@ +#include "ImageLoader.h" + +SDL_Surface* LoadImage(const char* filename) { + SDL_Surface* loadedImage = NULL; + SDL_Surface* optimizedImage = NULL; + + // Initialize loadedImage with the file. + loadedImage = IMG_Load(filename); + if(loadedImage != NULL) { + // Then copy the image to a surface for us to blit later. + optimizedImage = SDL_DisplayFormat(loadedImage); + SDL_FreeSurface(loadedImage); + return optimizedImage; + } else { + // Tell us what file is mising and do some stuid error texture thing. + Debug::logger->message("ImageLoader: %s cannot be found!"); + return errorTexture; + } +} + +SDL_Surface* LoadImageAlpha(const char* filename) { + SDL_Surface* loadedImage = NULL; + SDL_Surface* optimizedImage = NULL; + + // Initialize loadedImage with the file. + loadedImage = IMG_Load(filename); + if(loadedImage != NULL) { + // Then copy the image to a surface and give us an alpha channel. + optimizedImage = SDL_DisplayFormatAlpha(loadedImage); + SDL_FreeSurface(loadedImage); + return optimizedImage; + } else { + // Tell us what file is mising and do some stuid error texture thing. + Debug::logger->message("ImageLoader: %s cannot be found!"); + return errorTexture; + } +} diff --git a/src/libUnuk/ImageLoader.h b/src/libUnuk/ImageLoader.h new file mode 100644 index 0000000..dd112f3 --- /dev/null +++ b/src/libUnuk/ImageLoader.h @@ -0,0 +1,11 @@ +#ifndef _IMAGELOADER_H_ +#define _IMAGELOADER_H_ +#include +#include +#include "../Unuk/Globals.h" +#include "Debug.h" + +SDL_Surface* LoadImage(const char* filename); +SDL_Surface* LoadImageAlpha(const char* filename); + +#endif diff --git a/src/libUnuk/Rect.cpp b/src/libUnuk/Rect.cpp new file mode 100644 index 0000000..5528146 --- /dev/null +++ b/src/libUnuk/Rect.cpp @@ -0,0 +1,38 @@ +#include "Rect.h" + +Rect::Rect(void) { +} + +Rect::~Rect(void) { +} + +void Rect::SetXY(int xArg, int yArg) { + rect.x = xArg; + rect.y = yArg; +} + +void Rect::SetWidthHeight(int wArg, int hArg) { + rect.w = wArg; + rect.h = hArg; +} + +void Rect::SetRGB(Uint8 rArg, Uint8 gArg, Uint8 bArg) { + r = rArg; + g = gArg; + b = bArg; +} + +void Rect::Draw(void) { + SDL_Rect offset; + + offset.x = rect.x - camera.x; + offset.y = rect.y - camera.y; + offset.w = rect.w; + offset.h = rect.h; + + SDL_FillRect(screen, &offset, SDL_MapRGB(screen->format, r, g, b)); +} + +void Rect::DrawLiteral(void) { + SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, r, g, b)); +} diff --git a/src/libUnuk/Rect.h b/src/libUnuk/Rect.h index c9bee71..ae076ea 100644 --- a/src/libUnuk/Rect.h +++ b/src/libUnuk/Rect.h @@ -2,7 +2,35 @@ #define _RECT_H_ #include #include // May not need this. +#include "../Unuk/Globals.h" +#include "ApplySurface.h" using namespace std; +class Rect { +public: + Rect(void); + ~Rect(void); + + int GetWidth(void) { return rect.w; } + int GetHeight(void) { return rect.h; } + int GetX(void) { return rect.x; } + int GetY(void) { return rect.y; } + + void SetXY(int xArg, int yArg); + void SetWidthHeight(int wArg, int hArg); + void SetRGB(Uint8 rArg, Uint8 gArg, Uint8 bArg); + + void Draw(void); + void DrawLiteral(void); + +protected: + Uint8 r; + Uint8 g; + Uint8 b; + +private: + SDL_Rect rect; +}; + #endif