From: Daniel Karbach Date: Wed, 1 Aug 2012 20:58:08 +0000 (+0200) Subject: added SDL initialization classes X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;ds=sidebyside;h=5ceb9e51fd6768946c4a2d72aac13fa6bc78fa88;p=l2e.git added SDL initialization classes --- diff --git a/Debug/makefile b/Debug/makefile index 7cfe0c4..7439cad 100644 --- a/Debug/makefile +++ b/Debug/makefile @@ -8,6 +8,7 @@ RM := rm -rf # All of the sources participating in the build are defined here -include sources.mk +-include src/sdl/subdir.mk -include src/subdir.mk -include subdir.mk -include objects.mk diff --git a/Debug/objects.mk b/Debug/objects.mk index 742c2da..b99d1e5 100644 --- a/Debug/objects.mk +++ b/Debug/objects.mk @@ -4,5 +4,5 @@ USER_OBJS := -LIBS := +LIBS := -lSDL diff --git a/Debug/sources.mk b/Debug/sources.mk index e7f4bf1..414d559 100644 --- a/Debug/sources.mk +++ b/Debug/sources.mk @@ -23,5 +23,6 @@ C_UPPER_DEPS := # Every subdirectory with source files must be described here SUBDIRS := \ +src/sdl \ src \ diff --git a/Debug/src/sdl/subdir.mk b/Debug/src/sdl/subdir.mk new file mode 100644 index 0000000..67239ce --- /dev/null +++ b/Debug/src/sdl/subdir.mk @@ -0,0 +1,27 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +# Add inputs and outputs from these tool invocations to the build variables +CPP_SRCS += \ +../src/sdl/InitSDL.cpp \ +../src/sdl/InitScreen.cpp + +OBJS += \ +./src/sdl/InitSDL.o \ +./src/sdl/InitScreen.o + +CPP_DEPS += \ +./src/sdl/InitSDL.d \ +./src/sdl/InitScreen.d + + +# Each subdirectory must supply rules for building sources it contributes +src/sdl/%.o: ../src/sdl/%.cpp + @echo 'Building file: $<' + @echo 'Invoking: GCC C++ Compiler' + g++ -I/usr/include/SDL -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + @echo 'Finished building: $<' + @echo ' ' + + diff --git a/Debug/src/subdir.mk b/Debug/src/subdir.mk index 4257574..b8432d7 100644 --- a/Debug/src/subdir.mk +++ b/Debug/src/subdir.mk @@ -17,7 +17,7 @@ CPP_DEPS += \ src/%.o: ../src/%.cpp @echo 'Building file: $<' @echo 'Invoking: GCC C++ Compiler' - g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + g++ -I/usr/include/SDL -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" @echo 'Finished building: $<' @echo ' ' diff --git a/Release/makefile b/Release/makefile index 7cfe0c4..7439cad 100644 --- a/Release/makefile +++ b/Release/makefile @@ -8,6 +8,7 @@ RM := rm -rf # All of the sources participating in the build are defined here -include sources.mk +-include src/sdl/subdir.mk -include src/subdir.mk -include subdir.mk -include objects.mk diff --git a/Release/objects.mk b/Release/objects.mk index 742c2da..b99d1e5 100644 --- a/Release/objects.mk +++ b/Release/objects.mk @@ -4,5 +4,5 @@ USER_OBJS := -LIBS := +LIBS := -lSDL diff --git a/Release/sources.mk b/Release/sources.mk index e7f4bf1..414d559 100644 --- a/Release/sources.mk +++ b/Release/sources.mk @@ -23,5 +23,6 @@ C_UPPER_DEPS := # Every subdirectory with source files must be described here SUBDIRS := \ +src/sdl \ src \ diff --git a/Release/src/sdl/subdir.mk b/Release/src/sdl/subdir.mk new file mode 100644 index 0000000..ad789ab --- /dev/null +++ b/Release/src/sdl/subdir.mk @@ -0,0 +1,27 @@ +################################################################################ +# Automatically-generated file. Do not edit! +################################################################################ + +# Add inputs and outputs from these tool invocations to the build variables +CPP_SRCS += \ +../src/sdl/InitSDL.cpp \ +../src/sdl/InitScreen.cpp + +OBJS += \ +./src/sdl/InitSDL.o \ +./src/sdl/InitScreen.o + +CPP_DEPS += \ +./src/sdl/InitSDL.d \ +./src/sdl/InitScreen.d + + +# Each subdirectory must supply rules for building sources it contributes +src/sdl/%.o: ../src/sdl/%.cpp + @echo 'Building file: $<' + @echo 'Invoking: GCC C++ Compiler' + g++ -I/usr/include/SDL -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + @echo 'Finished building: $<' + @echo ' ' + + diff --git a/Release/src/subdir.mk b/Release/src/subdir.mk index df4637c..e2d08a0 100644 --- a/Release/src/subdir.mk +++ b/Release/src/subdir.mk @@ -17,7 +17,7 @@ CPP_DEPS += \ src/%.o: ../src/%.cpp @echo 'Building file: $<' @echo 'Invoking: GCC C++ Compiler' - g++ -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" + g++ -I/usr/include/SDL -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" @echo 'Finished building: $<' @echo ' ' diff --git a/src/main.cpp b/src/main.cpp index 0fce8fe..2040663 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,31 @@ * Author: holy */ +#include "sdl/InitScreen.h" +#include "sdl/InitSDL.h" + +#include +#include + +using sdl::InitScreen; +using sdl::InitSDL; + +using std::cerr; +using std::cout; +using std::endl; +using std::exception; + int main(int argc, char **argv) { - return 0; + const int width = 800; + const int height = 480; + + try { + InitSDL sdl; + InitScreen screen(width, height); + + return 0; + } catch (exception &e) { + cerr << "exception in main(): " << e.what() << endl; + return 1; + } } diff --git a/src/sdl/InitSDL.cpp b/src/sdl/InitSDL.cpp new file mode 100644 index 0000000..0f2eacd --- /dev/null +++ b/src/sdl/InitSDL.cpp @@ -0,0 +1,27 @@ +/* + * InitSDL.cpp + * + * Created on: Apr 22, 2012 + * Author: holy + */ + +#include "InitSDL.h" + +#include + +using std::runtime_error; + + +namespace sdl { + +InitSDL::InitSDL(Uint32 flags) { + if (SDL_Init(flags) != 0) { + throw runtime_error("failed to initialize SDL"); + } +} + +InitSDL::~InitSDL(void) { + SDL_Quit(); +} + +} diff --git a/src/sdl/InitSDL.h b/src/sdl/InitSDL.h new file mode 100644 index 0000000..631b8c9 --- /dev/null +++ b/src/sdl/InitSDL.h @@ -0,0 +1,29 @@ +/* + * InitSDL.h + * + * Created on: Apr 22, 2012 + * Author: holy + */ + +#ifndef SDL_INITSDL_H_ +#define SDL_INITSDL_H_ + +#include + + +namespace sdl { + +class InitSDL { + +public: + explicit InitSDL(Uint32 flags = SDL_INIT_EVERYTHING); + virtual ~InitSDL(void); +private: + InitSDL(const InitSDL &); + InitSDL &operator =(const InitSDL &); + +}; + +} + +#endif /* SDL_INITSDL_H_ */ diff --git a/src/sdl/InitScreen.cpp b/src/sdl/InitScreen.cpp new file mode 100644 index 0000000..c9b275f --- /dev/null +++ b/src/sdl/InitScreen.cpp @@ -0,0 +1,28 @@ +/* + * InitScreen.cpp + * + * Created on: Apr 22, 2012 + * Author: holy + */ + +#include "InitScreen.h" + +#include + +using std::runtime_error; + + +namespace sdl { + +InitScreen::InitScreen(int width, int height, int bpp, Sint32 flags) +: screen(SDL_SetVideoMode(width, height, bpp, flags)) { + if (!screen) { + throw runtime_error("failed to open screen"); + } +} + +InitScreen::~InitScreen(void) { + +} + +} diff --git a/src/sdl/InitScreen.h b/src/sdl/InitScreen.h new file mode 100644 index 0000000..54e7680 --- /dev/null +++ b/src/sdl/InitScreen.h @@ -0,0 +1,37 @@ +/* + * InitScreen.h + * + * Created on: Apr 22, 2012 + * Author: holy + */ + +#ifndef SDL_INITSCREEN_H_ +#define SDL_INITSCREEN_H_ + +#include + +namespace sdl { + +class InitScreen { + +public: + InitScreen(int width, int height, int bpp = 32, Sint32 flags = SDL_HWSURFACE | SDL_DOUBLEBUF); + virtual ~InitScreen(void); +private: + InitScreen(const InitScreen &); + InitScreen &operator =(const InitScreen &); + +public: + SDL_Surface *Screen(void) { return screen; }; + const SDL_Surface *Screen(void) const { return screen; }; + + void Flip(void) { SDL_Flip(screen); }; + +private: + SDL_Surface *screen; + +}; + +} + +#endif /* SDL_INITSCREEN_H_ */