]> git.localhorst.tv Git - l2e.git/commitdiff
added SDL initialization classes
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 1 Aug 2012 20:58:08 +0000 (22:58 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 1 Aug 2012 20:58:08 +0000 (22:58 +0200)
15 files changed:
Debug/makefile
Debug/objects.mk
Debug/sources.mk
Debug/src/sdl/subdir.mk [new file with mode: 0644]
Debug/src/subdir.mk
Release/makefile
Release/objects.mk
Release/sources.mk
Release/src/sdl/subdir.mk [new file with mode: 0644]
Release/src/subdir.mk
src/main.cpp
src/sdl/InitSDL.cpp [new file with mode: 0644]
src/sdl/InitSDL.h [new file with mode: 0644]
src/sdl/InitScreen.cpp [new file with mode: 0644]
src/sdl/InitScreen.h [new file with mode: 0644]

index 7cfe0c440018b3bc5fec0c95de550aee65b8c451..7439cadb2393e57aad28b62b2db3c663d27b0b8d 100644 (file)
@@ -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
index 742c2da043f4f5d93c414dca3a725ab2204d9817..b99d1e557524bff7e90047ab535352d6c2d0af69 100644 (file)
@@ -4,5 +4,5 @@
 
 USER_OBJS :=
 
-LIBS :=
+LIBS := -lSDL
 
index e7f4bf132b8025d4f949adeee717652f8a7f25c3..414d5595efb298ef462d8085f64bc8203167e610 100644 (file)
@@ -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 (file)
index 0000000..67239ce
--- /dev/null
@@ -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 ' '
+
+
index 4257574fc844d01bd0b15752683d470705bdbc01..b8432d7a8d630876b48aa2ae99616f5de673b4ac 100644 (file)
@@ -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 ' '
 
index 7cfe0c440018b3bc5fec0c95de550aee65b8c451..7439cadb2393e57aad28b62b2db3c663d27b0b8d 100644 (file)
@@ -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
index 742c2da043f4f5d93c414dca3a725ab2204d9817..b99d1e557524bff7e90047ab535352d6c2d0af69 100644 (file)
@@ -4,5 +4,5 @@
 
 USER_OBJS :=
 
-LIBS :=
+LIBS := -lSDL
 
index e7f4bf132b8025d4f949adeee717652f8a7f25c3..414d5595efb298ef462d8085f64bc8203167e610 100644 (file)
@@ -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 (file)
index 0000000..ad789ab
--- /dev/null
@@ -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 ' '
+
+
index df4637c45e4f77433327f9cd70680d86ddcef324..e2d08a05f0855664cb9acd9cc25a45ab9c102c7b 100644 (file)
@@ -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 ' '
 
index 0fce8fe511640d4e9f3fdb7fa9feceaa224e7e1a..2040663eba42195dd402a2aa0f5034d127ba5c1c 100644 (file)
@@ -5,6 +5,31 @@
  *      Author: holy
  */
 
+#include "sdl/InitScreen.h"
+#include "sdl/InitSDL.h"
+
+#include <exception>
+#include <iostream>
+
+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 (file)
index 0000000..0f2eacd
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * InitSDL.cpp
+ *
+ *  Created on: Apr 22, 2012
+ *      Author: holy
+ */
+
+#include "InitSDL.h"
+
+#include <stdexcept>
+
+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 (file)
index 0000000..631b8c9
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * InitSDL.h
+ *
+ *  Created on: Apr 22, 2012
+ *      Author: holy
+ */
+
+#ifndef SDL_INITSDL_H_
+#define SDL_INITSDL_H_
+
+#include <SDL/SDL.h>
+
+
+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 (file)
index 0000000..c9b275f
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * InitScreen.cpp
+ *
+ *  Created on: Apr 22, 2012
+ *      Author: holy
+ */
+
+#include "InitScreen.h"
+
+#include <stdexcept>
+
+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 (file)
index 0000000..54e7680
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * InitScreen.h
+ *
+ *  Created on: Apr 22, 2012
+ *      Author: holy
+ */
+
+#ifndef SDL_INITSCREEN_H_
+#define SDL_INITSCREEN_H_
+
+#include <SDL/SDL.h>
+
+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_ */