parent
b41c12950d
commit
45c8964c49
@ -1,3 +1,4 @@
|
||||
*.o
|
||||
*.a
|
||||
libsegl.so.*
|
||||
testprog
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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..
|
||||
|
@ -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
|
@ -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
|
@ -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);
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
@ -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();
|
||||
}
|
@ -1,5 +1,9 @@
|
||||
#include "modelloader.h"
|
||||
|
||||
namespace segl {
|
||||
|
||||
Modelloader::Modelloader(std::string _filename) {
|
||||
filename = _filename;
|
||||
}
|
||||
|
||||
} // namespace segl
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
Loading…
Reference in new issue