Namepsace in Dateien eingefuegt.

GL aus Rect/Color entfernt
Compiled als .so
This commit is contained in:
Sebastian 2008-08-10 17:14:54 +02:00
parent b41c12950d
commit 45c8964c49
67 changed files with 591 additions and 356 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.o
*.a
libsegl.so.*
testprog

View File

@ -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

View File

@ -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

View File

@ -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

43
color.cpp Normal file
View File

@ -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);
}
}

View File

@ -1,27 +1,31 @@
#ifndef __GLCOLOR_H
#define __GLCOLOR_H
#ifndef __COLOR_H
#define __COLOR_H
#include <SDL.h>
#include <SDL_opengl.h>
#include <iostream>
#include <string>
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..

View File

@ -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

View File

@ -5,6 +5,7 @@
#include <cmath>
#include <SDL_opengl.h>
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

View File

@ -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

View File

@ -7,7 +7,12 @@
#include "rotationsmatrix.h"
#include <SDL_opengl.h>
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

View File

@ -1,5 +1,7 @@
#include "extstring.h"
namespace segl {
int explode(std::string str, std::string delim, std::vector<std::string> *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

View File

@ -4,9 +4,13 @@
#include <string>
#include <vector>
namespace segl {
int explode(std::string str, std::string delim, std::vector<std::string> *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

View File

@ -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

View File

@ -3,6 +3,8 @@
#include <SDL.h>
namespace segl {
class FPSManager {
private:
Uint32 lastticks;
@ -17,4 +19,6 @@ class FPSManager {
float getFPS();
};
} // namespace segl
#endif

103
geotypes.cpp Normal file
View File

@ -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

70
geotypes.h Normal file
View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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);
}
}

View File

@ -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

View File

@ -4,9 +4,12 @@
#include <SDL.h>
#include <SDL_opengl.h>
#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

View File

@ -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<std::string, GLFont*> GLFontEngine::fontpool;
} // namespace segl

View File

@ -11,7 +11,9 @@
#include <SDL.h>
#include <SDL_opengl.h>
#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

View File

@ -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<EFBFBD>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

View File

@ -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

View File

@ -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

View File

@ -7,15 +7,17 @@
#include <SDL/SDL_opengl.h>
#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

View File

@ -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<EFBFBD>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<EFBFBD>lligst drum k<>mmern
// for(unsigned int i=0; i<items.size(); i++) {
// delete(items[i]);
// }
}
} // namespace segl

View File

@ -7,16 +7,17 @@
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
#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<GLGuiObject*> items;
@ -24,7 +25,7 @@ class GLGuiWindow : public GLGuiObject {
std::vector<GLGuiObject*> clickable;
std::vector<GLGuiObject*> 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

View File

@ -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. <EFBFBD>berarbeiten..
Punkt2D tmp = pos;
// tmp.x = pos.x - (caplen+vallen+valuewidth)/2;
@ -79,3 +81,5 @@ MenuItem::~MenuItem() {
}
} // namespace segl

View File

@ -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

View File

@ -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

View File

@ -6,6 +6,8 @@
#include <SDL.h>
#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

View File

@ -1,5 +1,7 @@
#include "menumanager.h"
namespace segl {
MenuManager::MenuManager() {
aktuell = 0;
}
@ -69,3 +71,5 @@ void MenuManager::reset() {
}
}
} // namespace segl

View File

@ -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

View File

@ -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

View File

@ -6,6 +6,8 @@
#include "../punkt2d.h"
#include "menuitem.h"
namespace segl {
class MenuMenu {
private:
std::vector<MenuItem*> menuitems;
@ -49,4 +51,6 @@ class MenuMenu {
void render();
};
} // namespace segl
#endif

View File

@ -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;
}

View File

@ -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

View File

@ -6,6 +6,8 @@
#include <SDL_opengl.h>
#include "gltexture.h"
namespace segl {
class GLSDLScreen {
private:
SDL_Surface *screen;
@ -44,4 +46,6 @@ class GLSDLScreen {
void renderScreen();
};
} // namespace segl
#endif

View File

@ -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<EFBFBD>scht oder wir m<>ssen es nich l<>schen
}
@ -177,3 +179,5 @@ GLTexture::~GLTexture() {
}
std::vector<GLTexture*> GLTexture::alltextures;
} // namespace segl

View File

@ -9,6 +9,8 @@
#include <SDL_opengl.h>
#include "sdlfuncs.h"
namespace segl {
class GLTexture {
private:
GLuint texint;
@ -60,4 +62,6 @@ class GLTexture {
bool isLoaded();
};
} // namespace segl
#endif

177
main.cpp
View File

@ -1,177 +0,0 @@
#define VERSION "0.2.2 DEV"
#include <iostream>
#include <string>
#include <SDL.h>
#include <SDL_opengl.h>
#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();
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -5,9 +5,11 @@
#include <SDL_opengl.h>
#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

View File

@ -1,5 +1,9 @@
#include "modelloader.h"
namespace segl {
Modelloader::Modelloader(std::string _filename) {
filename = _filename;
}
} // namespace segl

View File

@ -5,6 +5,7 @@
#include <fstream>
#include "model.h"
namespace segl {
class Modelloader {
protected:
@ -15,4 +16,6 @@ class Modelloader {
virtual bool load(Model *m)=0;
};
} // namespace segl
#endif

View File

@ -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);
}

View File

@ -5,6 +5,8 @@
#include <cmath>
#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

View File

@ -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 );

View File

@ -5,6 +5,8 @@
#include <cmath>
#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

View File

@ -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

View File

@ -4,6 +4,7 @@
#include <SDL_opengl.h>
#include "punkt3d.h"
namespace segl {
class Quader {
public:
@ -12,4 +13,6 @@ class Quader {
void render();
};
} // namespace segl
#endif

View File

@ -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

View File

@ -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

40
rect.cpp Normal file
View File

@ -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

View File

@ -1,16 +1,18 @@
#ifndef __GLRECT_H
#define __GLRECT_H
#ifndef __RECT_H
#define __RECT_H
#include <SDL.h>
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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -4,9 +4,13 @@
#include <iostream>
#include <SDL.h>
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

View File

@ -1,14 +0,0 @@
#include <iostream>
#include "glsdlscreen.h"
int main() {
GLSDLScreen screen;
screen.enableOpenGL(true);
screen.setVideoMode(640, 480, 32);
screen.apply();
// whee
return 0;
}

View File