From 45c8964c49f80539b7d22c1fcd24dcccab0bd3c4 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 10 Aug 2008 17:14:54 +0200 Subject: [PATCH] Namepsace in Dateien eingefuegt. GL aus Rect/Color entfernt Compiled als .so --- .gitignore | 1 + Makefile | 32 +++++++- catmullromspline.cpp | 4 + catmullromspline.h | 2 + color.cpp | 43 ++++++++++ glcolor.h => color.h | 18 +++-- emath.cpp | 4 + emath.h | 4 + emath_opengl.cpp | 4 + emath_opengl.h | 5 ++ extstring.cpp | 4 + extstring.h | 4 + fpsmanager.cpp | 4 + fpsmanager.h | 4 + geotypes.cpp | 103 ++++++++++++++++++++++++ geotypes.h | 70 ++++++++++++++++ glcamera.cpp | 4 + glcamera.h | 4 + glcolor.cpp | 39 --------- gldrawhelper.cpp | 8 +- gldrawhelper.h | 7 +- glfontengine.cpp | 5 +- glfontengine.h | 9 ++- glgui/button.cpp | 7 +- glgui/button.h | 6 +- glgui/textlabel.cpp | 7 +- glgui/textlabel.h | 10 ++- glgui/window.cpp | 10 ++- glgui/window.h | 9 ++- glmenu/menuitem.cpp | 6 +- glmenu/menuitem.h | 4 + glmenu/menuitems.cpp | 4 + glmenu/menuitems.h | 4 + glmenu/menumanager.cpp | 4 + glmenu/menumanager.h | 3 + glmenu/menumenu.cpp | 4 + glmenu/menumenu.h | 4 + glrect.cpp | 35 -------- glsdlscreen.cpp | 4 + glsdlscreen.h | 4 + gltexture.cpp | 6 +- gltexture.h | 4 + main.cpp | 177 ----------------------------------------- matrix.cpp | 4 + matrix.h | 4 +- model/loadobj.cpp | 4 + model/loadobj.h | 4 + model/model.cpp | 8 +- model/model.h | 12 ++- model/modelloader.cpp | 4 + model/modelloader.h | 3 + punkt2d.cpp | 27 ++++--- punkt2d.h | 13 ++- punkt3d.cpp | 45 ++++++----- punkt3d.h | 24 +++--- quader.cpp | 4 + quader.h | 3 + quaternion.cpp | 4 + quaternion.h | 4 + rect.cpp | 40 ++++++++++ glrect.h => rect.h | 16 ++-- rotationsmatrix.cpp | 4 + rotationsmatrix.h | 4 + sdlfuncs.cpp | 4 + sdlfuncs.h | 4 + testprog.cpp | 14 ---- testprog.h | 0 67 files changed, 591 insertions(+), 356 deletions(-) create mode 100644 color.cpp rename glcolor.h => color.h (63%) create mode 100644 geotypes.cpp create mode 100644 geotypes.h delete mode 100644 glcolor.cpp delete mode 100644 glrect.cpp delete mode 100644 main.cpp create mode 100644 rect.cpp rename glrect.h => rect.h (56%) delete mode 100644 testprog.cpp delete mode 100644 testprog.h diff --git a/.gitignore b/.gitignore index 957757d..fd3e4fe 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.o *.a +libsegl.so.* testprog diff --git a/Makefile b/Makefile index 506aab3..0534258 100755 --- a/Makefile +++ b/Makefile @@ -1,18 +1,27 @@ CC = g++ AR = ar -OBJECTS = punkt3d.o punkt2d.o emath.o emath_opengl.o glcolor.o gldrawhelper.o glfontengine.o glrect.o gltexture.o matrix.o quaternion.o rotationsmatrix.o glsdlscreen.o sdlfuncs.o fpsmanager.o glcamera.o catmullromspline.o extstring.o quader.o -OBJOPT = -Wall -c `sdl-config --cflags` +OBJECTS = punkt3d.o punkt2d.o emath.o emath_opengl.o color.o gldrawhelper.o glfontengine.o rect.o gltexture.o matrix.o quaternion.o rotationsmatrix.o glsdlscreen.o sdlfuncs.o fpsmanager.o glcamera.o catmullromspline.o extstring.o quader.o +OBJOPT = -Wall -c -DVERSION=$(VERSION) -O2 `sdl-config --cflags` +WINOPT = -Wall -c -DVERSION=$(VERSION) -O2 -I/usr/i586-mingw32msvc/include -I/usr/i586-mingw32msvc/include/SDL +LIBLINK = -lc -shared -Wl,-soname,$(LIBNAME).so.$(LIBVERSION) +WINLINK = -L/usr/i586-mingw32msvc/lib /usr/i586-mingw32msvc/lib/SDL_image.lib -lmingw32 -shared -mwindows -lGL -lGLU -lSDL -lSDL_image /usr/i586-mingw32msvc/lib/SDL_image.lib /usr/i586-mingw32msvc/lib/SDL_image.dll SUBDIRS = glgui glmenu model SUBDIROBJECTS = glgui/*.o glmenu/*.o model/*.o -VERSION = 0.0.1 +VERSION = 0.1.1 +LIBVERSION = 1 LIBNAME = libsegl +EXT = so.$(LIBVERSION) + +.PHONY: windows seglar: $(OBJECTS) subdirs rm -f $(LIBNAME).a $(AR) rcs $(LIBNAME).a $(OBJECTS) $(SUBDIROBJECTS) # ranlib $(LIBNAME).a -segllib: $(OBJECTS) subdirs +lib: LINKER = $(LINKER) +lib: $(OBJECTS) subdirs + $(CC) -o $(LIBNAME).$(EXT) $(OBJECTS) $(SUBDIROBJECTS) $(LIBLINK) subdirs: @for i in $(SUBDIRS); do $(MAKE) CC="$(CC)" AR="$(AR)" OBJOPT="$(OBJOPT)" -C $$i; done @@ -30,6 +39,21 @@ glmenu/glmenu.a: testprog: seglar testprog.o g++ `sdl-config --libs` -lSDL_image -lGL -lGLU testprog.o -o testprog $(LIBNAME).a +winlib: CC = i586-mingw32msvc-g++ +winlib: AR = i586-mingw32msvc-ar +winlib: OBJOPT = $(WINOPT) +winlib: LIBLINK = $(WINLINK) +winlib: export EXT = dll +winlib: lib + +winar: CC = i586-mingw32msvc-g++ +winar: AR = i586-mingw32msvc-ar +winar: OBJOPT = $(WINOPT) +winar: LIBLINK = $(WINLINK) +winar: export EXT = dll +winar: seglar + + cleansubdirs: @for i in $(SUBDIRS); do $(MAKE) clean -C $$i; done diff --git a/catmullromspline.cpp b/catmullromspline.cpp index 0e71eda..a00529a 100644 --- a/catmullromspline.cpp +++ b/catmullromspline.cpp @@ -1,5 +1,7 @@ #include "catmullromspline.h" +namespace segl { + CatmullRomSpline::CatmullRomSpline(float _s) { cr = new Matrix(4, 4); setS(_s); @@ -99,3 +101,5 @@ void CatmullRomSpline::setS(float _s) { CatmullRomSpline::~CatmullRomSpline() { delete(cr); } + +} // namespace segl diff --git a/catmullromspline.h b/catmullromspline.h index 1a71204..b113af8 100644 --- a/catmullromspline.h +++ b/catmullromspline.h @@ -8,6 +8,7 @@ #include "punkt2d.h" #include "punkt3d.h" +namespace segl { class CatmullRomSpline { private: @@ -27,5 +28,6 @@ class CatmullRomSpline { ~CatmullRomSpline(); }; +} // namespace segl #endif diff --git a/color.cpp b/color.cpp new file mode 100644 index 0000000..7de0ebc --- /dev/null +++ b/color.cpp @@ -0,0 +1,43 @@ +#include "color.h" + +namespace segl { + +Color::Color() { + set(0.0f, 0.0f, 0.0f, 1.0f); + setalpha = true; +} + +Color::Color(float _r, float _g, float _b, float _a) { + set(_r, _g, _b, _a); +} + +Color::Color(const SDL_Color &c) { + set(c.r/255.0f, c.g/255.0f, c.b/255.0f); + setalpha = true; +} + +void Color::set(float _r, float _g, float _b, float _a) { + r = _r; + g = _g; + b = _b; + a = _a; +} + +SDL_Color Color::getSDLColor() { + SDL_Color c = {(Uint8)(r*255.0f), (Uint8)(g*255.0f), (Uint8)(b*255.0f), (Uint8)(a*255.0f)}; + return c; +} + +void Color::print(std::string m) { + std::cout << m << " Color: " << r << ", " << g << ", " << b << std::endl; +} + +} // namespace segl + +void glColorGLC(segl::Color c) { + if(c.setalpha) { + glColor4f(c.r, c.g, c.b, c.a); + } else { + glColor3f(c.r, c.g, c.b); + } +} diff --git a/glcolor.h b/color.h similarity index 63% rename from glcolor.h rename to color.h index d1ad223..edbc0e3 100644 --- a/glcolor.h +++ b/color.h @@ -1,27 +1,31 @@ -#ifndef __GLCOLOR_H -#define __GLCOLOR_H +#ifndef __COLOR_H +#define __COLOR_H #include #include #include #include -class GLColor { +namespace segl { + +class Color { public: float r, g, b, a; bool setalpha; - GLColor(); - GLColor(float _r, float _g, float _b, float _a=1.0f); - GLColor(const SDL_Color&); + Color(); + Color(float _r, float _g, float _b, float _a=1.0f); + Color(const SDL_Color&); void set(float _r, float _g, float _b, float _a=1.0f); SDL_Color getSDLColor(); void print(std::string m=""); }; -void glColorGLC(GLColor c); +} // namespace segl + +void glColorGLC(segl::Color c); // a) setalpha entscheiden lassen // b) zwei funktionen, eine setzt alpha mit in richtung 3f, 4f.. diff --git a/emath.cpp b/emath.cpp index 07ba569..de7473c 100644 --- a/emath.cpp +++ b/emath.cpp @@ -1,5 +1,7 @@ #include "emath.h" +namespace segl { + // Trigonometrische Funktionen float deg2rad(float deg) { @@ -34,3 +36,5 @@ float ssin(float c) { float scos(float c) { return ssin(c+90.0f); } + +} // namespace segl diff --git a/emath.h b/emath.h index 39b518b..45047e8 100644 --- a/emath.h +++ b/emath.h @@ -5,6 +5,7 @@ #include #include +namespace segl { float deg2rad(float deg); float rad2deg(float rad); @@ -15,4 +16,7 @@ float rad2deg(float rad); float ssin(float); float scos(float); +} // namespace segl + + #endif diff --git a/emath_opengl.cpp b/emath_opengl.cpp index a79c158..e2a4472 100644 --- a/emath_opengl.cpp +++ b/emath_opengl.cpp @@ -1,5 +1,7 @@ #include "emath_opengl.h" +namespace segl { + void rotFrom2VecTo2Vec(Punkt3D a, Punkt3D b, Punkt3D c, Punkt3D d, Punkt3D *rvec, float *rvecdeg, Punkt3D *rvec2, float *rvecdeg2) { Punkt3D rotvec, rotvec2, nullvec; float rotvecdeg = 0.0f, rotvecdeg2 = 0.0f; @@ -71,3 +73,5 @@ void rotvec2(Punkt3D a, Punkt3D b, Punkt3D c, Punkt3D d, float *dega, Punkt3D *v else *vecb = c.kreuzprodukt(d); } + +} // namespace segl diff --git a/emath_opengl.h b/emath_opengl.h index 24cfce2..fc7d9d3 100644 --- a/emath_opengl.h +++ b/emath_opengl.h @@ -7,7 +7,12 @@ #include "rotationsmatrix.h" #include +namespace segl { + void rotFrom2VecTo2Vec(Punkt3D a, Punkt3D b, Punkt3D c, Punkt3D d, Punkt3D *, float *, Punkt3D *, float *); void rotFrom2VecTo2Vec(Punkt3D a, Punkt3D b, Punkt3D c, Punkt3D d); void rotvec2(Punkt3D a, Punkt3D b, Punkt3D c, Punkt3D d, float *dega, Punkt3D *veca, float *degb, Punkt3D *vecb); + +} // namespace segl + #endif diff --git a/extstring.cpp b/extstring.cpp index 4ff1cba..88f5be6 100644 --- a/extstring.cpp +++ b/extstring.cpp @@ -1,5 +1,7 @@ #include "extstring.h" +namespace segl { + int explode(std::string str, std::string delim, std::vector *erg, bool clean) { erg->clear(); @@ -45,3 +47,5 @@ std::string basename(std::string str) { std::string rbasename(std::string str) { return str.substr(0, str.rfind("/")+1); } + +} // namespace segl diff --git a/extstring.h b/extstring.h index 03639e5..6283d70 100644 --- a/extstring.h +++ b/extstring.h @@ -4,9 +4,13 @@ #include #include +namespace segl { + int explode(std::string str, std::string delim, std::vector *erg, bool clean=false); std::string trim(std::string t); std::string basename(std::string str); std::string rbasename(std::string str); +} // namespace segl + #endif diff --git a/fpsmanager.cpp b/fpsmanager.cpp index 9c84af1..11b53df 100644 --- a/fpsmanager.cpp +++ b/fpsmanager.cpp @@ -1,5 +1,7 @@ #include "fpsmanager.h" +namespace segl { + FPSManager::FPSManager(int _fps) { setFPS(_fps); frames = 0; @@ -31,3 +33,5 @@ void FPSManager::delay() { float FPSManager::getFPS() { return framerate; } + +} // namespace segl diff --git a/fpsmanager.h b/fpsmanager.h index bf45d53..1176224 100644 --- a/fpsmanager.h +++ b/fpsmanager.h @@ -3,6 +3,8 @@ #include +namespace segl { + class FPSManager { private: Uint32 lastticks; @@ -17,4 +19,6 @@ class FPSManager { float getFPS(); }; +} // namespace segl + #endif diff --git a/geotypes.cpp b/geotypes.cpp new file mode 100644 index 0000000..20d2f1c --- /dev/null +++ b/geotypes.cpp @@ -0,0 +1,103 @@ +#include "geotypes.h" + +namespace segl { + +Sphere::Sphere(Punkt3D _pos, float _radius) { + pos = _pos; + radius = _radius; +} + +Sphere::Sphere() { + radius = 1.0f; +} + +bool Sphere::collision(const Sphere &s) { + +} + +bool Sphere::collision(const Ray &r) { + +} + +bool Sphere::collision(const Box & b) { + +} + +bool Sphere::collision(const Plane &p) { + +} + +Ray::Ray() { + dir.set(0.0f, 1.0f, 0.0f); +} + +Ray::Ray(Punkt3D _pos, Punkt3D _dir) { + pos = _pos; + dir = _dir; +} + +bool Ray::collision(const Sphere &s) { + return s.collision(*this); +} + +bool Ray::collision(const Ray &r); +bool Ray::collision(const Box & b); +bool Ray::collision(const Plane &p); + +Box::Box() { + max.set(1.0f, 1.0f, 1.0f); +} + +Box::Box(Punkt3D _min, Punkt3D _max) { + min = _min; + max = _max; +} + +bool Box::collision(const Sphere &s) { + return s.collision(*this); +} + +bool Box::collision(const Ray &r) { + return r.collision(*this); +} + +bool Box::collision(const Box & b) { + +} + +bool Box::collision(const Plane &p) { + +} + +Plane::Plane() { + norm.set(0.0f, 1.0f, 0.0f); +} + +Plane::Plane(Punkt3D _pos, Punkt3D _norm) { + pos = _pos; + norm = _norm; +} + +Plane::Plane(float x, float y, float z, float a) { + // TODO: Implementation (if not too lazy) + norm.set(x, y, z); + norm.normalize(); +} + +bool Plane::collision(const Sphere &s) { + return s.collision(*this); +} + +bool Plane::collision(const Ray &r) { + return r.collision(*this); +} + +bool Plane::collision(const Box & b) { + return b.collision(*this); +} + +bool Plane::collision(const Plane &p) { + +} + +} // namespace segl diff --git a/geotypes.h b/geotypes.h new file mode 100644 index 0000000..15d8460 --- /dev/null +++ b/geotypes.h @@ -0,0 +1,70 @@ +#ifndef __GEOTYPES_H +#define __GEOTYPES_H + +#include "punkt3d.h" + +namespace segl { + +class Ray; +class Box +class Plane; + + +class Sphere { + public: + Punkt3D pos; + float radius; + + Sphere(Punkt3D _pos, float radius); + Sphere(); + + bool collision(const Sphere &s); + bool collision(const Ray &r); + bool collision(const Box & b); + bool collision(const Plane &p); +}; + +class Ray { + public: + Punkt3D pos; + Punkt3D dir; + + Ray(); + Ray(Punkt3D _pos, Punkt3D _dir); + + bool collision(const Sphere &s); + bool collision(const Ray &r); + bool collision(const Box & b); + bool collision(const Plane &p); +}; + +class Box { + public: + Punkt3D min; + Punkt3D max; + + Box(); + Box(Punkt3D _min, Punkt3D _max); + + bool collision(const Sphere &s); + bool collision(const Ray &r); + bool collision(const Box & b); + bool collision(const Plane &p); +}; + +class Plane { + public: + Punkt3D pos; + Punkt3D norm; + + Plane(); + Plane(Punkt3D _pos, Punkt3D _norm); + Plane(float x, float y, float z, float a); + + bool collision(const Sphere &s); + bool collision(const Ray &r); + bool collision(const Box & b); + bool collision(const Plane &p); +}; + +} // namespace segl diff --git a/glcamera.cpp b/glcamera.cpp index 64c108c..cd75e8e 100644 --- a/glcamera.cpp +++ b/glcamera.cpp @@ -1,5 +1,7 @@ #include "glcamera.h" +namespace segl { + GLCamera::GLCamera() { std_norm.set(0.0f, 1.0f, 0.0f); std_dir.set(0.0f, 0.0f, -1.0f); @@ -182,3 +184,5 @@ Punkt3D GLCamera::getPos() { GLCamera::~GLCamera() { } + +} // namespace segl diff --git a/glcamera.h b/glcamera.h index 7119715..2547d0b 100644 --- a/glcamera.h +++ b/glcamera.h @@ -8,6 +8,8 @@ #include "emath_opengl.h" #include "punkt3d.h" +namespace segl { + class GLCamera { private: Punkt3D std_dir; @@ -57,4 +59,6 @@ class GLCamera { ~GLCamera(); }; +} // namespace segl { + #endif diff --git a/glcolor.cpp b/glcolor.cpp deleted file mode 100644 index ed5a8c1..0000000 --- a/glcolor.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "glcolor.h" - -GLColor::GLColor() { - set(0.0f, 0.0f, 0.0f, 1.0f); - setalpha = true; -} - -GLColor::GLColor(float _r, float _g, float _b, float _a) { - set(_r, _g, _b, _a); -} - -GLColor::GLColor(const SDL_Color &c) { - set(c.r/255.0f, c.g/255.0f, c.b/255.0f); - setalpha = true; -} - -void GLColor::set(float _r, float _g, float _b, float _a) { - r = _r; - g = _g; - b = _b; - a = _a; -} - -SDL_Color GLColor::getSDLColor() { - SDL_Color c = {(Uint8)(r*255.0f), (Uint8)(g*255), (Uint8)(b*255), (Uint8)(a*255)}; - return c; -} - -void GLColor::print(std::string m) { - std::cout << m << " Color: " << r << ", " << g << ", " << b << std::endl; -} - -void glColorGLC(GLColor c) { - if(c.setalpha) { - glColor4f(c.r, c.g, c.b, c.a); - } else { - glColor3f(c.r, c.g, c.b); - } -} diff --git a/gldrawhelper.cpp b/gldrawhelper.cpp index 94b2c02..731bebc 100644 --- a/gldrawhelper.cpp +++ b/gldrawhelper.cpp @@ -1,7 +1,9 @@ #include "gldrawhelper.h" -void GLDrawSDLRect(SDL_Rect *rect, GLRect *tex) { - GLRect tmptex; +namespace segl { + +void GLDrawSDLRect(SDL_Rect *rect, Rect *tex) { + Rect tmptex; if(tex) { tmptex = *tex; } else { @@ -22,3 +24,5 @@ void GLDrawSDLRect(SDL_Rect *rect, GLRect *tex) { glVertex2i(rect->x, rect->y); glEnd(); } + +} // namespace segl diff --git a/gldrawhelper.h b/gldrawhelper.h index ecf83aa..1431f0c 100644 --- a/gldrawhelper.h +++ b/gldrawhelper.h @@ -4,9 +4,12 @@ #include #include -#include "glrect.h" +#include "rect.h" -void GLDrawSDLRect(SDL_Rect *rect, GLRect *tex=0); +namespace segl { +void GLDrawSDLRect(SDL_Rect *rect, Rect *tex=0); + +} // namespace segl #endif diff --git a/glfontengine.cpp b/glfontengine.cpp index 7785d3f..6d61c5f 100644 --- a/glfontengine.cpp +++ b/glfontengine.cpp @@ -1,5 +1,6 @@ #include "glfontengine.h" +namespace segl { bool GLFontEngine::addFont(std::string fontfile, std::string fontname) { GLFont *tmp = new GLFont(fontfile, 0.685f); @@ -80,7 +81,7 @@ void GLFontEngine::setColor(float _r, float _g, float _b, float _a) { col.set(_r, _g, _b, _a); } -void GLFontEngine::setColor(GLColor c) { +void GLFontEngine::setColor(Color c) { col = c; } @@ -247,3 +248,5 @@ int GLFontEngine::getTextWidthbyInt(int length) { } std::map GLFontEngine::fontpool; + +} // namespace segl diff --git a/glfontengine.h b/glfontengine.h index 00e56e3..839a7d4 100644 --- a/glfontengine.h +++ b/glfontengine.h @@ -11,7 +11,9 @@ #include #include #include "gltexture.h" -#include "glcolor.h" +#include "color.h" + +namespace segl { class GLFont { public: @@ -32,7 +34,7 @@ class GLFontEngine { GLFont *font; bool fontloaded; - GLColor col; + Color col; // float r, g, b, a; int fsize; @@ -49,7 +51,7 @@ class GLFontEngine { GLFontEngine(std::string); bool fontSelect(std::string); void setColor(float, float, float, float=1.0f); - void setColor(GLColor); + void setColor(Color); void renderText(std::string, SDL_Rect); // wrapper // void renderText(std::string, int x, int y, *SDL_Rect=0, bool center=false); @@ -67,5 +69,6 @@ class GLFontEngine { }; +} // namespace segl #endif diff --git a/glgui/button.cpp b/glgui/button.cpp index 2b4ca71..b5f1667 100644 --- a/glgui/button.cpp +++ b/glgui/button.cpp @@ -1,11 +1,14 @@ #include "button.h" +namespace segl { + GLGuiButton::GLGuiButton(int _eventid, int _x, int _y, bool _center, int _wrap) : GLGuiTextLabel(_x, _y, _center, _wrap) { highlightable = true; clickable = true; eventid = _eventid; highlightcol.set(1.0f, 0.0f, 0.0f, 1.0f); } + GLGuiButton::GLGuiButton(int _eventid, std::string str, int _x, int _y, bool _center, int _wrap) : GLGuiTextLabel(str, _x, _y, _center, _wrap){ highlightable = true; clickable = true; @@ -14,7 +17,7 @@ GLGuiButton::GLGuiButton(int _eventid, std::string str, int _x, int _y, bool _ce } void GLGuiButton::onMouseOver(int m_x, int m_y) { - // Längste stelle finden, dann collision + // L�ngste stelle finden, dann collision } void GLGuiButton::onMouseClick(int m_x, int m_y, int m_button) { @@ -23,3 +26,5 @@ void GLGuiButton::onMouseClick(int m_x, int m_y, int m_button) { e.user.code = eventid; SDL_PushEvent(&e); } + +} // namespace diff --git a/glgui/button.h b/glgui/button.h index 39ff8fa..a46d42b 100644 --- a/glgui/button.h +++ b/glgui/button.h @@ -10,10 +10,12 @@ #define GLGUI_BUTTONDOWN SDL_USEREVENT+10 +namespace segl { + class GLGuiButton : public GLGuiTextLabel { protected: int eventid; - GLColor highlightcol; + Color highlightcol; public: GLGuiButton(int _eventid, int _x, int _y, bool _center=false, int _wrap=0); @@ -25,4 +27,6 @@ class GLGuiButton : public GLGuiTextLabel { void onMouseClick(int m_x, int m_y, int m_button); }; +} // namespace { + #endif diff --git a/glgui/textlabel.cpp b/glgui/textlabel.cpp index 1fbfcbe..7439ca9 100644 --- a/glgui/textlabel.cpp +++ b/glgui/textlabel.cpp @@ -1,5 +1,7 @@ #include "textlabel.h" +namespace segl { + GLGuiTextLabel::GLGuiTextLabel(int _x, int _y, bool _center, int _wrap) { setPos(_x, _y); center = _center; @@ -19,7 +21,7 @@ void GLGuiTextLabel::setText(std::string str) { text = str; } -void GLGuiTextLabel::setColor(GLColor c) { +void GLGuiTextLabel::setColor(Color c) { col = c; } @@ -35,3 +37,6 @@ void GLGuiTextLabel::render() { fontengine.renderLines(text, x, y, center, 0, wrap, 0); GLFontEngine::regain3DbyPoppingMatrix(); } + +} // namespace segl + diff --git a/glgui/textlabel.h b/glgui/textlabel.h index c2050c8..bb54def 100644 --- a/glgui/textlabel.h +++ b/glgui/textlabel.h @@ -7,15 +7,17 @@ #include #include "object.h" -#include "../glcolor.h" +#include "../color.h" #include "../glfontengine.h" +namespace segl { + class GLGuiTextLabel : public GLGuiObject{ protected: GLFontEngine fontengine; std::string text; - GLColor col; + Color col; int x, y; bool center; int wrap; @@ -24,9 +26,11 @@ class GLGuiTextLabel : public GLGuiObject{ GLGuiTextLabel(std::string, int _x, int _y, bool _center=false, int _wrap=0); void setText(std::string str); - void setColor(GLColor); + void setColor(Color); void setPos(int _x, int _y); virtual void render(); }; +} // namespace segl + #endif diff --git a/glgui/window.cpp b/glgui/window.cpp index d58fa31..54f68b5 100644 --- a/glgui/window.cpp +++ b/glgui/window.cpp @@ -1,12 +1,14 @@ #include "window.h" -GLGuiWindow::GLGuiWindow(SDL_Rect _pos, GLColor _bgcolor) { +namespace segl { + +GLGuiWindow::GLGuiWindow(SDL_Rect _pos, Color _bgcolor) { pos = _pos; bgcolor = _bgcolor; } void GLGuiWindow::addItem(GLGuiObject *gobj) { - // Objekt wird in delete gelöscht + // Objekt wird in delete gel�scht items.push_back(gobj); if(gobj->isHighlightable()) highlightable.push_back(gobj); @@ -33,8 +35,10 @@ SDL_Rect GLGuiWindow::getPos() { } GLGuiWindow::~GLGuiWindow() { -// der der allokiert soll sich gefälligst drum kümmern +// der der allokiert soll sich gef�lligst drum k�mmern // for(unsigned int i=0; i #include -#include "../glcolor.h" +#include "../color.h" #include "../gldrawhelper.h" #include "object.h" +namespace segl { class GLGuiWindow : public GLGuiObject { private: bool renderbackground; SDL_Rect pos; - GLColor bgcolor; + Color bgcolor; std::vector items; @@ -24,7 +25,7 @@ class GLGuiWindow : public GLGuiObject { std::vector clickable; std::vector keyboardable; public: - GLGuiWindow(SDL_Rect _pos, GLColor _bgcolor); + GLGuiWindow(SDL_Rect _pos, Color _bgcolor); ~GLGuiWindow(); void addItem(GLGuiObject*); @@ -32,4 +33,6 @@ class GLGuiWindow : public GLGuiObject { void render(); }; +} // namespace segl + #endif diff --git a/glmenu/menuitem.cpp b/glmenu/menuitem.cpp index 160b41c..ad999df 100644 --- a/glmenu/menuitem.cpp +++ b/glmenu/menuitem.cpp @@ -1,5 +1,7 @@ #include "menuitem.h" +namespace segl { + MenuItem::MenuItem(std::string c) { caption = c; fontsizeadd = 0; @@ -40,7 +42,7 @@ void MenuItem::render(Punkt2D pos, bool center, int basefontsize, int maxwidth, if(!usevalue) { fontengine.renderLine(caption, (int)pos.x, (int)pos.y, center); } else { - // center und position ggf. überarbeiten.. + // center und position ggf. �berarbeiten.. Punkt2D tmp = pos; // tmp.x = pos.x - (caplen+vallen+valuewidth)/2; @@ -79,3 +81,5 @@ MenuItem::~MenuItem() { } + +} // namespace segl diff --git a/glmenu/menuitem.h b/glmenu/menuitem.h index a29fb85..3641fe9 100644 --- a/glmenu/menuitem.h +++ b/glmenu/menuitem.h @@ -5,6 +5,8 @@ #include "../glfontengine.h" #include "../punkt2d.h" +namespace segl { + class MenuItem { protected: std::string caption; @@ -43,4 +45,6 @@ class MenuItem { virtual void render(Punkt2D pos, bool center, int basefontsize, int maxwidth, int valuewidth, bool highlight, int caplen, int capvallen, int maxlen); }; +} // namespace segl + #endif diff --git a/glmenu/menuitems.cpp b/glmenu/menuitems.cpp index 2b2df3b..e9ef1ec 100644 --- a/glmenu/menuitems.cpp +++ b/glmenu/menuitems.cpp @@ -1,5 +1,7 @@ #include "menuitems.h" +namespace segl { + // MISendSDLEvent MISendSDLEvent::MISendSDLEvent(std::string str, SDL_Event event) : MenuItem(str) { @@ -201,3 +203,5 @@ void MIEventOnToggle::right() { void MIEventOnToggle::resetEvent(SDL_Event event) { sendevent = event; } + +} // namespace segl diff --git a/glmenu/menuitems.h b/glmenu/menuitems.h index 53d5f7a..4528522 100644 --- a/glmenu/menuitems.h +++ b/glmenu/menuitems.h @@ -6,6 +6,8 @@ #include #include "menuitem.h" +namespace segl { + class MISendSDLEvent : public MenuItem { private: SDL_Event sendevent; @@ -97,4 +99,6 @@ class MIEventOnToggle : public MIToggle { void resetEvent(SDL_Event event); }; +} // namespace segl + #endif diff --git a/glmenu/menumanager.cpp b/glmenu/menumanager.cpp index 0bc5442..fe20ea8 100644 --- a/glmenu/menumanager.cpp +++ b/glmenu/menumanager.cpp @@ -1,5 +1,7 @@ #include "menumanager.h" +namespace segl { + MenuManager::MenuManager() { aktuell = 0; } @@ -69,3 +71,5 @@ void MenuManager::reset() { } } + +} // namespace segl diff --git a/glmenu/menumanager.h b/glmenu/menumanager.h index 814efd9..873e6bc 100644 --- a/glmenu/menumanager.h +++ b/glmenu/menumanager.h @@ -6,6 +6,7 @@ #include "../glfontengine.h" #include "menumenu.h" +namespace segl { class MenuManager { private: @@ -31,4 +32,6 @@ class MenuManager { void reset(); }; +} // namespace segl + #endif diff --git a/glmenu/menumenu.cpp b/glmenu/menumenu.cpp index a92538b..a800ca0 100644 --- a/glmenu/menumenu.cpp +++ b/glmenu/menumenu.cpp @@ -1,5 +1,7 @@ #include "menumenu.h" +namespace segl { + MenuMenu::MenuMenu() { itempos = 0; centermenu = false; @@ -165,3 +167,5 @@ void MenuMenu::render() { } glEnable(GL_DEPTH_TEST); } + +} // namespace segl diff --git a/glmenu/menumenu.h b/glmenu/menumenu.h index ef1b5fa..54f3a81 100644 --- a/glmenu/menumenu.h +++ b/glmenu/menumenu.h @@ -6,6 +6,8 @@ #include "../punkt2d.h" #include "menuitem.h" +namespace segl { + class MenuMenu { private: std::vector menuitems; @@ -49,4 +51,6 @@ class MenuMenu { void render(); }; +} // namespace segl + #endif diff --git a/glrect.cpp b/glrect.cpp deleted file mode 100644 index 480b6b4..0000000 --- a/glrect.cpp +++ /dev/null @@ -1,35 +0,0 @@ -#include "glrect.h" - -GLRect::GLRect() { - set(0.0f, 0.0f, 0.0f, 0.0f); -} - -GLRect::GLRect(float _x, float _y, float _w, float _h) { - set(_x, _y, _w, _h); -} - -GLRect::GLRect(const SDL_Rect &r) { - set(r.x, r.y, r.w, r.h); -} - -void GLRect::set(float _x, float _y, float _w, float _h) { - x = _x; - y = _y; - w = _w; - h = _h; -} - -void GLRect::setPoint(float _x, float _y) { - x = _x; - y = _y; -} - -void GLRect::setDim(float _w, float _h) { - w = _w; - h = _h; -} - -SDL_Rect GLRect::getSDLRect() { - SDL_Rect tmp = {(Uint8)x, (Uint8)y, (Uint8)w, (Uint8)h}; - return tmp; -} diff --git a/glsdlscreen.cpp b/glsdlscreen.cpp index 2d612fa..fdec12e 100644 --- a/glsdlscreen.cpp +++ b/glsdlscreen.cpp @@ -1,5 +1,7 @@ #include "glsdlscreen.h" +namespace segl { + GLSDLScreen::GLSDLScreen() { width = 0; height = 1; @@ -152,3 +154,5 @@ void GLSDLScreen::clearScreen() { void GLSDLScreen::renderScreen() { SDL_GL_SwapBuffers(); } + +} // namespace segl diff --git a/glsdlscreen.h b/glsdlscreen.h index 3ffa365..4541bb2 100644 --- a/glsdlscreen.h +++ b/glsdlscreen.h @@ -6,6 +6,8 @@ #include #include "gltexture.h" +namespace segl { + class GLSDLScreen { private: SDL_Surface *screen; @@ -44,4 +46,6 @@ class GLSDLScreen { void renderScreen(); }; +} // namespace segl + #endif diff --git a/gltexture.cpp b/gltexture.cpp index cd50d07..6310ff8 100644 --- a/gltexture.cpp +++ b/gltexture.cpp @@ -1,5 +1,7 @@ #include "gltexture.h" +namespace segl { + GLTexture::GLTexture() { init(); alltextures.push_back(this); @@ -112,7 +114,7 @@ void GLTexture::unloadTexture() { glDeleteTextures(1, &texint); loaded = false; - // Entweder tex == image, wurde schon gelöscht oder wir müssen es nich löschen + // Entweder tex == image, wurde schon gel�scht oder wir m�ssen es nich l�schen } @@ -177,3 +179,5 @@ GLTexture::~GLTexture() { } std::vector GLTexture::alltextures; + +} // namespace segl diff --git a/gltexture.h b/gltexture.h index 0fa564b..e26a915 100644 --- a/gltexture.h +++ b/gltexture.h @@ -9,6 +9,8 @@ #include #include "sdlfuncs.h" +namespace segl { + class GLTexture { private: GLuint texint; @@ -60,4 +62,6 @@ class GLTexture { bool isLoaded(); }; +} // namespace segl + #endif diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 4db8011..0000000 --- a/main.cpp +++ /dev/null @@ -1,177 +0,0 @@ -#define VERSION "0.2.2 DEV" - -#include -#include - -#include -#include - -#include "gltexture.h" -#include "glfontengine.h" - -// #define GL_DEBUG_MOVEMENT false - -void setupGL(); -void resizeOpenGLWindow(int, int, float=1.0f, float=100.0f); - -int main(int argc, char **argv) { - std::cout << "ARGV: " << argv[0] << std::endl; - //Vars - SDL_Surface *screen; - bool quit = false; - SDL_Event event; - int w_width = 640; - int w_height = 480; - int w_bbp = 32; - float znear = 1.0f; - float zfar = 100.0f; - - if(SDL_Init(SDL_INIT_VIDEO)<0) { - std::cerr << "Konnte SDL nicht initialisieren" << SDL_GetError() << std::endl; - return 1; - } - - // Setting video mode - int videoFlags; - const SDL_VideoInfo *videoInfo; - - videoInfo = SDL_GetVideoInfo(); - - if(!videoInfo) { - std::cerr << "Video query failed: " << SDL_GetError() << std::endl; - return 1; - } - - videoFlags = SDL_OPENGL; - videoFlags |= SDL_GL_DOUBLEBUFFER; - videoFlags |= SDL_HWPALETTE; - videoFlags |= SDL_RESIZABLE; - if(videoInfo->hw_available) - videoFlags |= SDL_HWSURFACE; - else - videoFlags |= SDL_SWSURFACE; - if(videoInfo->blit_hw) - videoFlags |= SDL_HWACCEL; - -// videoFlags |=SDL_FULLSCREEN; - -// SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); -// SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 ); -// SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 ); -// SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); - SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); - - if(!(screen = SDL_SetVideoMode(w_width, w_height, w_bbp, videoFlags))) { - std::cerr << "Kein SDL-Screen verfügbar: " << SDL_GetError() << std::endl; - return 1; - } - SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); - - SDL_WM_SetCaption("GLGui Test, 0); - - // blank screen -// SDL_FillRect(screen, 0, SDL_MapRGBA(screen->format, 0, 0, 0, 0)); - - // GL Optionen - setupGL(); - - resizeOpenGLWindow(w_width, w_height, znear, zfar); - - // Keyrepeat, falls benötigt auskommentieren - SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); - - // Fontengine initliaisieren, für alle die Fonts brauchen - GLFontEngine::addFont("font_big_better_alpha.png", "default"); - - // Programmvariablen - Snake3D snake3d; - - //movement & keyboardcontrol - Uint8 *keys = SDL_GetKeyState(NULL);; - SDLKey tkey; - typedef enum { move_up=0, move_down, move_left, move_right} nummovekeys; - SDLKey movekeys[4]; - - bool pause = true; - bool blend = false; - bool extralines = false; - bool fullscreen = false; - - // splash screen - bool splashscreen = true; - snake3d.pause(true); - SDL_Rect splashpos = { 40, 40, screen->w -80, 310 }; - GLFontEngine fontengine("default"); - -#ifdef GL_DEBUG_MOVEMENT - movekeys[move_up] = SDLK_i; - movekeys[move_down] = SDLK_k; - movekeys[move_left] = SDLK_j; - movekeys[move_right] = SDLK_l; -#else - movekeys[move_up] = SDLK_UP; - movekeys[move_down] = SDLK_DOWN; - movekeys[move_left] = SDLK_LEFT; - movekeys[move_right] = SDLK_RIGHT; -#endif - - while(!quit) { - if(SDL_PollEvent(&event)) { - switch(event.type) { - case SDL_QUIT: - quit = true; - break; - case SDL_KEYDOWN: - keys = SDL_GetKeyState(NULL); - tkey = event.key.keysym.sym; - - break; - case SDL_KEYUP: - keys = SDL_GetKeyState(NULL); - break; - } - } else { - - glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glLoadIdentity(); - - SDL_Delay(10); - } - - } - GLFontEngine::quit(); - SDL_Quit(); - - return 0; -} - -void setupGL() { - glClearColor(0.0f, 0.0f, 0.0f, 0.0f); - glClearDepth(1.0f); - glDepthFunc(GL_LEQUAL); - glEnable(GL_DEPTH_TEST); - glEnable(GL_TEXTURE_2D); - glShadeModel(GL_SMOOTH); - glBlendFunc(GL_SRC_ALPHA, GL_ONE); -// glBlendFunc(GL_SRC_COLOR,GL_DST_COLOR); - -// glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA); -// glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); - glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); - glEnable(GL_ALPHA_TEST); - glAlphaFunc(GL_GREATER, 0.1); -} - -void resizeOpenGLWindow(int width, int height, float znear, float zfar) { - if(height==0) - height = 1; - - glViewport(0, 0, (GLsizei)width, (GLsizei)height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, znear, zfar); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); -} diff --git a/matrix.cpp b/matrix.cpp index 21f346c..dcf0bcc 100644 --- a/matrix.cpp +++ b/matrix.cpp @@ -1,5 +1,7 @@ #include "matrix.h" +namespace segl { + Matrix::Matrix(int _m, int _n) { m = _m; n = _n; @@ -154,3 +156,5 @@ Matrix::~Matrix() { } delete[](c); } + +} // namespace segl diff --git a/matrix.h b/matrix.h index 94d55e1..3424b74 100644 --- a/matrix.h +++ b/matrix.h @@ -7,6 +7,8 @@ #include "punkt3d.h" #include "emath.h" +namespace segl { + class Matrix { protected: float **c; @@ -39,6 +41,6 @@ class Matrix { }; - +} // namespace segl #endif diff --git a/model/loadobj.cpp b/model/loadobj.cpp index e829d4d..9e758e5 100644 --- a/model/loadobj.cpp +++ b/model/loadobj.cpp @@ -1,5 +1,7 @@ #include "loadobj.h" +namespace segl { + LoadOBJ::LoadOBJ(std::string _filename) : Modelloader(_filename) { } @@ -233,3 +235,5 @@ bool LoadOBJ::load(Model *m) { // std::cout << "Loaded!" << std::endl; return true; } + +} // namespace segl diff --git a/model/loadobj.h b/model/loadobj.h index af9dbe2..12ced61 100644 --- a/model/loadobj.h +++ b/model/loadobj.h @@ -6,6 +6,8 @@ #include "model.h" #include "../extstring.h" +namespace segl { + class LoadOBJ : public Modelloader { private: @@ -14,4 +16,6 @@ class LoadOBJ : public Modelloader { bool load(Model *m); }; +} // namespace segl + #endif diff --git a/model/model.cpp b/model/model.cpp index 8fadc27..ebb51d5 100644 --- a/model/model.cpp +++ b/model/model.cpp @@ -1,5 +1,7 @@ #include "model.h" +namespace segl { + // Class Meshpoint Meshpoint::Meshpoint() { @@ -31,11 +33,11 @@ Material::Material() { specular.set(1.0f, 1.0f, 1.0f); } -Material::Material(std::string _name, GLColor _a, GLColor _d, GLColor _s) { +Material::Material(std::string _name, Color _a, Color _d, Color _s) { set(_name, _a, _d, _s); } -void Material::set(std::string _name, GLColor _a, GLColor _d, GLColor _s) { +void Material::set(std::string _name, Color _a, Color _d, Color _s) { name = _name; ambient = _a; diffuse = _d; @@ -156,3 +158,5 @@ const Punkt3D* Model::getMeshData(unsigned int *meshanz) { *meshanz = meshdataanz; return (const Punkt3D*)meshdata; } + +} // namespace segl diff --git a/model/model.h b/model/model.h index e55f0a6..34769ad 100644 --- a/model/model.h +++ b/model/model.h @@ -5,9 +5,11 @@ #include #include "../punkt3d.h" #include "../punkt2d.h" -#include "../glcolor.h" +#include "../color.h" #include "../quader.h" +namespace segl { + class Meshpoint { public: Meshpoint(); @@ -22,12 +24,12 @@ class Meshpoint { class Material { public: Material(); - Material(std::string _name, GLColor _a, GLColor _d, GLColor _s); - void set(std::string _name, GLColor _a, GLColor _d, GLColor _s); + Material(std::string _name, Color _a, Color _d, Color _s); + void set(std::string _name, Color _a, Color _d, Color _s); void use(); std::string name; - GLColor ambient, diffuse, specular; + Color ambient, diffuse, specular; }; class Polygonpoint { @@ -88,4 +90,6 @@ class Model { const Punkt3D* getMeshData(unsigned int *meshanz); }; +} // namespace segl + #endif diff --git a/model/modelloader.cpp b/model/modelloader.cpp index 07541aa..28b245f 100644 --- a/model/modelloader.cpp +++ b/model/modelloader.cpp @@ -1,5 +1,9 @@ #include "modelloader.h" +namespace segl { + Modelloader::Modelloader(std::string _filename) { filename = _filename; } + +} // namespace segl diff --git a/model/modelloader.h b/model/modelloader.h index f047b44..0080203 100644 --- a/model/modelloader.h +++ b/model/modelloader.h @@ -5,6 +5,7 @@ #include #include "model.h" +namespace segl { class Modelloader { protected: @@ -15,4 +16,6 @@ class Modelloader { virtual bool load(Model *m)=0; }; +} // namespace segl + #endif diff --git a/punkt2d.cpp b/punkt2d.cpp index 6df3036..29b7d70 100644 --- a/punkt2d.cpp +++ b/punkt2d.cpp @@ -1,5 +1,7 @@ #include "punkt2d.h" +namespace segl { + Punkt2D::Punkt2D() { x = y = 0.0f; } @@ -112,33 +114,36 @@ bool Punkt2D::operator==(const Punkt2D& b) { bool Punkt2D::operator!=(const Punkt2D& b) { return !(*this==b); } + // Freunde -Punkt2D operator+(const float& _m, const Punkt2D& b) { - return Punkt2D(b.x+_m, b.y+_m); +segl::Punkt2D operator+(const float& _m, const segl::Punkt2D& b) { + return segl::Punkt2D(b.x+_m, b.y+_m); } -Punkt2D operator-(const float& _m, const Punkt2D& b) { - return Punkt2D(b.x-_m, b.y-_m); +segl::Punkt2D operator-(const float& _m, const segl::Punkt2D& b) { + return segl::Punkt2D(b.x-_m, b.y-_m); } -Punkt2D operator*(const float& _m, const Punkt2D& b) { - return Punkt2D(b.x*_m, b.y*_m); +segl::Punkt2D operator*(const float& _m, const segl::Punkt2D& b) { + return segl::Punkt2D(b.x*_m, b.y*_m); } -Punkt2D operator/(const float& _m, const Punkt2D& b) { - return Punkt2D(b.x/_m, b.y/_m); +segl::Punkt2D operator/(const float& _m, const segl::Punkt2D& b) { + return segl::Punkt2D(b.x/_m, b.y/_m); } -void glTexCoord2f(Punkt2D p) { +} // namespace segl + +void glTexCoord2f(segl::Punkt2D p) { glTexCoord2f(p.x, p.y); } -float abs(Punkt2D p) { +float abs(segl::Punkt2D p) { return p.abs(); } // Fixed Headers -void glTexCoordP2D(Punkt2D p) { +void glTexCoordP2D(segl::Punkt2D p) { glTexCoord2f(p.x, p.y); } diff --git a/punkt2d.h b/punkt2d.h index 5ce98dc..0bc8fd6 100644 --- a/punkt2d.h +++ b/punkt2d.h @@ -5,6 +5,8 @@ #include #include "emath.h" +namespace segl { + class Punkt2D { public: Punkt2D(); @@ -45,10 +47,15 @@ class Punkt2D { }; -void glTexCoord2f(Punkt2D); -float abs(Punkt2D); + +} // namespace segl + +void glTexCoord2f(segl::Punkt2D); +float abs(segl::Punkt2D); // Fixed Headers -void glTexCoordP2D(Punkt2D p); +void glTexCoordP2D(segl::Punkt2D p); + + #endif diff --git a/punkt3d.cpp b/punkt3d.cpp index e69bf91..dbf7ac6 100644 --- a/punkt3d.cpp +++ b/punkt3d.cpp @@ -1,5 +1,7 @@ #include "punkt3d.h" +namespace segl { + Punkt3D::Punkt3D() { x = y = z = 0.0f; } @@ -88,8 +90,6 @@ void Punkt3D::print(std::string coordname) { std::cout << coordname << "Coord: (" << x << ", " << y << ", " << z << ")" << std::endl; } - - Punkt3D Punkt3D::operator+(const Punkt3D &b) { Punkt3D c; c.x = x + b.x; @@ -179,68 +179,71 @@ bool Punkt3D::operator==(const Punkt3D& b) { bool Punkt3D::operator!=(const Punkt3D& b) { return !(*this==b); } + // Freunde -Punkt3D operator+(const float& _m, const Punkt3D& b) { - return Punkt3D(b.x+_m, b.y+_m, b.z+_m); +segl::Punkt3D operator+(const float& _m, const segl::Punkt3D& b) { + return segl::Punkt3D(b.x+_m, b.y+_m, b.z+_m); } -Punkt3D operator-(const float& _m, const Punkt3D& b) { - return Punkt3D(b.x-_m, b.y-_m, b.z-_m); +segl::Punkt3D operator-(const float& _m, const segl::Punkt3D& b) { + return segl::Punkt3D(b.x-_m, b.y-_m, b.z-_m); } -Punkt3D operator*(const float& _m, const Punkt3D& b) { - return Punkt3D(b.x*_m, b.y*_m, b.z*_m); +segl::Punkt3D operator*(const float& _m, const segl::Punkt3D& b) { + return segl::Punkt3D(b.x*_m, b.y*_m, b.z*_m); } -Punkt3D operator/(const float& _m, const Punkt3D& b) { - return Punkt3D(b.x/_m, b.y/_m, b.z/_m); +segl::Punkt3D operator/(const float& _m, const segl::Punkt3D& b) { + return segl::Punkt3D(b.x/_m, b.y/_m, b.z/_m); } -std::ostream &operator<<(std::ostream &ostr, const Punkt3D &r) { +std::ostream &operator<<(std::ostream &ostr, const segl::Punkt3D &r) { return ostr << "(" << r.x << ", " << r.y << ", " << r.z << ")"; } -float abs(Punkt3D p) { +} // namespace segl + +float abs(segl::Punkt3D p) { return p.abs(); } // OpenGL Funktionen f�r Punkt3D -void glVertex3f(Punkt3D p) { +void glVertex3f(segl::Punkt3D p) { glVertex3f(p.x, p.y, p.z); } -void glTranslatef(Punkt3D p) { +void glTranslatef(segl::Punkt3D p) { glTranslatef(p.x, p.y, p.z); } -void glNormal3f(Punkt3D p) { +void glNormal3f(segl::Punkt3D p) { glNormal3f(p.x, p.y, p.z); } -void glRotatef(float deg, Punkt3D vec) { +void glRotatef(float deg, segl::Punkt3D vec) { glRotatef(deg, vec.x, vec.y, vec.z); } // Funktionen mit richtgen bezeichnern -void glVertexP3D(Punkt3D p) { +void glVertexP3D(segl::Punkt3D p) { glVertex3f(p.x, p.y, p.z); } -void glTranslateP3D(Punkt3D p) { +void glTranslateP3D(segl::Punkt3D p) { glTranslatef(p.x, p.y, p.z); } -void glNormalP3D(Punkt3D p) { +void glNormalP3D(segl::Punkt3D p) { glNormal3f(p.x, p.y, p.z); } -void glRotateP3D(float deg, Punkt3D vec) { +void glRotateP3D(float deg, segl::Punkt3D vec) { glRotatef(deg, vec.x, vec.y, vec.z); } -void gluLookAt(Punkt3D pos, Punkt3D viewport, Punkt3D normal) { +void gluLookAt(segl::Punkt3D pos, segl::Punkt3D viewport, segl::Punkt3D normal) { gluLookAt( pos.x, pos.y, pos.z, viewport.x, viewport.y, viewport.z, normal.x, normal.y, normal.z ); diff --git a/punkt3d.h b/punkt3d.h index bb394f6..93de090 100644 --- a/punkt3d.h +++ b/punkt3d.h @@ -5,6 +5,8 @@ #include #include "emath.h" +namespace segl { + class Punkt3D { public: Punkt3D(); @@ -55,22 +57,24 @@ class Punkt3D { friend std::ostream &operator<<(std::ostream &ostr, const Punkt3D &r); }; -float abs(Punkt3D); +} // namespace segl + +float abs(segl::Punkt3D); // OpenGL-Functions for Punkt3D -void glVertex3f(Punkt3D); -void glTranslatef(Punkt3D); -void glNormal3f(Punkt3D); +void glVertex3f(segl::Punkt3D); +void glTranslatef(segl::Punkt3D); +void glNormal3f(segl::Punkt3D); -void glRotatef(float, Punkt3D); +void glRotatef(float, segl::Punkt3D); // Funktionen mit richtgen bezeichnern -void glVertexP3D(Punkt3D); -void glTranslateP3D(Punkt3D); -void glNormalP3D(Punkt3D); +void glVertexP3D(segl::Punkt3D); +void glTranslateP3D(segl::Punkt3D); +void glNormalP3D(segl::Punkt3D); -void glRotateP3D(float, Punkt3D); -void gluLookAt(Punkt3D pos, Punkt3D viewport, Punkt3D normal); +void glRotateP3D(float, segl::Punkt3D); +void gluLookAt(segl::Punkt3D pos, segl::Punkt3D viewport, segl::Punkt3D normal); #endif diff --git a/quader.cpp b/quader.cpp index 13c1e6b..7678271 100644 --- a/quader.cpp +++ b/quader.cpp @@ -1,5 +1,7 @@ #include "quader.h" +namespace segl { + void Quader::clean() { a.set(0.0f, 0.0f, 0.0f); b = c = d = e = f = g = h = a; @@ -33,3 +35,5 @@ void Quader::render() { glVertexP3D(h); glEnd(); } + +} // namespace segl diff --git a/quader.h b/quader.h index 6ef34b0..fa0678f 100644 --- a/quader.h +++ b/quader.h @@ -4,6 +4,7 @@ #include #include "punkt3d.h" +namespace segl { class Quader { public: @@ -12,4 +13,6 @@ class Quader { void render(); }; +} // namespace segl + #endif diff --git a/quaternion.cpp b/quaternion.cpp index 862220e..dd4f7b8 100644 --- a/quaternion.cpp +++ b/quaternion.cpp @@ -1,5 +1,7 @@ #include "quaternion.h" +namespace segl { + Quaternion::Quaternion() { w = 1.0f, x = y = z = 0.0f; @@ -163,3 +165,5 @@ Quaternion Quaternion::operator*(const Quaternion &q) { // q.createGlMatrix(matrix); // glMultMatrixf(matrix); // } + +} // namespace segl diff --git a/quaternion.h b/quaternion.h index 22d5adf..a0bbf7b 100644 --- a/quaternion.h +++ b/quaternion.h @@ -8,6 +8,8 @@ #include "punkt3d.h" #include "emath.h" +namespace segl { + class Quaternion { private: float x, y, z, w; @@ -51,4 +53,6 @@ class Quaternion { // // void glMultMatrixf(Quaternion); +} // namespace segl + #endif diff --git a/rect.cpp b/rect.cpp new file mode 100644 index 0000000..d476cd1 --- /dev/null +++ b/rect.cpp @@ -0,0 +1,40 @@ +#include "rect.h" + +namespace segl { + +Rect::Rect() { + set(0.0f, 0.0f, 0.0f, 0.0f); +} + +Rect::Rect(float _x, float _y, float _w, float _h) { + set(_x, _y, _w, _h); +} + +Rect::Rect(const SDL_Rect &r) { + set(r.x, r.y, r.w, r.h); +} + +void Rect::set(float _x, float _y, float _w, float _h) { + x = _x; + y = _y; + w = _w; + h = _h; +} + +void Rect::setPoint(float _x, float _y) { + x = _x; + y = _y; +} + +void Rect::setDim(float _w, float _h) { + w = _w; + h = _h; +} + +SDL_Rect Rect::getSDLRect() { + SDL_Rect tmp = {(Uint8)x, (Uint8)y, (Uint8)w, (Uint8)h}; + return tmp; +} + +} // namespace segl + diff --git a/glrect.h b/rect.h similarity index 56% rename from glrect.h rename to rect.h index 886e4de..5732a27 100644 --- a/glrect.h +++ b/rect.h @@ -1,16 +1,18 @@ -#ifndef __GLRECT_H -#define __GLRECT_H +#ifndef __RECT_H +#define __RECT_H #include -class GLRect { +namespace segl { + +class Rect { public: float x, y; float w, h; - GLRect(); - GLRect(float, float, float, float); - GLRect(const SDL_Rect&); + Rect(); + Rect(float, float, float, float); + Rect(const SDL_Rect&); void set(float, float, float, float); void setPoint(float, float); @@ -19,4 +21,6 @@ class GLRect { }; +} // namespace segl + #endif diff --git a/rotationsmatrix.cpp b/rotationsmatrix.cpp index 7cf2da7..9dfb658 100644 --- a/rotationsmatrix.cpp +++ b/rotationsmatrix.cpp @@ -1,5 +1,7 @@ #include "rotationsmatrix.h" +namespace segl { + Rotationsmatrix::Rotationsmatrix() : Matrix(3,3) { set(x_axis, 0.0f); } @@ -90,3 +92,5 @@ Rotationsmatrix Rotationsmatrix::operator*(const Rotationsmatrix &p) { Rotationsmatrix::~Rotationsmatrix() { } + +} // namespace segl diff --git a/rotationsmatrix.h b/rotationsmatrix.h index 34f18f1..fba62aa 100644 --- a/rotationsmatrix.h +++ b/rotationsmatrix.h @@ -6,6 +6,8 @@ #include "emath.h" #include "matrix.h" +namespace segl { + enum axis { x_axis=0, y_axis, z_axis }; class Rotationsmatrix : public Matrix { @@ -28,4 +30,6 @@ class Rotationsmatrix : public Matrix { Rotationsmatrix operator*(const Rotationsmatrix&); }; +} // namespace segl + #endif diff --git a/sdlfuncs.cpp b/sdlfuncs.cpp index 675e678..782a2c8 100644 --- a/sdlfuncs.cpp +++ b/sdlfuncs.cpp @@ -1,5 +1,7 @@ #include "sdlfuncs.h" +namespace segl { + Uint32 getPixel(SDL_Surface *surface, int x, int y) { int bpp = surface->format->BytesPerPixel; @@ -80,3 +82,5 @@ void mirrorSurfaceMiddleX(SDL_Surface *surface) { } SDL_UnlockSurface(surface); } + +} // namespace segl diff --git a/sdlfuncs.h b/sdlfuncs.h index 3cf394e..a2ba80a 100644 --- a/sdlfuncs.h +++ b/sdlfuncs.h @@ -4,9 +4,13 @@ #include #include +namespace segl { + Uint32 getPixel(SDL_Surface *surface, int x, int y); void setPixel(SDL_Surface *surface, int x, int y, Uint32 pixel); void swapPixel(SDL_Surface *surface, int x1, int y1, int x2, int y2); void mirrorSurfaceMiddleX(SDL_Surface *surface); +} // namespace segl + #endif diff --git a/testprog.cpp b/testprog.cpp deleted file mode 100644 index 019a7d7..0000000 --- a/testprog.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include "glsdlscreen.h" - -int main() { - GLSDLScreen screen; - - screen.enableOpenGL(true); - screen.setVideoMode(640, 480, 32); - screen.apply(); - - // whee - - return 0; -} diff --git a/testprog.h b/testprog.h deleted file mode 100644 index e69de29..0000000