├── FoxelEngine ├── .gitignore ├── Shader.cpp ├── resource1.h ├── FoxelEngine.rc ├── FoxelManager.cpp ├── GI_Light.h ├── Shader │ ├── Basic.frag │ ├── Post.vert │ ├── Basic.vert │ ├── Model.frag │ ├── Foxel.frag │ ├── Model.vert │ ├── Foxel.vert │ └── Post.frag ├── GI_Light.cpp ├── FoxelEngine.vcxproj.user ├── GameComponent.cpp ├── Explosion.h ├── Explosion.cpp ├── GameComponent.h ├── BitCube.h ├── BitCube.cpp ├── Convert.h ├── Main_Menu.h ├── Light.h ├── Camera.h ├── TextButton.h ├── DirectLight.h ├── Foxel_Interaction.cpp ├── ToolBox.h ├── Convert.cpp ├── Material.h ├── Foxel_Interaction.h ├── Vec2d.h ├── BitmapText.h ├── Foxel.h ├── PropDynamic.h ├── Material.cpp ├── GameMenu.h ├── GL_Screen.h ├── main.cpp ├── GlobalLight.h ├── Axes.cpp ├── Entity_2D.h ├── SlideControl.h ├── Controler.h ├── ColorPanel.h ├── World.h ├── DrawableGameComponent.h ├── Pistol.h ├── PlayerControler.h ├── Bullet.h ├── Core_events.cpp ├── Event.h ├── BitmapText.cpp ├── Shader.h ├── Axes.h ├── Vec3d.h ├── TextButton.cpp ├── Vec2.h ├── Vec3.h ├── GameGUI.h ├── TextField.h ├── Matrix4.h ├── Model.h ├── Color.h ├── PostProcessor.h ├── ShaderProgram.h ├── View.h ├── Camera.cpp ├── Config.h ├── PropDynamic.cpp ├── Foxel.cpp ├── DirectLight.cpp ├── Editor.h ├── Event.cpp ├── DrawableGameComponent.cpp ├── Bullet.cpp ├── Vec2d.cpp ├── Player.h ├── CollisionDetector.h ├── Core.h ├── Map.h ├── CollisionDetector.cpp ├── GameMenu.cpp ├── World.cpp ├── BrushBox.h ├── Entity_2D.cpp ├── GlobalLight.cpp ├── Screen.h ├── ToolBox.cpp ├── Color.cpp ├── Controler.cpp ├── SlideControl.cpp ├── Main_Menu.cpp ├── Config.cpp ├── PlayerControler.cpp ├── Maps │ ├── Test_Map2.foxel │ ├── Test_Map3.foxel │ ├── Test_Map4.foxel │ ├── Test_Map5.foxel │ └── Test_Map.foxel ├── Models │ └── pistol.mtl ├── TextField.cpp ├── Vec3d.cpp ├── GameGUI.cpp ├── Vec2.cpp ├── GL_Screen.cpp ├── Vec3.cpp ├── ShaderProgram.cpp ├── ColorPanel.cpp ├── Core.cpp ├── Pistol.cpp ├── BrushBox.cpp ├── Core_inputs.cpp ├── Player.cpp ├── Model.cpp ├── Matrix4.cpp ├── View.cpp ├── Map.cpp ├── Editor.cpp ├── Screen.cpp ├── FoxelManager.h ├── PostProcessor.cpp └── FoxelEngine.vcxproj ├── FoxelEngine.suo ├── FoxelEngine.sln.docstates.suo ├── README.md ├── LICENSE └── FoxelEngine.sln /FoxelEngine/.gitignore: -------------------------------------------------------------------------------- 1 | # Stupid files 2 | *.aps 3 | *.cd 4 | *.cfg 5 | *.log -------------------------------------------------------------------------------- /FoxelEngine.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoxelFox/FoxelEngine/HEAD/FoxelEngine.suo -------------------------------------------------------------------------------- /FoxelEngine/Shader.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoxelFox/FoxelEngine/HEAD/FoxelEngine/Shader.cpp -------------------------------------------------------------------------------- /FoxelEngine/resource1.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoxelFox/FoxelEngine/HEAD/FoxelEngine/resource1.h -------------------------------------------------------------------------------- /FoxelEngine/FoxelEngine.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoxelFox/FoxelEngine/HEAD/FoxelEngine/FoxelEngine.rc -------------------------------------------------------------------------------- /FoxelEngine/FoxelManager.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoxelFox/FoxelEngine/HEAD/FoxelEngine/FoxelManager.cpp -------------------------------------------------------------------------------- /FoxelEngine.sln.docstates.suo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FoxelFox/FoxelEngine/HEAD/FoxelEngine.sln.docstates.suo -------------------------------------------------------------------------------- /FoxelEngine/GI_Light.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | class GI_Light 3 | { 4 | public: 5 | GI_Light(void); 6 | ~GI_Light(void); 7 | }; 8 | 9 | -------------------------------------------------------------------------------- /FoxelEngine/Shader/Basic.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec4 ex_Color; 4 | out vec4 frag_Output; 5 | 6 | void main(void){ 7 | frag_Output = ex_Color; 8 | } -------------------------------------------------------------------------------- /FoxelEngine/GI_Light.cpp: -------------------------------------------------------------------------------- 1 | #include "GI_Light.h" 2 | 3 | 4 | GI_Light::GI_Light(void) 5 | { 6 | } 7 | 8 | 9 | GI_Light::~GI_Light(void) 10 | { 11 | } 12 | -------------------------------------------------------------------------------- /FoxelEngine/FoxelEngine.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /FoxelEngine/GameComponent.cpp: -------------------------------------------------------------------------------- 1 | #include "GameComponent.h" 2 | 3 | GameComponent::GameComponent(){} 4 | 5 | void GameComponent::update(){} 6 | 7 | GameComponent::~GameComponent(){} -------------------------------------------------------------------------------- /FoxelEngine/Explosion.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | class Explosion{ 3 | private: 4 | short strength; 5 | public: 6 | Explosion(short strength); 7 | ~Explosion(void); 8 | }; 9 | 10 | -------------------------------------------------------------------------------- /FoxelEngine/Explosion.cpp: -------------------------------------------------------------------------------- 1 | #include "Explosion.h" 2 | 3 | 4 | Explosion::Explosion(short strength) 5 | { 6 | this->strength = strength; 7 | } 8 | 9 | 10 | Explosion::~Explosion(void) 11 | { 12 | } 13 | -------------------------------------------------------------------------------- /FoxelEngine/GameComponent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Vec3d.h" 3 | class GameComponent{ 4 | protected: 5 | Vec3d position; 6 | public: 7 | GameComponent(void); 8 | virtual void update(); 9 | ~GameComponent(void); 10 | }; -------------------------------------------------------------------------------- /FoxelEngine/BitCube.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | class BitCube 4 | { 5 | public: 6 | std::bitset<128> bitGrid[128][128]; 7 | void set(unsigned char x,unsigned char y,unsigned char z,bool state); 8 | bool get(unsigned char x,unsigned char y,unsigned char z); 9 | }; 10 | -------------------------------------------------------------------------------- /FoxelEngine/Shader/Post.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | layout(location = 0) in vec3 vertexPosition_modelspace; 4 | 5 | out vec2 uv; 6 | 7 | void main(){ 8 | gl_Position = vec4(vertexPosition_modelspace,1); 9 | uv = (vertexPosition_modelspace.xy+vec2(1,1))/2.0; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /FoxelEngine/BitCube.cpp: -------------------------------------------------------------------------------- 1 | #include "BitCube.h" 2 | 3 | 4 | void BitCube::set(unsigned char x,unsigned char y,unsigned char z,bool state){ 5 | bitGrid[x][y][z] = state; 6 | } 7 | 8 | bool BitCube::get(unsigned char x,unsigned char y,unsigned char z){ 9 | return bitGrid[x][y][z]; 10 | } -------------------------------------------------------------------------------- /FoxelEngine/Convert.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | const double PI = 3.14159265f; 4 | class Convert{ 5 | public: 6 | static float degToRad(float* deg); 7 | static double degToRad(double* deg); 8 | static float degToRad(float deg); 9 | static double degToRad(double deg); 10 | }; 11 | 12 | -------------------------------------------------------------------------------- /FoxelEngine/Main_Menu.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Screen.h" 3 | #include "gamemenu.h" 4 | #include "Event.h" 5 | class Main_Menu : public GameMenu{ 6 | private: 7 | void createEvents(); 8 | public: 9 | void draw(); 10 | Main_Menu(void); 11 | ~Main_Menu(void); 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /FoxelEngine/Light.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Color.h" 3 | #include "Vec3.h" 4 | struct Light{ 5 | Color color; 6 | Vec3 normal,position; 7 | 8 | Light(Vec3 position, Vec3 normal, Color color){ 9 | this->position = position; 10 | this->color = color; 11 | this->normal = normal; 12 | } 13 | 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /FoxelEngine/Shader/Basic.vert: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | uniform mat4 viewMatrix, projMatrix; 4 | 5 | in vec3 in_Position; 6 | in vec4 in_Color; 7 | in vec3 in_Normal; 8 | 9 | out vec4 ex_Color; 10 | 11 | void main(void) 12 | { 13 | ex_Color = vec4(in_Color); 14 | gl_Position = projMatrix * viewMatrix * vec4(in_Position, 1.0); 15 | } 16 | -------------------------------------------------------------------------------- /FoxelEngine/Camera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "PropDynamic.h" 4 | #include "Vec3d.h" 5 | #include "Matrix4.h" 6 | #include "World.h" 7 | 8 | class Camera : public PropDynamic{ 9 | Matrix4 viewMatrix; 10 | public: 11 | Camera(void); 12 | Camera(Vec3d position); 13 | void setupView(); 14 | ~Camera(void); 15 | }; 16 | 17 | -------------------------------------------------------------------------------- /FoxelEngine/TextButton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "TextField.h" 3 | 4 | 5 | 6 | class TextButton : public TextField{ 7 | bool pressed; 8 | public: 9 | TextButton(Vec2 position, Vec2 size, std::string content); 10 | void press(); 11 | void release(); 12 | bool isPressed(); 13 | bool intersect(Vec2 point); 14 | ~TextButton(void); 15 | }; 16 | 17 | -------------------------------------------------------------------------------- /FoxelEngine/DirectLight.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "Light.h" 5 | class DirectLight{ 6 | private: 7 | std::vector lights; 8 | std::vector id; 9 | public: 10 | DirectLight(std::vector id); 11 | 12 | 13 | float* generateDirectLightArray(); 14 | 15 | std::vector getLight(); 16 | }; 17 | 18 | -------------------------------------------------------------------------------- /FoxelEngine/Foxel_Interaction.cpp: -------------------------------------------------------------------------------- 1 | #include "Foxel_Interaction.h" 2 | 3 | using namespace Event; 4 | 5 | setFoxel::setFoxel(Vec3d* pos, char id) : BasicEvent(){ 6 | eventID = Event::SET_FOXEL; 7 | newFoxelID = id; 8 | position = pos; 9 | 10 | } 11 | 12 | Vec3d* setFoxel::getPosition(){ 13 | return position; 14 | } 15 | 16 | setFoxel::~setFoxel(void){ 17 | } 18 | -------------------------------------------------------------------------------- /FoxelEngine/ToolBox.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GameMenu.h" 3 | namespace MapEditor{ 4 | 5 | enum ActiveTool {Brush , Entity}; 6 | 7 | class ToolBox : public GameMenu{ 8 | public: 9 | ToolBox(Vec2 position, Vec2 size); 10 | ~ToolBox(void); 11 | ActiveTool activeTool; 12 | void update(); 13 | void draw(); 14 | void resize(); 15 | }; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /FoxelEngine/Convert.cpp: -------------------------------------------------------------------------------- 1 | #include "Convert.h" 2 | 3 | float Convert::degToRad(float* deg){ 4 | return (float) PI**deg/180; 5 | } 6 | 7 | double Convert::degToRad(double* deg){ 8 | return PI**deg/180; 9 | } 10 | 11 | float Convert::degToRad(float deg){ 12 | return (float) PI*deg/180; 13 | } 14 | 15 | double Convert::degToRad(double deg){ 16 | return PI*deg/180; 17 | } 18 | -------------------------------------------------------------------------------- /FoxelEngine/Material.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Color.h" 3 | #include "ShaderProgram.h" 4 | namespace GLSL{ 5 | class Material{ 6 | Color defuse,specular; 7 | ProgramTyp materialTyp; 8 | public: 9 | Material(ProgramTyp materialTyp); 10 | Material(ProgramTyp materialTyp, Color defuse, Color specular); 11 | ~Material(void); 12 | void use(); 13 | }; 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /FoxelEngine/Foxel_Interaction.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Event.h" 3 | #include "Vec3d.h" 4 | namespace Event{ 5 | class setFoxel : public Event::BasicEvent{ 6 | private: 7 | Vec3d* position; 8 | char newFoxelID; 9 | 10 | public: 11 | setFoxel(Vec3d* pos, char id); 12 | Vec3d* getPosition(); 13 | char getNewFoxelID(); 14 | ~setFoxel(void); 15 | }; 16 | 17 | 18 | } -------------------------------------------------------------------------------- /FoxelEngine/Shader/Model.frag: -------------------------------------------------------------------------------- 1 | #version 150 2 | 3 | in vec4 ex_Color; 4 | out vec4 frag_Output; 5 | 6 | in vec3 ex_Normal; 7 | in vec3 ex_Light; 8 | 9 | void main(void){ 10 | frag_Output = ex_Color; 11 | //frag_Output.r = clamp((dot(ex_Normal,ex_Light)),0.1,1); 12 | //frag_Output.g = clamp((dot(ex_Normal,ex_Light)),0.1,1); 13 | //frag_Output.b = clamp((dot(ex_Normal,ex_Light)),0.1,1); 14 | } -------------------------------------------------------------------------------- /FoxelEngine/Vec2d.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | class Vec2d{ 3 | 4 | public: 5 | double x,y; 6 | 7 | Vec2d(void); 8 | Vec2d(double x, double y); 9 | // Operatoren 10 | void operator+=(double skalar); 11 | void operator+=(Vec2d vector); 12 | void operator-=(double skalar); 13 | void operator-=(Vec2d vector); 14 | Vec2d operator*(double skalar); 15 | Vec2d operator*(Vec2d vector); 16 | Vec2d operator-(); 17 | ~Vec2d(void); 18 | }; -------------------------------------------------------------------------------- /FoxelEngine/BitmapText.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include "Vec3.h" 6 | #include "Screen.h" 7 | 8 | class BitmapText{ 9 | 10 | private: 11 | std::string text; 12 | bool bigText; 13 | public: 14 | BitmapText(std::string); 15 | ~BitmapText(void); 16 | 17 | void setBigText(bool boolean); 18 | void setText(std::string); 19 | void draw(); 20 | }; 21 | 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FoxelEngine 2 | 3 | [![Video](https://img.youtube.com/vi/nXAUnrXhaOU/0.jpg)](https://www.youtube.com/watch?v=nXAUnrXhaOU) 4 | [![Video](https://img.youtube.com/vi/BAQEjXU-blc/0.jpg)](https://www.youtube.com/watch?v=BAQEjXU-blc) 5 | [![Video](https://img.youtube.com/vi/kse0AOaynpQ/0.jpg)](https://www.youtube.com/watch?v=kse0AOaynpQ) 6 | [![Video](https://img.youtube.com/vi/fsjk-l-oyAc/0.jpg)](https://www.youtube.com/watch?v=fsjk-l-oyAc) 7 | 8 | -------------------------------------------------------------------------------- /FoxelEngine/Foxel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class Foxel { 6 | 7 | private: 8 | GLushort color[3]; 9 | char id; 10 | char visiblity; 11 | bool test; 12 | 13 | public: 14 | Foxel(); 15 | Foxel(char idFoxel, char vis); 16 | ~Foxel(); 17 | void setColor(GLushort r, GLushort g, GLushort b); 18 | void setVisiblity(char setBit); 19 | char getVisiblity(); 20 | void setId(char); 21 | char getId(); 22 | GLushort* getColor(); 23 | }; 24 | -------------------------------------------------------------------------------- /FoxelEngine/PropDynamic.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "GameComponent.h" 3 | #include "Vec3d.h" 4 | 5 | class PropDynamic : public GameComponent{ 6 | protected: 7 | float friction; 8 | Vec3d velocity; 9 | Vec3d rotation; 10 | 11 | public: 12 | PropDynamic(void); 13 | PropDynamic(Vec3d position); 14 | void update(float* time); 15 | ~PropDynamic(void); 16 | 17 | void setFriction(float friction); 18 | void setRotation(Vec3d rotation); 19 | void setPosition(Vec3d position); 20 | }; 21 | 22 | -------------------------------------------------------------------------------- /FoxelEngine/Material.cpp: -------------------------------------------------------------------------------- 1 | #include "Material.h" 2 | using namespace GLSL; 3 | 4 | Material::Material(ProgramTyp materialTyp){ 5 | this->materialTyp = materialTyp; 6 | } 7 | 8 | Material::Material(ProgramTyp materialTyp, Color defuse, Color specular){ 9 | this->materialTyp = materialTyp; 10 | this->defuse = defuse; 11 | this->specular = specular; 12 | } 13 | 14 | Material::~Material(void) 15 | { 16 | } 17 | 18 | void Material::use(){ 19 | PM::useProg(materialTyp); 20 | } 21 | -------------------------------------------------------------------------------- /FoxelEngine/GameMenu.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Screen.h" 4 | #include "TextButton.h" 5 | #include "Entity_2D.h" 6 | class GameMenu : public Entity_2D{ 7 | protected: 8 | std::vector selectOptions; 9 | public: 10 | GameMenu(Vec2 position, Vec2 size); 11 | GameMenu(void); 12 | ~GameMenu(void); 13 | virtual void createEvents(); 14 | void catchMousePosition(Vec2 pos); 15 | void catchMouseClick(Vec2 pos); 16 | void update(); 17 | void draw(); 18 | }; -------------------------------------------------------------------------------- /FoxelEngine/GL_Screen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | static int screenWidth, screenHeight; 7 | class GL_Screen 8 | { 9 | private: 10 | SDL_Surface* screen; 11 | float ar; 12 | 13 | public: 14 | GL_Screen(int w, int h, bool isFullscreen); 15 | void load3DView(); 16 | void resize(int w, int h); 17 | static int getWidth(); 18 | static int getHeight(); 19 | static void load2DView(); 20 | SDL_Surface* getSurface(); 21 | ~GL_Screen(void); 22 | }; -------------------------------------------------------------------------------- /FoxelEngine/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Core.h" 2 | #include 3 | Core game; 4 | #undef main 5 | int main(int argc, char *argv[]){ 6 | if(game.init(argc,argv)){ 7 | float startTime, endTime, renderTime = 0; 8 | while(game.running){ 9 | startTime = (float) SDL_GetTicks(); 10 | game.inputs(); 11 | game.events(); 12 | game.update(&renderTime); 13 | game.render(); 14 | endTime = (float) SDL_GetTicks(); 15 | renderTime = (endTime - startTime); 16 | 17 | } 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /FoxelEngine/GlobalLight.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Vec3.h" 4 | 5 | static GLfloat* ambientLight; 6 | static GLfloat* diffuseLight; 7 | static GLfloat* specularLight; 8 | static GLfloat* mat_specular; 9 | static GLfloat* mat_shininess; 10 | 11 | class GlobalLight{ 12 | private: 13 | 14 | public: 15 | static void load(); 16 | static void lightAt(Vec3 position); 17 | static void turnOff(); 18 | static void turnOn(); 19 | GlobalLight(void); 20 | ~GlobalLight(void); 21 | }; 22 | 23 | -------------------------------------------------------------------------------- /FoxelEngine/Axes.cpp: -------------------------------------------------------------------------------- 1 | #include "Axes.h" 2 | 3 | 4 | Axes::Axes(void){ 5 | anzVertex = 4; 6 | anzIndex = 6; 7 | indices = AxeIndices; 8 | vertices = AxeVertices; 9 | colors = AxeColor; 10 | } 11 | 12 | void Axes::render(){ 13 | glBindVertexArray(vao); 14 | glEnableVertexAttribArray(0); 15 | glEnableVertexAttribArray(1); 16 | glDrawElements(GL_LINES,6,GL_UNSIGNED_INT,indices); 17 | glDisableVertexAttribArray(0); 18 | glDisableVertexAttribArray(1); 19 | glBindVertexArray(0); 20 | } 21 | 22 | Axes::~Axes(void){ 23 | } 24 | -------------------------------------------------------------------------------- /FoxelEngine/Entity_2D.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Vec2.h" 3 | #include "Color.h" 4 | class Entity_2D{ 5 | protected: 6 | Vec2 size; 7 | Vec2 position; 8 | Color backColor; 9 | public: 10 | Entity_2D(Vec2 position, Vec2 size); 11 | Entity_2D(void); 12 | ~Entity_2D(void); 13 | Vec2 getPosition(); 14 | Vec2 getSize(); 15 | void setBackColor(Color color); 16 | void setPosition(Vec2 position); 17 | void setSize(Vec2 size); 18 | void move(Vec2 value); 19 | void drawBackground(); 20 | bool mouseIntersect(); 21 | }; 22 | 23 | -------------------------------------------------------------------------------- /FoxelEngine/SlideControl.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Entity_2D.h" 4 | #include "TextField.h" 5 | class SlideControl : public Entity_2D{ 6 | private: 7 | double value; 8 | double buffValue; 9 | TextField* text; 10 | void setText(); 11 | std::string prefix; 12 | public: 13 | SlideControl(Vec2 position, Vec2 size, std::string prefix); 14 | 15 | void changeValue(float value); 16 | void setValue(float value); 17 | void draw(); 18 | void setPosition(Vec2 position); 19 | float getValue(); 20 | }; 21 | 22 | -------------------------------------------------------------------------------- /FoxelEngine/Controler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace MapEditor{ 5 | class Controler{ 6 | friend class Editor; 7 | private: 8 | bool rightMouseButton, leftMouseButton, midleMouseButton; 9 | bool A,S,D,W,Shift,Tab; 10 | bool Grab; 11 | int wheelState; 12 | 13 | public: 14 | Controler(void); 15 | ~Controler(void); 16 | void catchKeyDown(SDLKey sym); 17 | void catchKeyUp(SDLKey sym); 18 | void catchMouseClick(Uint8 button); 19 | void catchMouseRelease(Uint8 button); 20 | }; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /FoxelEngine/ColorPanel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Entity_2D.h" 3 | #include "Color.h" 4 | #include "SlideControl.h" 5 | class ColorPanel : public Entity_2D{ 6 | private: 7 | Color color; 8 | SlideControl* slider_red; 9 | SlideControl* slider_green; 10 | SlideControl* slider_blue; 11 | SlideControl* slider_emit; 12 | 13 | void drawColorCircle(); 14 | public: 15 | ColorPanel(Vec2 position, Vec2 size); 16 | ~ColorPanel(void); 17 | 18 | Color getColor(); 19 | void draw(); 20 | void resize(Vec2 position); 21 | void mouseInteraction(); 22 | }; 23 | 24 | -------------------------------------------------------------------------------- /FoxelEngine/World.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | //#include 3 | #include 4 | #include "Event.h" 5 | #include "FoxelManager.h" 6 | #include "Screen.h" 7 | #include "Axes.h" 8 | #include "Bullet.h" 9 | #include "GameGUI.h" 10 | #include "Config.h" 11 | 12 | class World{ 13 | private: 14 | Axes* center; 15 | GameGUI* gui; 16 | BulletManager* bulletManager; 17 | 18 | public: 19 | World(void); 20 | void render(); 21 | void drawGui(); 22 | void update(); 23 | bool load(); 24 | void setDebugMode(bool boolean); 25 | ~World(void); 26 | }; 27 | 28 | -------------------------------------------------------------------------------- /FoxelEngine/DrawableGameComponent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "gamecomponent.h" 4 | 5 | #define BUFFER_OFFSET(i) (reinterpret_cast(i)) // for VBO 6 | 7 | class DrawableGameComponent : 8 | public GameComponent 9 | { 10 | protected: 11 | GLfloat *vertices, *colors, *normals; 12 | GLuint vao, *indices, vbos[3]; 13 | unsigned int anzVertex; 14 | unsigned int anzIndex; 15 | unsigned int anzPolygon; 16 | public: 17 | DrawableGameComponent(void); 18 | ~DrawableGameComponent(void); 19 | void load(); 20 | virtual void draw(){} 21 | }; 22 | 23 | -------------------------------------------------------------------------------- /FoxelEngine/Pistol.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Model.h" 3 | #include "PropDynamic.h" 4 | #include "Screen.h" 5 | #include "Matrix4.h" 6 | #include "Bullet.h" 7 | class Pistol : public PropDynamic{ 8 | private: 9 | Model* model; 10 | Matrix4 objMatrix; 11 | Vec3d rVelocity; 12 | BulletType bulletType; 13 | int cooldown; 14 | public: 15 | Pistol(void); 16 | ~Pistol(void); 17 | void load(); 18 | void draw(); 19 | void forceR(Vec3d rForce); 20 | void update(float* time); 21 | void shoot(Vec3 position, Vec3 direction); 22 | void shoot2(Vec3 position, Vec3 direction); 23 | }; 24 | 25 | -------------------------------------------------------------------------------- /FoxelEngine/PlayerControler.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | class PlayerControler{ 4 | friend class Player; 5 | private: 6 | unsigned char nlod; //DEBUG! level of detail for chunks 7 | int controleMode; 8 | int wheelState; 9 | bool left, right; 10 | bool forward, backward; 11 | bool sprint; 12 | bool setFoxel,shoot,zoom,midleMouseButton; 13 | 14 | public: 15 | PlayerControler(int controleMode); 16 | void getKeyDown(SDLKey sym); 17 | void getKeyUp(SDLKey sym); 18 | void catchMouseClick(Uint8 button); 19 | void catchMouseRelease(Uint8 button); 20 | ~PlayerControler(void); 21 | }; 22 | 23 | -------------------------------------------------------------------------------- /FoxelEngine/Bullet.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Vec3.h" 3 | #include 4 | 5 | enum BulletType {NORMAL, ROCKET}; 6 | 7 | class Bullet{ 8 | friend class BulletManager; 9 | 10 | private: 11 | BulletType bulletType; 12 | 13 | public: 14 | Vec3 position, velocity; 15 | 16 | Bullet(Vec3 start, Vec3 velocity, BulletType bulletType); 17 | BulletType getBulletType(); 18 | void update(); 19 | ~Bullet(void); 20 | }; 21 | 22 | class BulletManager{ 23 | private: 24 | static std::vector bullets; 25 | 26 | public: 27 | static void addBullet(Bullet* b); 28 | void detectHits(); 29 | 30 | 31 | }; 32 | -------------------------------------------------------------------------------- /FoxelEngine/Core_events.cpp: -------------------------------------------------------------------------------- 1 | #include "Core.h" 2 | #include 3 | 4 | using namespace Event; 5 | 6 | BasicEvent* curentEvent; 7 | setFoxel* p; 8 | 9 | void Core::events(){ 10 | 11 | while(BasicEvent::isWaiting()){ 12 | curentEvent = BasicEvent::getNext(); 13 | p = (setFoxel*)curentEvent; 14 | switch(curentEvent->getID()){ 15 | case SET_FOXEL: FoxelManager::settingFoxel((setFoxel*)curentEvent);break; 16 | case PLAYMODE: startGame(); break; 17 | case EDITMODE: startEditor(); break; 18 | case EXIT: running = false; 19 | break; 20 | 21 | 22 | default: break; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /FoxelEngine/Event.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Event{ 5 | 6 | enum EventID{ SET_FOXEL, EXIT, PLAYMODE, EDITMODE }; 7 | 8 | static int nextEvent; 9 | static int waitingEvents; 10 | 11 | class BasicEvent{ 12 | private: 13 | static void deleteEvents(); 14 | 15 | 16 | protected: 17 | short eventID; 18 | 19 | public: 20 | BasicEvent(void); 21 | BasicEvent(short id); 22 | static void initEventSystem(); 23 | static BasicEvent* getNext(); 24 | static bool isWaiting(); 25 | short getID(); 26 | ~BasicEvent(void); 27 | }; 28 | static std::vector eventList; 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /FoxelEngine/BitmapText.cpp: -------------------------------------------------------------------------------- 1 | #include "BitMapText.h" 2 | 3 | 4 | BitmapText::BitmapText(std::string newText){ 5 | text = newText; 6 | bigText = true; 7 | } 8 | 9 | void BitmapText::setText(std::string newText){ 10 | text = newText; 11 | bigText = true; 12 | } 13 | 14 | 15 | void BitmapText::draw(){ 16 | for(int i = 0; i < text.length(); i++){ 17 | if(bigText){ 18 | glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,text[i]); 19 | }else{ 20 | glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,text[i]); 21 | } 22 | 23 | } 24 | } 25 | 26 | void BitmapText::setBigText(bool boolean){ 27 | bigText = boolean; 28 | } 29 | 30 | BitmapText::~BitmapText(void){ 31 | 32 | } -------------------------------------------------------------------------------- /FoxelEngine/Shader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace GLSL{ 8 | enum ShaderTyp { VERTEX_SHADER = 0, FRAGMENT_SHADER = 1 }; 9 | 10 | class Shader{ 11 | private: 12 | bool imFine; 13 | std::string fileName; 14 | ShaderTyp shaderTyp; 15 | GLuint shaderObject; 16 | GLint fileSize; 17 | char* fileSource; 18 | 19 | void compile(); 20 | void loadFile(std::string fileName); 21 | 22 | public: 23 | Shader(std::string fileName); 24 | ~Shader(void); 25 | bool allRight(); 26 | GLuint getShaderObject(); 27 | 28 | static void printShaderLog(GLint object); 29 | }; 30 | }; -------------------------------------------------------------------------------- /FoxelEngine/Axes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "drawablegamecomponent.h" 4 | 5 | static GLfloat AxeVertices[] = {0,0,0, 6 | 8,0,0, 7 | 0,8,0, 8 | 0,0,8}; 9 | 10 | static GLfloat AxeColor[] = {0,0,0, 11 | 1,0,0, 12 | 0,1,0, 13 | 0,0,1}; 14 | 15 | static GLuint AxeIndices[] = {0,1,0,2,0,3}; 16 | 17 | class Axes : public DrawableGameComponent{ 18 | private: 19 | //VertexPositionColor* vertices; 20 | public: 21 | Axes(void); 22 | ~Axes(void); 23 | void render(); 24 | }; 25 | 26 | -------------------------------------------------------------------------------- /FoxelEngine/Shader/Foxel.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec4 ex_Color; 4 | layout(location = 0) out vec4 frag_Output; 5 | layout(location = 1) out vec3 frag_Normal; 6 | layout(location = 2) out vec3 frag_Position; 7 | 8 | in vec3 ex_Position; 9 | in vec3 ex_Normal; 10 | in vec3 ex_Light; 11 | in vec3 ex_Light_global; 12 | 13 | void main(void){ 14 | frag_Output = vec4(ex_Color.rgb,1.0) + ex_Color.a; 15 | frag_Normal = ex_Normal*0.5+0.5; 16 | frag_Position = ex_Position; 17 | //frag_Output.r += clamp(dot(ex_Normal,ex_Light),0.25,0.75)* 0.25; 18 | //frag_Output.g += clamp(dot(ex_Normal,ex_Light),0.25,0.75)* 0.25; 19 | //frag_Output.b += clamp(dot(ex_Normal,ex_Light),0.25,0.75)* 0.25; 20 | } -------------------------------------------------------------------------------- /FoxelEngine/Vec3d.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Vec2d.h" 3 | class Vec3d : public Vec2d{ 4 | 5 | public: 6 | double z; 7 | 8 | Vec3d(void); 9 | Vec3d(double x, double y, double z); 10 | void normalize(); 11 | double length(); 12 | static double dot(Vec3d left, Vec3d right); 13 | // Operatoren 14 | void operator+=(double skalar); 15 | void operator+=(Vec3d vector); 16 | void operator-=(double skalar); 17 | void operator-=(Vec3d vector); 18 | Vec3d operator*(double skalar); 19 | Vec3d operator*(Vec3d vector); 20 | Vec3d operator-(); 21 | Vec3d operator-(Vec3d vector); 22 | Vec3d operator+(Vec3d vector); 23 | bool operator!=(Vec3d vector); 24 | ~Vec3d(void); 25 | }; 26 | 27 | -------------------------------------------------------------------------------- /FoxelEngine/TextButton.cpp: -------------------------------------------------------------------------------- 1 | #include "TextButton.h" 2 | 3 | 4 | TextButton::TextButton(Vec2 position, Vec2 size, std::string content) 5 | : TextField(position, size, content){ 6 | pressed = false; 7 | } 8 | 9 | void TextButton::press(){ 10 | pressed = true; 11 | } 12 | 13 | void TextButton::release(){ 14 | pressed = false; 15 | } 16 | 17 | bool TextButton::isPressed(){ 18 | return pressed; 19 | } 20 | 21 | bool TextButton::intersect(Vec2 point){ 22 | if(point.x > position.x && point.x < position.x + size.x 23 | && point.y > position.y && point.y < position.y + size.y){ 24 | return true; 25 | }else{ 26 | return false; 27 | } 28 | } 29 | 30 | TextButton::~TextButton(void) 31 | { 32 | } 33 | -------------------------------------------------------------------------------- /FoxelEngine/Vec2.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | class Vec2{ 3 | 4 | public: 5 | float x,y; 6 | 7 | Vec2(void); 8 | Vec2(float x, float y); 9 | 10 | void rotate(Vec2 center, double phi); 11 | void normalize(); 12 | float length(); 13 | static float dot(Vec2 left, Vec2 right); 14 | // Operatoren 15 | void operator+=(float skalar); 16 | void operator+=(Vec2 vector); 17 | void operator-=(float skalar); 18 | void operator-=(Vec2 vector); 19 | Vec2 operator*(float skalar); 20 | Vec2 operator*(Vec2 vector); 21 | Vec2 operator+(float skalar); 22 | Vec2 operator+(Vec2 vector); 23 | Vec2 operator-(float skalar); 24 | Vec2 operator-(Vec2 vector); 25 | Vec2 operator-(); 26 | Vec2 operator+(); 27 | ~Vec2(void); 28 | }; -------------------------------------------------------------------------------- /FoxelEngine/Vec3.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Vec2.h" 3 | #include "Vec3d.h" 4 | class Vec3 : public Vec2{ 5 | 6 | public: 7 | float z; 8 | 9 | Vec3(void); 10 | Vec3(Vec3d vector); 11 | Vec3(float x, float y, float z); 12 | void normalize(); 13 | float length(); 14 | static float dot(Vec3 left, Vec3 right); 15 | // Operatoren 16 | void operator+=(float skalar); 17 | void operator+=(Vec3 vector); 18 | void operator-=(float skalar); 19 | void operator-=(Vec3 vector); 20 | Vec3 operator*(float skalar); 21 | Vec3 operator*(Vec3 vector); 22 | Vec3 operator-(); 23 | Vec3 operator-(Vec3 vector); 24 | Vec3 operator+(Vec3 vector); 25 | bool operator!=(Vec3 vector); 26 | 27 | bool isAxisOriented(); 28 | ~Vec3(void); 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /FoxelEngine/GameGUI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "TextField.h" 4 | #include "Screen.h" 5 | #include "Vec2.h" 6 | 7 | class GameGUI{ 8 | private: 9 | bool debug; 10 | TextField* debugInformations; 11 | std::string debug_ChunkInformations; 12 | std::string debug_GPU_Uploads; 13 | std::string debug_PolycountInformation; 14 | std::string debug_DirectLights; 15 | std::string debug_BounceLights; 16 | 17 | public: 18 | GameGUI(void); 19 | ~GameGUI(void); 20 | void draw(); 21 | void update(); 22 | void setDebugGpuUploads(int value); 23 | void setDebugChunkInformation(int value); 24 | void setDebugPolycountInformation(long value); 25 | void setDebugDirectLightsCount(int value); 26 | void setDebugBounceLightsCount(int value); 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /FoxelEngine/TextField.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "Entity_2D.h" 5 | #include "BitMapText.h" 6 | //#include 7 | 8 | 9 | class TextField : public Entity_2D{ 10 | 11 | protected: 12 | std::vector linesOfContent; 13 | int* displayWidth; 14 | int* displayHeight; 15 | bool withBox, bigText; 16 | int boxPadding; 17 | GLfloat textColor[3]; 18 | 19 | public: 20 | TextField(Vec2 position, Vec2 size, std::string); 21 | TextField(Vec2 position, Vec2 size); 22 | ~TextField(void); 23 | 24 | Vec2 getPosition(); 25 | void setContent(int,std::string); 26 | void setTextColor(float r, float g, float b); 27 | void draw(); 28 | void setBigText(bool boolean); 29 | void newLine(std::string); 30 | void setWithBox(bool boolean); 31 | }; -------------------------------------------------------------------------------- /FoxelEngine/Matrix4.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "Vec3.h" 5 | static const int M_SIZE = 4; 6 | class Matrix4{ 7 | 8 | public: 9 | Matrix4(void); 10 | ~Matrix4(void); 11 | float matrix[M_SIZE*M_SIZE]; 12 | 13 | static Matrix4 Identity(); 14 | 15 | static Matrix4 RotateX(float angle); 16 | static Matrix4 RotateY(float angle); 17 | static Matrix4 RotateZ(float angle); 18 | static Matrix4 CreateFromAxisAngle(Vec3 axis, float angle); 19 | 20 | Matrix4 operator*(Matrix4 B); 21 | 22 | void scale(float x, float y, float z); 23 | void translate(float x,float y,float z); 24 | void translate(Vec3 vector); 25 | void rotate(float angle, float x, float y, float z); 26 | 27 | 28 | 29 | float* getMatrix(); 30 | void printMatrix(); 31 | }; 32 | 33 | -------------------------------------------------------------------------------- /FoxelEngine/Model.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | #define BUFFER_OFFSET(i) (reinterpret_cast(i)) // for VBO 10 | 11 | struct GLVertex{ 12 | GLfloat x,y,z; 13 | GLfloat a,b,c; 14 | GLfloat u,v; 15 | }; 16 | 17 | struct Vertex{ 18 | float x,y,z; 19 | }; 20 | 21 | struct Normal{ 22 | float a,b,c; 23 | }; 24 | 25 | struct Textur{ 26 | float u,v; 27 | }; 28 | 29 | class Model{ 30 | private: 31 | static GLuint anzVertex, anzIndex; 32 | static GLVertex* vertices; 33 | static GLuint vao, *indices, vbos[2]; 34 | static bool loaded; 35 | 36 | 37 | public: 38 | Model(); 39 | ~Model(); 40 | bool load(char* objfile); 41 | void draw(); 42 | }; 43 | 44 | -------------------------------------------------------------------------------- /FoxelEngine/Color.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Color{ 4 | unsigned char RGBA[4]; 5 | public: 6 | Color(void); 7 | Color(unsigned char R, unsigned char G, unsigned char B); 8 | Color(unsigned char R, unsigned char G, unsigned char B, unsigned char A); 9 | 10 | unsigned char* getColorArray(); 11 | unsigned char getRed(); 12 | unsigned char getGreen(); 13 | unsigned char getBlue(); 14 | unsigned char getAlpha(); 15 | 16 | void setColor(unsigned char r, unsigned char g, unsigned char b); 17 | void setColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a); 18 | 19 | void setRed(unsigned char r); 20 | void setGreen(unsigned char g); 21 | void setBlue(unsigned char b); 22 | void setAlpha(unsigned char a); 23 | unsigned char getMaximum(); 24 | short getLuminate(); 25 | }; 26 | 27 | -------------------------------------------------------------------------------- /FoxelEngine/PostProcessor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | static const GLfloat g_quad_vertex_buffer_data[] = { 5 | -1.0f, -1.0f, 0.0f, 6 | 1.0f, -1.0f, 0.0f, 7 | -1.0f, 1.0f, 0.0f, 8 | -1.0f, 1.0f, 0.0f, 9 | 1.0f, -1.0f, 0.0f, 10 | 1.0f, 1.0f, 0.0f, 11 | }; 12 | 13 | 14 | class PostProcessor{ 15 | private: 16 | GLuint framebuffer; 17 | GLuint renderedTexture; 18 | GLuint positionTexture; 19 | GLuint normalTexture; 20 | GLuint depthTexture; 21 | GLuint depthrenderbuffer; 22 | 23 | GLuint quad_VertexArrayID; 24 | GLuint quad_vertexbuffer; 25 | 26 | GLuint bounceLightTexture; 27 | void generateBounceLightTexture(); 28 | 29 | public: 30 | PostProcessor(void); 31 | ~PostProcessor(void); 32 | void setupToDraw(); 33 | void draw(); 34 | bool load(); 35 | }; 36 | 37 | -------------------------------------------------------------------------------- /FoxelEngine/ShaderProgram.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "Shader.h" 5 | 6 | #define ShaderProgram PM // Programm Manager 7 | 8 | namespace GLSL{ 9 | enum ProgramTyp { PROGRAM_NULL = 0, PROGRAM_BASIC = 1, PROGRAM_FOXEL = 2, PROGRAM_MODEL = 3 , PROGRAM_POST = 4}; 10 | 11 | class ShaderProgram{ 12 | private: 13 | static ProgramTyp ActiveProgram; 14 | GLuint programObject; 15 | Shader* fragmentShader; 16 | Shader* vertexSchader; 17 | 18 | public: 19 | GLuint getProgram(); 20 | ShaderProgram(ProgramTyp typ); 21 | ~ShaderProgram(void); 22 | static void useProg(ProgramTyp typ); 23 | static GLint getUnifLoc(ProgramTyp typ, const GLchar *name); 24 | static GLint getActiveUnifLoc(const GLchar *name); 25 | }; 26 | static std::map progMap; 27 | }; -------------------------------------------------------------------------------- /FoxelEngine/View.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Entity_2D.h" 4 | #include "ShaderProgram.h" 5 | #include "Screen.h" 6 | #include "Vec3.h" 7 | #include "Player.h" 8 | namespace MapEditor{ 9 | enum ViewModus {VIEW_3D = 0, VIEW_TOP = 1, VIEW_RIGHT = 2, VIEW_FRONT = 3}; 10 | 11 | class View : public Entity_2D{ 12 | friend class Editor; 13 | private: 14 | ViewModus viewMode; 15 | Vec3 viewPosition; 16 | Player* ePlayer; 17 | float zoom; 18 | void drawGrid(); 19 | public: 20 | View(ViewModus viewMode, Vec2 position, Vec2 size); 21 | ~View(void); 22 | void setUp(); 23 | void update(float* time); 24 | void draw(); 25 | Player* getPlayer(); 26 | void addZoomValue(float value); 27 | void moveViewPosition(Vec3 value); 28 | 29 | ViewModus getViewMode(); 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /FoxelEngine/Camera.cpp: -------------------------------------------------------------------------------- 1 | #include "Camera.h" 2 | using namespace GLSL; 3 | 4 | Camera::Camera() : PropDynamic(){ 5 | } 6 | 7 | Camera::Camera(Vec3d position) 8 | : PropDynamic(position){ 9 | } 10 | void Camera::setupView(){ 11 | Screen::ViewMatrix = Matrix4::Identity(); 12 | Screen::ViewMatrix.rotate((float)rotation.x, 1.0f, 0.0f, 0.0f); 13 | Screen::ViewMatrix.rotate((float)rotation.z, 0.0f, 0.0f, 1.0f); 14 | Screen::ViewMatrix.translate((float)position.x,(float)position.y,(float)position.z); 15 | PM::useProg(PROGRAM_MODEL); 16 | glUniform3f(PM::getActiveUnifLoc("player_position"),(float)-position.x,(float)-position.y,(float)-position.z); 17 | PM::useProg(PROGRAM_FOXEL); 18 | glUniform3f(PM::getActiveUnifLoc("player_position"),(float)-position.x,(float)-position.y,(float)-position.z); 19 | } 20 | 21 | Camera::~Camera(void){ 22 | } 23 | 24 | -------------------------------------------------------------------------------- /FoxelEngine/Config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | enum DisplayMode{ DISPLAY_NORMAL, DISPLAY_WIRE, DISPLAY_QUAD, DISPLAY_WITHOUT_RAD }; 9 | 10 | class Config{ 11 | std::vector configContent; 12 | int screenW, screenH; 13 | bool fullscreen; 14 | 15 | static DisplayMode displayMode; 16 | static bool debug; 17 | static int chunkThreads; 18 | 19 | public: 20 | Config(void); 21 | void readConfig(std::string fileName); 22 | int getScreenW(); 23 | int getScreenH(); 24 | 25 | bool isFullscreen(); 26 | ~Config(void); 27 | 28 | void switchDebugMode(); 29 | void setDisplayMode(DisplayMode mode); 30 | 31 | static bool isDebug(); 32 | static DisplayMode getDisplayMode(); 33 | static int getChunkThreads(); 34 | }; 35 | 36 | -------------------------------------------------------------------------------- /FoxelEngine/PropDynamic.cpp: -------------------------------------------------------------------------------- 1 | #include "PropDynamic.h" 2 | 3 | 4 | PropDynamic::PropDynamic(void) : GameComponent(){ 5 | friction = 0.005f; 6 | } 7 | 8 | PropDynamic::PropDynamic(Vec3d position){ 9 | friction = 0.005f; 10 | this->position = position; 11 | } 12 | 13 | void PropDynamic::update(float* time){ 14 | velocity -= velocity * (friction / 2*(*time)); 15 | position += velocity **time; 16 | } 17 | 18 | //------------------------------------------------------------------------- 19 | // Setter Methods 20 | //------------------------------------------------------------------------- 21 | void PropDynamic::setFriction(float friction){ 22 | PropDynamic::friction = friction; 23 | } 24 | void PropDynamic::setRotation(Vec3d rotation){ 25 | this->rotation = rotation; 26 | } 27 | void PropDynamic::setPosition(Vec3d position){ 28 | this->position = position; 29 | } 30 | 31 | PropDynamic::~PropDynamic(void) 32 | { 33 | } 34 | -------------------------------------------------------------------------------- /FoxelEngine/Foxel.cpp: -------------------------------------------------------------------------------- 1 | #include "foxel.h" 2 | 3 | 4 | Foxel::Foxel() 5 | { 6 | color[0] = 64 , color[1] = 64 , color[2] = 64; 7 | visiblity = 63; 8 | id = 0; 9 | } 10 | Foxel::Foxel(char idFoxel, char vis){ 11 | color[0] = 64 , color[1] = 64 , color[2] = 64; 12 | visiblity = vis; 13 | id = idFoxel; 14 | test = true; 15 | } 16 | 17 | 18 | Foxel::~Foxel() 19 | { 20 | } 21 | 22 | void Foxel::setColor(GLushort r, GLushort g, GLushort b){ 23 | color[0] = r; 24 | color[1] = g; 25 | color[2] = b; 26 | } 27 | 28 | // Setzt Das jeweilige bit 29 | void Foxel::setVisiblity(char setBit){ 30 | if(setBit > 0){ 31 | visiblity |= setBit; 32 | }else{ 33 | visiblity &= setBit; 34 | } 35 | } 36 | 37 | char Foxel::getVisiblity(){ 38 | return visiblity; 39 | } 40 | 41 | void Foxel::setId(char setterID){ 42 | id = setterID; 43 | } 44 | 45 | char Foxel::getId(){ 46 | return id; 47 | } 48 | 49 | GLushort* Foxel::getColor(){ 50 | return color; 51 | } 52 | -------------------------------------------------------------------------------- /FoxelEngine/DirectLight.cpp: -------------------------------------------------------------------------------- 1 | #include "DirectLight.h" 2 | 3 | DirectLight::DirectLight(std::vector id){ 4 | this->id = id; 5 | } 6 | 7 | 8 | float* DirectLight::generateDirectLightArray(){ 9 | float* lightArray = new float[lights.size()*10]; 10 | int k = 0; 11 | for(int i = 0; i < lights.size();i++){ 12 | lightArray[k+0] = lights[i].position.x; 13 | lightArray[k+1] = lights[i].position.y; 14 | lightArray[k+2] = lights[i].position.z; 15 | 16 | lightArray[k+3] = lights[i].normal.x; 17 | lightArray[k+4] = lights[i].normal.y; 18 | lightArray[k+5] = lights[i].normal.z; 19 | 20 | lightArray[k+6] = lights[i].color.getRed(); 21 | lightArray[k+7] = lights[i].color.getGreen(); 22 | lightArray[k+8] = lights[i].color.getBlue(); 23 | lightArray[k+9] = lights[i].color.getAlpha(); 24 | k += 10; 25 | } 26 | return lightArray; 27 | } 28 | 29 | std::vector DirectLight::getLight(){ 30 | return lights; 31 | } -------------------------------------------------------------------------------- /FoxelEngine/Editor.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "View.h" 4 | #include "Axes.h" 5 | #include "GameMenu.h" 6 | #include "ToolBox.h" 7 | #include "Controler.h" 8 | #include "BrushBox.h" 9 | #include "ColorPanel.h" 10 | 11 | namespace MapEditor{ 12 | class Editor : public GameMenu{ 13 | private: 14 | ToolBox* toolBox; 15 | Controler* controler; 16 | std::vector views; 17 | View* activeView; 18 | View* catchActiveView(); 19 | Axes* center; 20 | ColorPanel* colorPanel; 21 | BrushBox* brush; 22 | bool playMode; 23 | static int gridDeep; 24 | void save(); 25 | 26 | public: 27 | Editor(void); 28 | ~Editor(void); 29 | 30 | void draw(); 31 | void update(float* time); 32 | void catchMouseClick(Vec2 pos); 33 | void catchKeyDown(SDLKey sym); 34 | void catchKeyUp(SDLKey sym); 35 | void resize(); 36 | MapEditor::Controler* getControler(); 37 | static int getGridDeep(); 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /FoxelEngine/Event.cpp: -------------------------------------------------------------------------------- 1 | #include "Event.h" 2 | using namespace Event; 3 | BasicEvent::BasicEvent(void){ 4 | eventList.push_back(this); 5 | waitingEvents++; 6 | } 7 | 8 | BasicEvent::BasicEvent(short id){ 9 | eventID = id; 10 | eventList.push_back(this); 11 | waitingEvents++; 12 | } 13 | 14 | void BasicEvent::initEventSystem(){ 15 | waitingEvents = 0; 16 | nextEvent = -1; 17 | } 18 | 19 | BasicEvent* BasicEvent::getNext(){ 20 | nextEvent++; 21 | waitingEvents--; 22 | if(nextEvent <= (int)eventList.size()){ 23 | return eventList[nextEvent]; 24 | }else{ 25 | deleteEvents(); 26 | return NULL; 27 | } 28 | } 29 | 30 | short BasicEvent::getID(){ 31 | return eventID; 32 | } 33 | 34 | bool BasicEvent::isWaiting(){ 35 | if(waitingEvents > 0) return true; 36 | else return false; 37 | } 38 | 39 | void BasicEvent::deleteEvents(){ 40 | for(unsigned int i = 0; i < eventList.size(); i++){ 41 | delete eventList[i]; 42 | } 43 | eventList.clear(); 44 | } 45 | 46 | BasicEvent::~BasicEvent(void){ 47 | } 48 | -------------------------------------------------------------------------------- /FoxelEngine/DrawableGameComponent.cpp: -------------------------------------------------------------------------------- 1 | #include "DrawableGameComponent.h" 2 | #include 3 | 4 | DrawableGameComponent::DrawableGameComponent(void){ 5 | } 6 | 7 | DrawableGameComponent::~DrawableGameComponent(void) 8 | { 9 | } 10 | 11 | void DrawableGameComponent::load(){ 12 | glGenVertexArrays(1,&vao); 13 | glBindVertexArray(vao); 14 | glGenBuffers(3,vbos); 15 | 16 | // vertex data 17 | glBindBuffer(GL_ARRAY_BUFFER,vbos[0]); 18 | glBufferData(GL_ARRAY_BUFFER,anzVertex*sizeof(GLfloat)*3,vertices,GL_STATIC_DRAW); 19 | glVertexAttribPointer(0,3,GL_FLOAT, GL_FALSE,0,0); 20 | 21 | // Color data 22 | glBindBuffer(GL_ARRAY_BUFFER,vbos[1]); 23 | glBufferData(GL_ARRAY_BUFFER,anzVertex*sizeof(GLfloat)*3,colors,GL_STATIC_DRAW); 24 | glVertexAttribPointer(1,3,GL_FLOAT, GL_FALSE,0,0); 25 | 26 | // index data 27 | glBindBuffer(GL_ARRAY_BUFFER,vbos[2]); 28 | glBufferData(GL_ARRAY_BUFFER,anzIndex*sizeof(GL_UNSIGNED_INT),indices,GL_STATIC_DRAW); 29 | 30 | 31 | glBindVertexArray(0); 32 | } -------------------------------------------------------------------------------- /FoxelEngine/Shader/Model.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | uniform mat4 viewMatrix, projMatrix; 4 | uniform vec3 player_position; 5 | uniform vec3 chunk_Position; 6 | 7 | in vec3 in_Position; 8 | in vec4 in_Color; 9 | in vec3 in_Normal; 10 | 11 | vec3 lightPos; 12 | vec3 g_lightPos = vec3(-102400,-51200,102400); 13 | 14 | out vec3 ex_Normal; 15 | out vec3 ex_Light; 16 | out vec4 ex_Color; 17 | 18 | float hsv,g_hsv; 19 | float entf; 20 | void main(void) 21 | { 22 | // player light 23 | lightPos = player_position; 24 | entf = distance(in_Position, lightPos); 25 | hsv = dot(in_Normal, normalize(lightPos - in_Position)); 26 | 27 | // global light 28 | g_hsv = clamp(dot(in_Normal, normalize(g_lightPos)),0.1,1.0); 29 | 30 | ex_Color = vec4(0.8,0.8,0.8,1.0); 31 | ex_Color *= clamp((g_hsv*0.25) + (hsv*0.25/(entf/16.0)),0.1,1.0); 32 | 33 | gl_Position = projMatrix * viewMatrix * vec4(in_Position, 1.0); 34 | 35 | ex_Light = normalize(lightPos - in_Position); 36 | ex_Normal = in_Normal; 37 | } 38 | -------------------------------------------------------------------------------- /FoxelEngine/Bullet.cpp: -------------------------------------------------------------------------------- 1 | #include "Bullet.h" 2 | #include "FoxelManager.h" 3 | 4 | 5 | Bullet::Bullet(Vec3 start,Vec3 direction, BulletType bulletType){ 6 | position = start; 7 | velocity = direction; 8 | this->bulletType = bulletType; 9 | } 10 | 11 | 12 | Bullet::~Bullet(void) 13 | { 14 | } 15 | 16 | void Bullet::update(){ 17 | position += velocity; 18 | } 19 | 20 | BulletType Bullet::getBulletType(){ 21 | return bulletType; 22 | } 23 | 24 | 25 | ///////////////////////////////////////////////////////////////// 26 | // BulletManager 27 | ///////////////// 28 | 29 | std::vector BulletManager::bullets; 30 | 31 | void BulletManager::addBullet(Bullet* b){ 32 | bullets.push_back(b); 33 | } 34 | 35 | void BulletManager::detectHits(){ 36 | for(int i = 0; i < bullets.size(); i++){ 37 | 38 | if(FoxelManager::detectBulletHit(&bullets[i]->position,&bullets[i]->velocity)){ 39 | // Hit detected 40 | 41 | } 42 | delete bullets[i]; 43 | } 44 | 45 | bullets.clear(); 46 | } -------------------------------------------------------------------------------- /FoxelEngine/Vec2d.cpp: -------------------------------------------------------------------------------- 1 | #include "Vec2d.h" 2 | 3 | Vec2d::Vec2d(void){ 4 | x = 0; 5 | y = 0; 6 | } 7 | 8 | Vec2d::Vec2d(double x,double y){ 9 | Vec2d::x = x; 10 | Vec2d::y = y; 11 | } 12 | 13 | void Vec2d::operator+=(double skalar){ 14 | Vec2d::x += skalar; 15 | Vec2d::y += skalar; 16 | } 17 | 18 | void Vec2d::operator+=(Vec2d vector){ 19 | Vec2d::x += vector.x; 20 | Vec2d::y += vector.y; 21 | } 22 | 23 | void Vec2d::operator-=(double skalar){ 24 | Vec2d::x -= skalar; 25 | Vec2d::y -= skalar; 26 | } 27 | 28 | void Vec2d::operator-=(Vec2d vector){ 29 | Vec2d::x -= vector.x; 30 | Vec2d::y -= vector.y; 31 | } 32 | 33 | Vec2d Vec2d::operator*(double skalar){ 34 | Vec2d tmp = *this; 35 | tmp.x *= skalar; 36 | tmp.y *= skalar; 37 | return tmp; 38 | } 39 | 40 | Vec2d Vec2d::operator*(Vec2d vector){ 41 | Vec2d tmp = *this; 42 | tmp.x *= vector.x; 43 | tmp.y *= vector.y; 44 | return tmp; 45 | } 46 | 47 | Vec2d Vec2d::operator-(){ 48 | Vec2d tmp = *this; 49 | tmp.x *= -1; 50 | tmp.y *= -1; 51 | return tmp; 52 | } 53 | 54 | Vec2d::~Vec2d(void) 55 | { 56 | } 57 | -------------------------------------------------------------------------------- /FoxelEngine/Player.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "PropDynamic.h" 5 | #include "Camera.h" 6 | #include "PlayerControler.h" 7 | #include "Pistol.h" 8 | #include "Vec3.h" 9 | #include "Convert.h" 10 | #include "Foxel_Interaction.h" 11 | 12 | enum PlayerTyp { PLAYER_NORMAL = 1, PLAYER_EDIT = 2, PLAYER_FOX = 1337}; 13 | 14 | class Player : public PropDynamic{ 15 | private: 16 | Pistol* pistol; 17 | Camera* camera; 18 | PlayerControler* controler; 19 | 20 | // propertys 21 | float maxMoveSpeed; 22 | float accelerateValue; 23 | float drx,dry; 24 | int playerTyp; 25 | 26 | short health; 27 | short armor; 28 | 29 | bool noclip; 30 | 31 | Vec3 calcDirVector(); 32 | void createEvents(); 33 | public: 34 | Player(int typ); 35 | void setTyp(int typ); 36 | void catchKeyDown(SDLKey sym); 37 | void catchKeyUp(SDLKey sym); 38 | void catchMouseMotion(float x, float y); 39 | PlayerControler* getControler(); 40 | void update(float* time); 41 | void render(); 42 | ~Player(void); 43 | }; 44 | 45 | -------------------------------------------------------------------------------- /FoxelEngine/CollisionDetector.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Vec3.h" 3 | // Copy Paste :D________________________________________________________________________________ 4 | bool inline GetIntersection( float fDst1, float fDst2, Vec3 P1, Vec3 P2, Vec3 &Hit) { 5 | if ( (fDst1 * fDst2) >= 0.0f) return false; 6 | if ( fDst1 == fDst2) return false; 7 | Hit = P1 + (P2-P1) * ( -fDst1/(fDst2-fDst1) ); 8 | return true; 9 | } 10 | 11 | int inline InBox( Vec3 Hit, Vec3 B1, Vec3 B2, const int Axis) { 12 | if ( Axis==1 && Hit.z > B1.z && Hit.z < B2.z && Hit.y > B1.y && Hit.y < B2.y) return true; 13 | if ( Axis==2 && Hit.z > B1.z && Hit.z < B2.z && Hit.x > B1.x && Hit.x < B2.x) return true; 14 | if ( Axis==3 && Hit.x > B1.x && Hit.x < B2.x && Hit.y > B1.y && Hit.y < B2.y) return true; 15 | return false; 16 | } 17 | 18 | 19 | 20 | class CollisionDetector 21 | { 22 | public: 23 | 24 | /** 25 | * returns true if line (L1, L2) intersects with the box (B1, B2) 26 | * returns intersection point in Hit 27 | */ 28 | static bool LineBox(Vec3 B1, Vec3 B2, Vec3 L1, Vec3 L2, Vec3 &Hit); 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /FoxelEngine/Core.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include // for Debug infos 3 | 4 | #include "Event.h" 5 | #include "Screen.h" 6 | #include "World.h" 7 | #include "Player.h" 8 | #include "Config.h" 9 | #include "Main_Menu.h" 10 | #include "Editor.h" 11 | #include "PostProcessor.h" 12 | 13 | 14 | enum{ON_MAIN_MENU = 0, ON_GAME = 1, ON_EDIT = 2, ON_GAME_PAUSE = 3}; 15 | 16 | class Core 17 | { 18 | private: 19 | Config* config; 20 | Screen* screen; 21 | SDL_Event* sdlEvent; 22 | World* world; 23 | Player* player; 24 | Main_Menu* mainMenu; 25 | MapEditor::Editor* editor; 26 | PostProcessor* postPro; 27 | 28 | float tickrate, tick; 29 | int userState; 30 | bool debugMode; 31 | 32 | void startGame(); 33 | void startEditor(); 34 | void inputOnGame(); 35 | void inputOnMenu(); 36 | void inputOnEdit(); 37 | void specialInputs(); 38 | 39 | public: 40 | bool running; 41 | 42 | 43 | Core(void); 44 | bool init(int argc, char *argv[]); 45 | void inputs(); 46 | void events(); 47 | void update(float* time); 48 | void render(); 49 | ~Core(void); 50 | }; 51 | 52 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 André Furchner 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /FoxelEngine/Map.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "Vec3.h" 4 | #include 5 | #include 6 | #include "Color.h" 7 | class Brush{ 8 | public: 9 | unsigned char sX,sY,sZ; // Start Point x y z; 10 | unsigned char eX,eY,eZ; // End Point x y z; 11 | unsigned char cR,cG,cB,em; // Color 12 | short id; // Foxel id 13 | Brush(){} 14 | Brush(unsigned char sX, unsigned char sY, unsigned char sZ, 15 | unsigned char eX, unsigned char eY, unsigned char eZ, 16 | short id, unsigned char cR, unsigned char cG, unsigned char cB, 17 | unsigned char em){ 18 | this->sX = sX; this->sY = sY; this->sZ = sZ; 19 | this->eX = eX; this->eY = eY; this->eZ = eZ; 20 | this->id = id; this->cR = cR; this->cG = cG; 21 | this->cB = cB; this->em = em; 22 | } 23 | }; 24 | 25 | class ChunkBrush : public Brush { 26 | public: 27 | int idX, idY, idZ; 28 | }; 29 | 30 | class Map{ 31 | static std::string name; 32 | public: 33 | Map(); 34 | ~Map(void); 35 | static void createBlock(Vec3 start, Vec3 end, short id, Color color); 36 | static void update(); 37 | static bool load(std::string mapName); 38 | static void save(std::string mapName); 39 | }; -------------------------------------------------------------------------------- /FoxelEngine/CollisionDetector.cpp: -------------------------------------------------------------------------------- 1 | #include "CollisionDetector.h" 2 | 3 | bool CollisionDetector::LineBox(Vec3 B1, Vec3 B2, Vec3 L1, Vec3 L2, Vec3 &Hit){ 4 | if (L2.x < B1.x && L1.x < B1.x){ return false;} 5 | if (L2.x > B2.x && L1.x > B2.x){ return false;} 6 | if (L2.y < B1.y && L1.y < B1.y){ return false;} 7 | if (L2.y > B2.y && L1.y > B2.y){ return false;} 8 | if (L2.z < B1.z && L1.z < B1.z){ return false;} 9 | if (L2.z > B2.z && L1.z > B2.z){ return false;} 10 | 11 | if (L1.x > B1.x && L1.x < B2.x 12 | && L1.y > B1.y && L1.y < B2.y 13 | && L1.z > B1.z && L1.z < B2.z){ 14 | Hit = L1; 15 | return true; 16 | } 17 | 18 | if ( (GetIntersection( L1.x-B1.x, L2.x-B1.x, L1, L2, Hit) && InBox( Hit, B1, B2, 1 )) 19 | || (GetIntersection( L1.y-B1.y, L2.y-B1.y, L1, L2, Hit) && InBox( Hit, B1, B2, 2 )) 20 | || (GetIntersection( L1.z-B1.z, L2.z-B1.z, L1, L2, Hit) && InBox( Hit, B1, B2, 3 )) 21 | || (GetIntersection( L1.x-B2.x, L2.x-B2.x, L1, L2, Hit) && InBox( Hit, B1, B2, 1 )) 22 | || (GetIntersection( L1.y-B2.y, L2.y-B2.y, L1, L2, Hit) && InBox( Hit, B1, B2, 2 )) 23 | || (GetIntersection( L1.z-B2.z, L2.z-B2.z, L1, L2, Hit) && InBox( Hit, B1, B2, 3 ))){ 24 | return true; 25 | }else{ 26 | return false; 27 | } 28 | } -------------------------------------------------------------------------------- /FoxelEngine/GameMenu.cpp: -------------------------------------------------------------------------------- 1 | #include "GameMenu.h" 2 | 3 | 4 | GameMenu::GameMenu(Vec2 position, Vec2 size) : Entity_2D(position, size){ 5 | 6 | } 7 | 8 | GameMenu::GameMenu(){} 9 | 10 | GameMenu::~GameMenu(void){ 11 | } 12 | 13 | void GameMenu::update(){ 14 | catchMousePosition(Screen::getMousePosition()); 15 | if(Screen::isKlickLeft()) catchMouseClick(Screen::getMousePosition()); 16 | } 17 | 18 | void GameMenu::draw(){ 19 | for(unsigned int i = 0; i < selectOptions.size(); i++){ 20 | selectOptions[i].draw(); 21 | } 22 | } 23 | 24 | void GameMenu::catchMousePosition(Vec2 mpos){ 25 | //mpos.y += Screen::getHeight() - 2 *mpos.y; 26 | for(unsigned int i = 0; i < selectOptions.size(); i++){ 27 | if(selectOptions[i].intersect(mpos)){ 28 | selectOptions[i].setTextColor(1.0f,0.0f,0.0f); 29 | }else{ 30 | selectOptions[i].setTextColor(1.0f,1.0f,1.0f); 31 | } 32 | } 33 | } 34 | 35 | void GameMenu::catchMouseClick(Vec2 mpos){ 36 | //mpos.y += Screen::getHeight() - 2 *mpos.y; 37 | for(unsigned int i = 0; i < selectOptions.size(); i++){ 38 | if(selectOptions[i].intersect(mpos)){ 39 | selectOptions[i].press(); 40 | }else{ 41 | selectOptions[i].release(); 42 | } 43 | } 44 | createEvents(); 45 | } 46 | 47 | void GameMenu::createEvents(){} -------------------------------------------------------------------------------- /FoxelEngine/Shader/Foxel.vert: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | uniform mat4 viewMatrix, projMatrix; 4 | uniform vec3 player_position; 5 | uniform vec3 chunk_Position; 6 | 7 | in vec3 in_Position; 8 | in vec4 in_Color; 9 | in vec3 in_Normal; 10 | 11 | vec3 lightPos; 12 | vec3 g_lightPos = vec3(102400,-51200,102400); 13 | 14 | out vec4 ex_Color; 15 | out vec3 ex_Position; 16 | out vec3 ex_Normal; 17 | out vec3 ex_Light; 18 | out vec3 ex_Light_global; 19 | 20 | float hsv,g_hsv; 21 | float entf; 22 | void main(void) 23 | { 24 | // player light 25 | //lightPos = player_position+chunk_Position; 26 | //entf = distance(in_Position, lightPos); 27 | 28 | //hsv = dot(in_Normal, normalize(lightPos - in_Position)); 29 | 30 | // global light 31 | //g_lightPos += chunk_Position; 32 | //g_hsv = clamp(dot(in_Normal, normalize(g_lightPos)),0.25,0.75); 33 | 34 | ex_Color = in_Color/255; 35 | //ex_Color = vec4((in_Normal+1) / 2,1); 36 | //ex_Color *= clamp((g_hsv) + (hsv*0.25/(entf/64.0)),0.25,0.75); 37 | 38 | gl_Position = projMatrix * viewMatrix * vec4(in_Position, 1.0); 39 | 40 | //ex_Light = normalize(lightPos - in_Position); 41 | //ex_Light_global = normalize(g_lightPos - in_Position); 42 | ex_Normal = normalize(in_Normal); 43 | ex_Position = in_Position + chunk_Position; 44 | 45 | } 46 | -------------------------------------------------------------------------------- /FoxelEngine.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FoxelEngine", "FoxelEngine\FoxelEngine.vcxproj", "{491E58BB-ACA8-43DE-BC54-B39A7536F803}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Debug|x64 = Debug|x64 10 | Release|Win32 = Release|Win32 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {491E58BB-ACA8-43DE-BC54-B39A7536F803}.Debug|Win32.ActiveCfg = Debug|Win32 15 | {491E58BB-ACA8-43DE-BC54-B39A7536F803}.Debug|Win32.Build.0 = Debug|Win32 16 | {491E58BB-ACA8-43DE-BC54-B39A7536F803}.Debug|x64.ActiveCfg = Debug|x64 17 | {491E58BB-ACA8-43DE-BC54-B39A7536F803}.Debug|x64.Build.0 = Debug|x64 18 | {491E58BB-ACA8-43DE-BC54-B39A7536F803}.Release|Win32.ActiveCfg = Release|Win32 19 | {491E58BB-ACA8-43DE-BC54-B39A7536F803}.Release|Win32.Build.0 = Release|Win32 20 | {491E58BB-ACA8-43DE-BC54-B39A7536F803}.Release|x64.ActiveCfg = Release|x64 21 | {491E58BB-ACA8-43DE-BC54-B39A7536F803}.Release|x64.Build.0 = Release|x64 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /FoxelEngine/World.cpp: -------------------------------------------------------------------------------- 1 | #include "World.h" 2 | #include "Map.h" 3 | 4 | using namespace GLSL; 5 | 6 | World::World(void){ 7 | center = new Axes(); 8 | bulletManager = new BulletManager(); 9 | gui = new GameGUI(); 10 | 11 | } 12 | 13 | bool World::load(){ 14 | 15 | if(Map::load("Test_Map")){ 16 | 17 | } 18 | center->load(); 19 | return true; 20 | } 21 | 22 | void World::update(){ 23 | bulletManager->detectHits(); 24 | Map::update(); 25 | 26 | if(Config::isDebug()){ 27 | gui->setDebugChunkInformation(FoxelManager::getNumberOfCurrentChunkUpdates()); 28 | gui->setDebugPolycountInformation(FoxelManager::getPolyCount()); 29 | gui->setDebugGpuUploads(FoxelManager::getNumberOfPendingGpuUploads()); 30 | gui->setDebugDirectLightsCount(FoxelManager::getNumberOfDirectLights()); 31 | gui->setDebugBounceLightsCount(FoxelManager::getNumberOfBounceLights()); 32 | gui->update(); 33 | } 34 | } 35 | 36 | void World::render(){ 37 | Screen::updateViewMatix(); 38 | 39 | FoxelManager::render(); 40 | 41 | PM::useProg(PROGRAM_MODEL); 42 | Screen::updateProjMatix(); 43 | Screen::updateViewMatix(); 44 | center->render(); 45 | } 46 | 47 | void World::drawGui(){ 48 | PM::useProg(PROGRAM_NULL); 49 | if(Config::isDebug()) gui->draw(); 50 | } 51 | 52 | World::~World(void){ 53 | delete gui; 54 | } -------------------------------------------------------------------------------- /FoxelEngine/BrushBox.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "DrawableGameComponent.h" 4 | #include "Vec3.h" 5 | #include "Screen.h" 6 | #include "Color.h" 7 | 8 | static GLfloat BoxV[] = {0.0f , 0.0f , 0.0f , 9 | 128.0f, 0.0f , 0.0f , 10 | 0.0f , 128.0f, 0.0f , 11 | 0.0f , 0.0f , 128.0f, 12 | 128.0f, 128.0f, 128.0f, 13 | 0.0f , 128.0f, 128.0f, 14 | 128.0f, 0.0f , 128.0f, 15 | 128.0f, 128.0f, 0.0f ,}; 16 | 17 | static GLfloat BoxC[] = {1.0f , 0.0f , 0.0f , 18 | 1.0f , 0.0f , 0.0f , 19 | 1.0f , 0.0f , 0.0f , 20 | 1.0f , 0.0f , 0.0f , 21 | 1.0f , 0.0f , 0.0f , 22 | 1.0f , 0.0f , 0.0f , 23 | 1.0f , 0.0f , 0.0f , 24 | 1.0f , 0.0f , 0.0f }; 25 | 26 | static GLuint BoxI[] = {0,1, 0,2, 0,3, 4,5, 4,6, 4,7, 27 | 1,6, 2,5, 3,5, 2,7, 3,6, 1,7}; 28 | 29 | class BrushBox : public DrawableGameComponent{ 30 | private: 31 | Vec3 moved; 32 | Vec3 snapedPosition; 33 | Vec3 paintStart, paintStop; 34 | Vec3 size; 35 | bool painting; 36 | int paintID; 37 | void rebuildMesh(); 38 | Color color; 39 | public: 40 | BrushBox(void); 41 | ~BrushBox(void); 42 | void draw(); 43 | void startPaint(); 44 | void stopPaint(); 45 | void move(Vec3 value); 46 | void setSize(Vec3 size); 47 | void setPaintID(int id); 48 | void makeBlock(); 49 | void setColor(Color color); 50 | }; 51 | 52 | -------------------------------------------------------------------------------- /FoxelEngine/Entity_2D.cpp: -------------------------------------------------------------------------------- 1 | #include "Entity_2D.h" 2 | #include "Screen.h" 3 | 4 | Entity_2D::Entity_2D(Vec2 position, Vec2 size){ 5 | this->position = position; 6 | this->size = size; 7 | backColor.setColor(32,32,32,255); 8 | } 9 | 10 | Entity_2D::Entity_2D(){} 11 | 12 | Entity_2D::~Entity_2D(void){ 13 | } 14 | 15 | void Entity_2D::move(Vec2 value){ 16 | this->position += value; 17 | } 18 | 19 | void Entity_2D::setPosition(Vec2 position){ 20 | this->position = position; 21 | } 22 | 23 | void Entity_2D::setSize(Vec2 size){ 24 | this->size = size; 25 | } 26 | 27 | void Entity_2D::drawBackground(){ 28 | glColor4ub(backColor.getRed(),backColor.getGreen(),backColor.getBlue(),backColor.getAlpha()); 29 | glBegin(GL_QUADS); 30 | glVertex3f(position.x, position.y, -64.0f); 31 | glVertex3f(position.x + size.x, position.y, -64.0f); 32 | glVertex3f(position.x + size.x, position.y + size.y, -64.0f); 33 | glVertex3f(position.x, position.y + size.y, -64.0f); 34 | 35 | 36 | 37 | glEnd(); 38 | } 39 | 40 | bool Entity_2D::mouseIntersect(){ 41 | Vec2 m = Screen::getMousePosition(); 42 | return (m.x > position.x) && (m.x < (position.x + size.x)) 43 | && (m.y > position.y) && (m.y < (position.y + size.y)); 44 | } 45 | 46 | void Entity_2D::setBackColor(Color color){ 47 | backColor = color; 48 | } 49 | 50 | Vec2 Entity_2D::getPosition(){ 51 | return position; 52 | } 53 | 54 | Vec2 Entity_2D::getSize(){ 55 | return size; 56 | } -------------------------------------------------------------------------------- /FoxelEngine/GlobalLight.cpp: -------------------------------------------------------------------------------- 1 | #include "GlobalLight.h" 2 | 3 | GlobalLight::GlobalLight(void){ 4 | } 5 | 6 | 7 | GlobalLight::~GlobalLight(void) 8 | { 9 | } 10 | 11 | void GlobalLight::load(){ 12 | ambientLight = new GLfloat[4]; 13 | diffuseLight = new GLfloat[4]; 14 | specularLight = new GLfloat[4]; 15 | mat_specular = new GLfloat[4]; 16 | mat_shininess = new GLfloat[4]; 17 | 18 | ambientLight[0] = 0.25f;ambientLight[0] = 0.2f; ambientLight[0] = 0.2f; ambientLight[0] = 0.1f; 19 | diffuseLight[0] = 0.8f;diffuseLight[0] = 0.8f; diffuseLight[0] = 0.8f; diffuseLight[0] = 1.0f; 20 | specularLight[0] = 0.5f;specularLight[0] = 0.5f; specularLight[0] = 0.5f; specularLight[0] = 1.0f; 21 | mat_specular[0] = 0.4f;mat_specular[0] = 0.4f; mat_specular[0] = 0.4f; mat_specular[0] = 0.1f; 22 | mat_shininess[0] = 1.0f; 23 | 24 | 25 | glEnable(GL_COLOR_MATERIAL); 26 | glShadeModel(GL_SMOOTH); 27 | 28 | glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight); 29 | glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight); 30 | glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight); 31 | glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); 32 | glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); 33 | glColorMaterial (GL_FRONT, GL_AMBIENT_AND_DIFFUSE) ; 34 | } 35 | 36 | void GlobalLight::lightAt(Vec3 position){ 37 | GLfloat lightPosition[] = { position.x, position.y, position.z, 0.1f }; 38 | glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); 39 | } 40 | 41 | void GlobalLight::turnOff(){ 42 | glDisable(GL_DEPTH_TEST); 43 | glDisable(GL_LIGHTING); 44 | glDisable(GL_LIGHT0); 45 | } 46 | 47 | void GlobalLight::turnOn(){ 48 | glEnable(GL_DEPTH_TEST); 49 | glEnable(GL_LIGHTING); 50 | glEnable(GL_LIGHT0); 51 | } -------------------------------------------------------------------------------- /FoxelEngine/Screen.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "Vec2.h" 9 | #include "Matrix4.h" 10 | static double M_PI = 3.14159265358979323846; 11 | 12 | 13 | class Screen{ 14 | private: 15 | SDL_Surface* screen; 16 | static int screenWidth, screenHeight; 17 | static Vec2 mousePosition, mouseMotion; 18 | static bool klickLeft,klickRight; 19 | static float ar; 20 | static bool isResized; 21 | 22 | public: 23 | static Matrix4 ProjMatrix; 24 | static Matrix4 ViewMatrix; 25 | Screen(int w, int h, bool isFullscreen); 26 | ~Screen(void); 27 | 28 | void reset(); 29 | void resize(int w, int h); 30 | void catchMousePosition(Vec2 position); 31 | void catchMouseMotion(Vec2 value); 32 | void setKlickLeft(bool boolean); 33 | void setKlickRight(bool boolean); 34 | void swap(); 35 | SDL_Surface* getSurface(); 36 | 37 | static Vec2 getMousePosition(); 38 | static Vec2 getMouseMotion(); 39 | static void buildProjectionMatrix(float fov, float ratio, float nearPlane, float farPlane); 40 | static void buildOrthoMatrix(float left, float right, float top, float bottom, float nearPlane, float farPlane); 41 | static void load2DView(); 42 | static void load3DView(); 43 | static void updateViewMatix(); 44 | static void updateProjMatix(); 45 | 46 | static void hideMouse(); 47 | static void showMouse(); 48 | 49 | static GLfloat* getProjectionMatrix(); 50 | static GLfloat* getViewMatrix(); 51 | 52 | static bool wasResized(); 53 | static float getAspectRatio(); 54 | static bool isKlickLeft(); 55 | static bool isKlickRight(); 56 | static int getWidth(); 57 | static int getHeight(); 58 | }; -------------------------------------------------------------------------------- /FoxelEngine/ToolBox.cpp: -------------------------------------------------------------------------------- 1 | #include "ToolBox.h" 2 | #include "Map.h" 3 | 4 | using namespace MapEditor; 5 | ToolBox::ToolBox(Vec2 position, Vec2 size) : GameMenu(position, size){ 6 | int y = 28; 7 | selectOptions.push_back(TextButton(Vec2(16,(float)Screen::getHeight()-y),Vec2(96,14),"Brush")); y += 28; 8 | selectOptions.push_back(TextButton(Vec2(16,(float)Screen::getHeight()-y),Vec2(96,14),"Entity")); y += 28; 9 | selectOptions.push_back(TextButton(Vec2(16,(float)Screen::getHeight()-y),Vec2(96,14),"Load")); y += 28; 10 | selectOptions.push_back(TextButton(Vec2(16,(float)Screen::getHeight()-y),Vec2(96,14),"Save")); y += 28; 11 | activeTool = Brush; 12 | } 13 | 14 | 15 | ToolBox::~ToolBox(void){ 16 | 17 | } 18 | 19 | void ToolBox::update(){ 20 | GameMenu::update(); 21 | if(selectOptions[0].isPressed()){ activeTool = Brush;} 22 | if(selectOptions[1].isPressed()){ activeTool = Entity;} 23 | if(selectOptions[2].isPressed()){} // TODO Loading a Map 24 | if(selectOptions[3].isPressed()){ Map::save("Untitled");} // TODO Saving under an other name 25 | } 26 | 27 | void ToolBox::draw(){ 28 | glBegin(GL_QUADS); 29 | glColor3f(0.0f,0.0f,0.0f); glVertex2f(position.x, position.y); 30 | glVertex2f(size.x , position.y); 31 | glColor3f(0.5f,0.1f,0.1f); glVertex2f(size.x , size.y ); 32 | glVertex2f(position.x, size.y); 33 | glEnd(); 34 | GameMenu::draw(); 35 | } 36 | 37 | void ToolBox::resize(){ 38 | size.y = (float)Screen::getHeight(); 39 | int y = 28; 40 | for(int i = 0; i < selectOptions.size(); i++){ 41 | selectOptions[i].setPosition(Vec2(16,(float)Screen::getHeight() - y)); 42 | y += 28; 43 | } 44 | } -------------------------------------------------------------------------------- /FoxelEngine/Color.cpp: -------------------------------------------------------------------------------- 1 | #include "Color.h" 2 | 3 | Color::Color(void){ 4 | RGBA[0] = RGBA[1] = RGBA[2] = 200; 5 | RGBA[3] = 255; 6 | } 7 | 8 | Color::Color(unsigned char R, unsigned char G, unsigned char B){ 9 | RGBA[0] = R; 10 | RGBA[1] = G; 11 | RGBA[2] = B; 12 | RGBA[3] = 255; 13 | } 14 | 15 | Color::Color(unsigned char R, unsigned char G, unsigned char B, unsigned char A){ 16 | RGBA[0] = R; 17 | RGBA[1] = G; 18 | RGBA[2] = B; 19 | RGBA[3] = A; 20 | } 21 | 22 | unsigned char* Color::getColorArray(){ 23 | return RGBA; 24 | } 25 | 26 | unsigned char Color::getRed(){ 27 | return RGBA[0]; 28 | } 29 | 30 | unsigned char Color::getGreen(){ 31 | return RGBA[1]; 32 | } 33 | 34 | unsigned char Color::getBlue(){ 35 | return RGBA[2]; 36 | } 37 | 38 | unsigned char Color::getAlpha(){ 39 | return RGBA[3]; 40 | } 41 | 42 | void Color::setColor(unsigned char r, unsigned char g, unsigned char b){ 43 | RGBA[0] = r; 44 | RGBA[1] = g; 45 | RGBA[2] = b; 46 | } 47 | 48 | void Color::setColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a){ 49 | RGBA[0] = r; 50 | RGBA[1] = g; 51 | RGBA[2] = b; 52 | RGBA[3] = a; 53 | } 54 | 55 | void Color::setRed(unsigned char r){ 56 | RGBA[0] = r; 57 | } 58 | 59 | void Color::setGreen(unsigned char g){ 60 | RGBA[1] = g; 61 | } 62 | 63 | void Color::setBlue(unsigned char b){ 64 | RGBA[2] = b; 65 | } 66 | 67 | void Color::setAlpha(unsigned char a){ 68 | RGBA[3] = a; 69 | } 70 | 71 | unsigned char Color::getMaximum(){ 72 | unsigned char max; 73 | if(RGBA[0] > RGBA[1]){ 74 | max = RGBA[0]; 75 | }else{ 76 | max = RGBA[1]; 77 | } 78 | if(max < RGBA[2]){ 79 | max = RGBA[2]; 80 | } 81 | return max; 82 | } 83 | 84 | short Color::getLuminate(){ 85 | return RGBA[0] + RGBA[1] + RGBA[2]; 86 | } -------------------------------------------------------------------------------- /FoxelEngine/Controler.cpp: -------------------------------------------------------------------------------- 1 | #include "Controler.h" 2 | #include "Screen.h" 3 | 4 | using namespace MapEditor; 5 | Controler::Controler(void){ 6 | rightMouseButton = leftMouseButton = midleMouseButton = false; 7 | wheelState = 0; 8 | A = S = D = W = Shift = Tab = Grab = false; 9 | } 10 | 11 | 12 | Controler::~Controler(void) 13 | { 14 | } 15 | 16 | void Controler::catchKeyDown(SDLKey sym){ 17 | switch(sym){ 18 | case SDLK_a: A = true; break; 19 | case SDLK_d: D = true; break; 20 | case SDLK_w: W = true; break; 21 | case SDLK_s: S = true; break; 22 | case SDLK_TAB: Tab = true; break; 23 | case SDLK_LSHIFT: Shift = true; break; 24 | 25 | case SDLK_f: 26 | if(Grab){ 27 | Grab = false; 28 | Screen::showMouse(); 29 | } 30 | else{ 31 | Grab = true; 32 | } 33 | break; 34 | } 35 | } 36 | 37 | void Controler::catchKeyUp(SDLKey sym){ 38 | switch(sym){ 39 | case SDLK_a: A = false; break; 40 | case SDLK_d: D = false; break; 41 | case SDLK_w: W = false; break; 42 | case SDLK_s: S = false; break; 43 | case SDLK_TAB: Tab = false; break; 44 | case SDLK_LSHIFT: Shift = false; break; 45 | } 46 | } 47 | 48 | void Controler::catchMouseClick(Uint8 button){ 49 | switch(button){ 50 | case SDL_BUTTON_LEFT: leftMouseButton = true; break; 51 | case SDL_BUTTON_MIDDLE: midleMouseButton = true; break; 52 | case SDL_BUTTON_RIGHT: rightMouseButton = true; break; 53 | 54 | case SDL_BUTTON_WHEELDOWN: wheelState--; break; 55 | case SDL_BUTTON_WHEELUP: wheelState++; break; 56 | } 57 | } 58 | 59 | void Controler::catchMouseRelease(Uint8 button){ 60 | switch(button){ 61 | case SDL_BUTTON_LEFT: leftMouseButton = false; break; 62 | case SDL_BUTTON_MIDDLE: midleMouseButton = false; break; 63 | case SDL_BUTTON_RIGHT: rightMouseButton = false; break; 64 | } 65 | } -------------------------------------------------------------------------------- /FoxelEngine/SlideControl.cpp: -------------------------------------------------------------------------------- 1 | #include "SlideControl.h" 2 | #include "Screen.h" 3 | 4 | SlideControl::SlideControl(Vec2 position, Vec2 size, std::string prefix) : Entity_2D(position, size){ 5 | value = 0.5f; 6 | buffValue = 0.0f; 7 | this->prefix = prefix; 8 | backColor.setColor(128,128,128,255); 9 | text = new TextField(position + 3,size,prefix+"0.5"); 10 | text->setWithBox(false); 11 | text->setBigText(false); 12 | } 13 | 14 | void SlideControl::changeValue(float nValue){ 15 | if(nValue < 0.0f){ 16 | buffValue -= 0.010f ; 17 | }else{ 18 | buffValue += 0.010f ; 19 | } 20 | 21 | if(buffValue <= -0.025f){ 22 | value -= 0.025f; 23 | buffValue = 0.0f; 24 | } 25 | if(buffValue >= 0.025f){ 26 | value += 0.025f; 27 | buffValue = 0.0f; 28 | } 29 | 30 | if(value < 0.025f) value = 0.0f; 31 | if(value > 0.975f) value = 1.0f; 32 | 33 | setText(); 34 | } 35 | 36 | void SlideControl::setValue(float nValue){ 37 | if(nValue < 0.0f) nValue = 0.0f; 38 | if(nValue > 1.0f) nValue = 1.0f; 39 | this->value = nValue; 40 | setText(); 41 | } 42 | 43 | void SlideControl::setText(){ 44 | std::stringstream ss; 45 | ss << prefix << value; 46 | text->setContent(0,ss.str()); 47 | } 48 | 49 | float SlideControl::getValue(){ 50 | return value; 51 | } 52 | 53 | void SlideControl::draw(){ 54 | drawBackground(); 55 | 56 | glColor3f(0.8f,0.2f,0.2f); 57 | glBegin(GL_QUADS); 58 | glVertex3f(position.x+2, position.y+1, -63.0f); 59 | glVertex3f(position.x-2 + size.x * value, position.y+1, -63.0f); 60 | glVertex3f(position.x-2 + size.x * value, position.y + size.y-2, -63.0f); 61 | glVertex3f(position.x+2, position.y + size.y-2, -63.0f); 62 | 63 | glEnd(); 64 | 65 | text->draw(); 66 | 67 | } 68 | 69 | void SlideControl::setPosition(Vec2 position){ 70 | Entity_2D::setPosition(position); 71 | text->setPosition(position+3); 72 | } -------------------------------------------------------------------------------- /FoxelEngine/Main_Menu.cpp: -------------------------------------------------------------------------------- 1 | #include "Main_Menu.h" 2 | #include 3 | 4 | Main_Menu::Main_Menu(void){ 5 | position.x = 60-8; 6 | position.y = 60-8; 7 | size.x = 256 -60+8; 8 | size.y = 256+26; 9 | selectOptions.push_back(TextButton(Vec2(64,256),Vec2(128,14),"Play")); 10 | selectOptions.push_back(TextButton(Vec2(64,192),Vec2(128,14),"Level Editor")); 11 | selectOptions.push_back(TextButton(Vec2(64,128),Vec2(128,14),"Options")); 12 | selectOptions.push_back(TextButton(Vec2(64,64),Vec2(128,14),"Exit")); 13 | } 14 | 15 | Main_Menu::~Main_Menu(void){ 16 | 17 | } 18 | 19 | void Main_Menu::draw(){ 20 | 21 | glEnable(GL_BLEND); 22 | glDisable(GL_DEPTH_TEST); 23 | 24 | glLoadIdentity(); 25 | glMatrixMode(GL_PROJECTION); 26 | glLoadIdentity(); 27 | glOrtho(0, Screen::getWidth(), 0, Screen::getHeight(), -128, 128); 28 | 29 | glColor3f(0.1f,0.1f,0.1f); 30 | glBegin(GL_QUADS); 31 | glVertex2f(position.x, position.y); 32 | glVertex2f(size.x , position.y); 33 | glVertex2f(size.x , size.y ); 34 | glVertex2f(position.x, size.y); 35 | glEnd(); 36 | 37 | glBegin(GL_QUADS); 38 | glVertex2f(position.x , 282 ); 39 | glVertex2f(position.x-16 , 264 ); 40 | glVertex2f(position.x-16 , position.y+16); 41 | glVertex2f(position.x, position.y); 42 | glEnd(); 43 | 44 | glBegin(GL_QUADS); 45 | glVertex2f(size.x, size.y-112 ); 46 | glVertex2f(size.x+16 , size.y-48-48 ); 47 | glVertex2f(size.x+16 , size.y-16); 48 | glVertex2f(size.x, size.y); 49 | glEnd(); 50 | 51 | GameMenu::draw(); 52 | } 53 | 54 | void Main_Menu::createEvents(){ 55 | if(selectOptions[0].isPressed()){ 56 | new Event::BasicEvent(Event::PLAYMODE); 57 | selectOptions[0].release(); 58 | } 59 | if(selectOptions[1].isPressed()){ 60 | new Event::BasicEvent(Event::EDITMODE); 61 | } 62 | if(selectOptions[3].isPressed()){ 63 | new Event::BasicEvent(Event::EXIT); 64 | selectOptions[3].release(); 65 | } 66 | } -------------------------------------------------------------------------------- /FoxelEngine/Config.cpp: -------------------------------------------------------------------------------- 1 | #include "Config.h" 2 | #include 3 | using namespace std; 4 | 5 | DisplayMode Config::displayMode = DISPLAY_NORMAL; 6 | bool Config::debug = true; 7 | int Config::chunkThreads = 1; 8 | 9 | Config::Config(void){ 10 | 11 | screenW = 1280; 12 | screenH = 720; 13 | fullscreen = true; 14 | } 15 | 16 | void Config::readConfig(string fileName){ 17 | ifstream file; 18 | file.open(fileName); 19 | if(file.is_open()){ 20 | string tmp; 21 | while(!file.eof()){ 22 | file >> tmp; 23 | configContent.push_back(tmp); 24 | } 25 | }else{ 26 | cout << "No config found, use default settings" << endl; 27 | screenW = GetSystemMetrics(SM_CXSCREEN); // Windows screen X Information 28 | screenH = GetSystemMetrics(SM_CYSCREEN); // Windows screen Y Information 29 | 30 | return; 31 | } 32 | for(unsigned int i = 0; i < configContent.size(); i++){ 33 | if(configContent[i] == "Fullscreen"){ 34 | if(configContent[i+1] == "false"){ 35 | fullscreen = false; 36 | } 37 | } 38 | if(configContent[i] == "Width"){ 39 | stringstream ss; 40 | ss << configContent[i+1]; 41 | ss >> screenW; 42 | } 43 | if(configContent[i] == "Height"){ 44 | stringstream ss; 45 | ss << configContent[i+1]; 46 | ss >> screenH; 47 | } 48 | if(configContent[i] == "ChunkThreads"){ 49 | stringstream ss; 50 | ss << configContent[i+1]; 51 | ss >> chunkThreads; 52 | } 53 | } 54 | } 55 | 56 | void Config::switchDebugMode(){ 57 | if(debug) debug = false; 58 | else debug = true; 59 | } 60 | 61 | void Config::setDisplayMode(DisplayMode mode){ 62 | displayMode = mode; 63 | } 64 | 65 | int Config::getScreenW(){ 66 | return screenW; 67 | } 68 | int Config::getScreenH(){ 69 | return screenH; 70 | } 71 | bool Config::isFullscreen(){ 72 | return fullscreen; 73 | } 74 | bool Config::isDebug(){ 75 | return debug; 76 | } 77 | DisplayMode Config::getDisplayMode(){ 78 | return displayMode; 79 | } 80 | int Config::getChunkThreads(){ 81 | return chunkThreads; 82 | } -------------------------------------------------------------------------------- /FoxelEngine/PlayerControler.cpp: -------------------------------------------------------------------------------- 1 | #include "PlayerControler.h" 2 | #include "Player.h" 3 | #include 4 | 5 | PlayerControler::PlayerControler(int controleMode){ 6 | this->controleMode = controleMode; 7 | left = right = false; 8 | forward = backward = false; 9 | sprint = false; 10 | setFoxel = false; 11 | shoot = false; 12 | zoom = false; 13 | nlod = 1; 14 | wheelState = 0; 15 | midleMouseButton = false; 16 | } 17 | 18 | void PlayerControler::getKeyDown(SDLKey sym){ 19 | switch(sym){ 20 | case SDLK_a: left = true; break; 21 | case SDLK_d: right = true; break; 22 | case SDLK_w: forward = true; break; 23 | case SDLK_s: backward = true; break; 24 | case SDLK_LSHIFT: sprint = true; break; 25 | case SDLK_e: setFoxel = true; break; 26 | } 27 | } 28 | 29 | void PlayerControler::getKeyUp(SDLKey sym){ 30 | switch(sym){ 31 | case SDLK_a: left = false; break; 32 | case SDLK_d: right = false; break; 33 | case SDLK_w: forward = false; break; 34 | case SDLK_s: backward = false; break; 35 | case SDLK_LSHIFT: sprint = false; break; 36 | case SDLK_e: setFoxel = false; break; 37 | } 38 | } 39 | 40 | void PlayerControler::catchMouseClick(Uint8 button){ 41 | switch(button){ 42 | case SDL_BUTTON_LEFT: shoot = true; break; 43 | case SDL_BUTTON_MIDDLE: midleMouseButton = true; break; 44 | case SDL_BUTTON_RIGHT: zoom = true; break; 45 | 46 | case SDL_BUTTON_WHEELDOWN: 47 | wheelState--; 48 | if(nlod > 1){ 49 | nlod /= 2; 50 | FoxelManager::setGlobalLod(nlod); 51 | } 52 | break; 53 | case SDL_BUTTON_WHEELUP: 54 | wheelState++; 55 | if(nlod < 8){ 56 | nlod *= 2; 57 | FoxelManager::setGlobalLod(nlod); 58 | } 59 | break; 60 | } 61 | } 62 | 63 | void PlayerControler::catchMouseRelease(Uint8 button){ 64 | switch(button){ 65 | case SDL_BUTTON_LEFT: shoot = false; break; 66 | case SDL_BUTTON_MIDDLE: midleMouseButton = false; break; 67 | case SDL_BUTTON_RIGHT: zoom = false; break; 68 | } 69 | } 70 | 71 | 72 | PlayerControler::~PlayerControler(void) 73 | { 74 | } 75 | -------------------------------------------------------------------------------- /FoxelEngine/Maps/Test_Map2.foxel: -------------------------------------------------------------------------------- 1 | C 5 2 1 2 | B 0 0 0 127 127 15 1 255 255 255 0 3 | B 40 48 16 71 79 31 1 255 0 76 0 4 | B 40 48 32 71 79 47 1 255 0 76 0 5 | 6 | C 5 1 1 7 | B 0 0 0 127 127 15 1 255 255 255 0 8 | B 16 88 16 31 103 79 1 70 114 140 0 9 | B 16 24 16 31 39 79 1 70 114 140 0 10 | B 80 24 16 95 39 79 1 70 114 140 0 11 | B 80 88 16 95 103 79 1 70 114 140 0 12 | B 32 88 56 79 103 71 1 70 114 140 0 13 | B 32 88 48 79 103 63 0 70 114 140 0 14 | B 80 40 56 95 87 71 1 70 114 140 0 15 | B 16 40 56 31 87 71 1 70 114 140 0 16 | B 16 40 48 31 87 63 0 70 114 140 0 17 | B 80 40 48 95 87 63 0 70 114 140 0 18 | B 32 24 56 79 39 71 1 70 114 140 0 19 | B 32 24 48 79 39 63 0 70 114 140 0 20 | B 8 40 56 23 87 71 0 70 114 140 0 21 | B 32 96 56 79 111 71 0 70 114 140 0 22 | B 88 40 56 103 87 71 0 70 114 140 0 23 | B 32 16 56 79 31 71 0 70 114 140 0 24 | 25 | C 4 2 1 26 | B 0 0 0 127 127 15 1 255 255 255 0 27 | B 8 104 16 119 119 31 1 223 172 70 0 28 | 29 | C 4 1 1 30 | B 0 0 0 127 127 15 1 255 255 255 0 31 | B 24 56 16 55 71 63 1 255 191 0 0 32 | B 32 56 40 47 71 55 0 255 191 0 0 33 | B 32 56 24 47 71 39 0 255 191 0 0 34 | 35 | C 3 2 1 36 | B 0 0 0 127 127 15 1 255 255 255 0 37 | B 88 24 16 119 55 31 1 140 255 0 0 38 | B 88 24 32 119 55 47 1 140 255 0 0 39 | 40 | C 3 1 1 41 | B 0 0 0 127 127 15 1 255 255 255 0 42 | B 64 72 16 95 103 31 1 6 127 255 0 43 | B 64 72 32 95 103 47 1 6 127 255 0 44 | B 64 72 32 95 103 47 1 6 127 255 0 45 | 46 | C 5 3 1 47 | B 0 0 0 127 15 127 1 255 255 255 0 48 | 49 | C 4 3 1 50 | B 0 0 0 127 15 127 1 255 255 255 0 51 | 52 | C 3 3 1 53 | B 0 0 0 127 15 127 1 255 255 255 0 54 | 55 | C 2 3 1 56 | B 112 0 0 127 15 127 1 255 255 255 0 57 | 58 | C 2 2 1 59 | B 112 0 0 127 127 127 1 255 255 255 0 60 | 61 | C 2 1 1 62 | B 112 0 0 127 127 127 1 255 255 255 0 63 | 64 | C 5 0 1 65 | B 0 112 0 127 127 127 1 255 255 255 0 66 | 67 | C 4 0 1 68 | B 0 112 0 127 127 127 1 255 255 255 0 69 | 70 | C 3 0 1 71 | B 0 112 0 127 127 127 1 255 255 255 0 72 | 73 | C 2 0 1 74 | B 112 112 0 127 127 127 1 255 255 255 0 75 | 76 | -------------------------------------------------------------------------------- /FoxelEngine/Models/pistol.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'pistole.blend' 2 | # Material Count: 6 3 | newmtl black_metal_District9SquirtgunSingle.jpg 4 | Ns 96.078431 5 | Ka 0.000000 0.000000 0.000000 6 | Kd 0.048573 0.048573 0.048573 7 | Ks 0.500000 0.500000 0.500000 8 | Ni 1.000000 9 | d 1.000000 10 | illum 2 11 | map_Kd F:\Dropbox\Coding\pistole.blend\District9SquirtgunSingle.jpg 12 | 13 | 14 | newmtl farbe_District9SquirtgunSingle.jpg 15 | Ns 37.254902 16 | Ka 0.000000 0.000000 0.000000 17 | Kd 0.578444 0.062550 0.010962 18 | Ks 0.200000 0.149739 0.093433 19 | Ni 1.000000 20 | d 1.000000 21 | illum 2 22 | map_Kd F:\Dropbox\Coding\pistole.blend\District9SquirtgunSingle.jpg 23 | map_Ns F:\\Dropbox\\3D Art\\Texturen\\MetalBare0005_L.png 24 | map_Ks F:\\Dropbox\\3D Art\\Texturen\\MetalBare0005_L.png 25 | map_Bump F:\\Dropbox\\3D Art\\Texturen\\MetalBare0005_L.png 26 | 27 | 28 | newmtl messing_District9SquirtgunSingle.jpg 29 | Ns 96.078431 30 | Ka 0.000000 0.000000 0.000000 31 | Kd 0.614521 0.351726 0.134616 32 | Ks 0.500000 0.500000 0.500000 33 | Ni 1.000000 34 | d 1.000000 35 | illum 2 36 | map_Kd F:\Dropbox\Coding\pistole.blend\District9SquirtgunSingle.jpg 37 | 38 | 39 | newmtl metall_District9SquirtgunSingle.jpg 40 | Ns 96.078431 41 | Ka 0.000000 0.000000 0.000000 42 | Kd 0.640000 0.640000 0.640000 43 | Ks 0.000000 0.000000 0.000000 44 | Ni 1.000000 45 | d 0.516129 46 | illum 1 47 | map_Kd F:\Dropbox\Coding\pistole.blend\District9SquirtgunSingle.jpg 48 | map_Ks F:\\Dropbox\\3D Art\\Texturen\\MetalBare0005_L.png 49 | map_Bump F:\\Dropbox\\3D Art\\Texturen\\MetalBare0005_L.png 50 | 51 | 52 | newmtl metall_shiny_District9SquirtgunSingle.jpg 53 | Ns 96.078431 54 | Ka 0.000000 0.000000 0.000000 55 | Kd 0.190655 0.191637 0.174496 56 | Ks 0.000000 0.000000 0.000000 57 | Ni 1.000000 58 | d 0.516129 59 | illum 1 60 | map_Kd F:\Dropbox\Coding\pistole.blend\District9SquirtgunSingle.jpg 61 | 62 | 63 | newmtl plast_District9SquirtgunSingle.jpg 64 | Ns 29.411765 65 | Ka 0.000000 0.000000 0.000000 66 | Kd 0.025000 0.025000 0.025000 67 | Ks 0.200000 0.191891 0.160357 68 | Ni 1.000000 69 | d 1.000000 70 | illum 2 71 | map_Kd F:\Dropbox\Coding\pistole.blend\District9SquirtgunSingle.jpg 72 | map_Bump F:\\Dropbox\\3D Art\\Texturen\\Metall_verzinkt.jpg 73 | 74 | 75 | -------------------------------------------------------------------------------- /FoxelEngine/TextField.cpp: -------------------------------------------------------------------------------- 1 | #include "TextField.h" 2 | 3 | 4 | TextField::TextField(Vec2 position, Vec2 size, std::string content) : Entity_2D(position, size){ 5 | linesOfContent.push_back(content); 6 | textColor[0] = 1; textColor[1] = 1; textColor[2] = 1; 7 | withBox = true; 8 | bigText = true; 9 | boxPadding = 4; 10 | } 11 | 12 | TextField::TextField(Vec2 position, Vec2 size){ 13 | textColor[0] = 1; textColor[1] = 1; textColor[2] = 1; 14 | withBox = true; 15 | bigText = true; 16 | boxPadding = 4; 17 | } 18 | 19 | 20 | void TextField::setContent(int line, std::string newContent){ 21 | linesOfContent[line] = newContent; 22 | linesOfContent[line].setBigText(bigText); 23 | } 24 | 25 | void TextField::newLine(std::string newContent){ 26 | linesOfContent.push_back(newContent); 27 | } 28 | 29 | 30 | void TextField::draw(){ 31 | glEnable(GL_BLEND); 32 | glColor3f(0.1f,0.1f,0.1f); 33 | if(withBox){ 34 | glBegin(GL_QUADS); 35 | glVertex2d(position.x - boxPadding, position.y - boxPadding); 36 | glVertex2d(position.x + size.x + boxPadding, position.y - boxPadding); 37 | glVertex2d(position.x + size.x + boxPadding, position.y + size.y + boxPadding); 38 | glVertex2d(position.x - boxPadding, position.y + size.y + boxPadding); 39 | glEnd(); 40 | } 41 | 42 | glColor3f(textColor[0], textColor[1], textColor[2]); 43 | glTranslated(position.x, position.y, 1); 44 | 45 | glDisable(GL_BLEND); 46 | for(unsigned int i = 0; i < linesOfContent.size(); i++){ 47 | glRasterPos2f(0,(float) -20*i); 48 | linesOfContent[i].draw(); 49 | } 50 | 51 | glTranslated(-position.x, -position.y, -1); 52 | 53 | } 54 | 55 | Vec2 TextField::getPosition(){ 56 | return position; 57 | } 58 | 59 | void TextField::setWithBox(bool boolean){ 60 | withBox = boolean; 61 | } 62 | 63 | void TextField::setTextColor(float r, float g, float b){ 64 | textColor[0] = r; 65 | textColor[1] = g; 66 | textColor[2] = b; 67 | } 68 | 69 | void TextField::setBigText(bool boolean){ 70 | bigText = boolean; 71 | for(unsigned int i = 0; i < linesOfContent.size(); i++){ 72 | linesOfContent[i].setBigText(boolean); 73 | } 74 | } 75 | 76 | TextField::~TextField(void){ 77 | 78 | } 79 | -------------------------------------------------------------------------------- /FoxelEngine/Vec3d.cpp: -------------------------------------------------------------------------------- 1 | #include "Vec3d.h" 2 | #include 3 | 4 | Vec3d::Vec3d(void) : Vec2d(){ 5 | z = 0; 6 | } 7 | 8 | Vec3d::Vec3d(double x,double y,double z) : Vec2d(x,y){ 9 | Vec3d::z = z; 10 | } 11 | 12 | double Vec3d::length(){ 13 | return (float) sqrt((x * x) + (y * y) + (z * z)); 14 | } 15 | 16 | void Vec3d::normalize(){ 17 | double num = 1.0f / length(); 18 | x *= num; 19 | y *= num; 20 | z *= num; 21 | } 22 | 23 | double Vec3d::dot(Vec3d left, Vec3d right) 24 | { 25 | return (((left.x * right.x) + (left.y * right.y)) + (left.z * right.z)); 26 | } 27 | 28 | void Vec3d::operator+=(double skalar){ 29 | Vec3d::x += skalar; 30 | Vec3d::y += skalar; 31 | Vec3d::z += skalar; 32 | } 33 | 34 | void Vec3d::operator+=(Vec3d vector){ 35 | Vec3d::x += vector.x; 36 | Vec3d::y += vector.y; 37 | Vec3d::z += vector.z; 38 | } 39 | 40 | void Vec3d::operator-=(double skalar){ 41 | Vec3d::x -= skalar; 42 | Vec3d::y -= skalar; 43 | Vec3d::z -= skalar; 44 | } 45 | 46 | void Vec3d::operator-=(Vec3d vector){ 47 | Vec3d::x -= vector.x; 48 | Vec3d::y -= vector.y; 49 | Vec3d::z -= vector.z; 50 | } 51 | 52 | Vec3d Vec3d::operator*(double skalar){ 53 | Vec3d tmp = *this; 54 | tmp.x *= skalar; 55 | tmp.y *= skalar; 56 | tmp.z *= skalar; 57 | return tmp; 58 | } 59 | 60 | Vec3d Vec3d::operator*(Vec3d vector){ 61 | Vec3d tmp = *this; 62 | tmp.x *= vector.x; 63 | tmp.y *= vector.y; 64 | tmp.z *= vector.z; 65 | return tmp; 66 | } 67 | 68 | Vec3d Vec3d::operator-(){ 69 | Vec3d tmp = *this; 70 | tmp.x *= -1; 71 | tmp.y *= -1; 72 | tmp.z *= -1; 73 | return tmp; 74 | } 75 | 76 | Vec3d Vec3d::operator-(Vec3d vector){ 77 | Vec3d tmp = *this; 78 | tmp.x -= vector.x; 79 | tmp.y -= vector.y; 80 | tmp.z -= vector.z; 81 | return tmp; 82 | } 83 | 84 | Vec3d Vec3d::operator+(Vec3d vector){ 85 | Vec3d tmp = *this; 86 | tmp.x += vector.x; 87 | tmp.y += vector.y; 88 | tmp.z += vector.z; 89 | return tmp; 90 | } 91 | 92 | bool Vec3d::operator!=(Vec3d vector){ 93 | const float t = 0.5f; 94 | if(x > vector.x - t && x < vector.x + t 95 | && y > vector.y - t && y < vector.y + t 96 | && z > vector.z - t && z < vector.z + t){ 97 | return false; 98 | } 99 | return true; 100 | } 101 | 102 | Vec3d::~Vec3d(void) 103 | { 104 | } 105 | -------------------------------------------------------------------------------- /FoxelEngine/GameGUI.cpp: -------------------------------------------------------------------------------- 1 | #include "GameGUI.h" 2 | #include "ShaderProgram.h" 3 | #include "Screen.h" 4 | 5 | using namespace GLSL; 6 | 7 | GameGUI::GameGUI(void){ 8 | debug = true; 9 | debugInformations = new TextField(Vec2(8,(float)Screen::getHeight()-22), Vec2(0,0)); 10 | debugInformations->newLine("Polycount: "); 11 | debugInformations->newLine("Chunk-Updates: "); 12 | debugInformations->newLine("GPU-Uploads: "); 13 | debugInformations->newLine("Direct-Lights: "); 14 | debugInformations->newLine("Bounce-Lights: "); 15 | } 16 | 17 | 18 | GameGUI::~GameGUI(void){ 19 | delete debugInformations; 20 | } 21 | 22 | void GameGUI::update(){ 23 | 24 | debugInformations->setPosition(Vec2(8,(float)Screen::getHeight()-22)); 25 | 26 | debugInformations->setContent(0,debug_PolycountInformation); 27 | debugInformations->setContent(1,debug_ChunkInformations); 28 | debugInformations->setContent(2,debug_GPU_Uploads); 29 | debugInformations->setContent(3,debug_DirectLights); 30 | debugInformations->setContent(4,debug_BounceLights); 31 | 32 | } 33 | 34 | void GameGUI::draw(){ 35 | int cx = Screen::getWidth()/2; 36 | int cy = Screen::getHeight()/2; 37 | 38 | glColor3f(1.0f,0,0); 39 | glBegin(GL_LINES); 40 | { 41 | glVertex3f(cx-7,cy,-16); 42 | glVertex3f(cx-2,cy,-16); 43 | 44 | glVertex3f(cx+2,cy,-16); 45 | glVertex3f(cx+7,cy,-16); 46 | 47 | glVertex3f(cx,cy-7,-16); 48 | glVertex3f(cx,cy-2,-16); 49 | 50 | glVertex3f(cx,cy+2,-16); 51 | glVertex3f(cx,cy+7,-16); 52 | } 53 | glEnd(); 54 | PM::useProg(PROGRAM_NULL); 55 | debugInformations->draw(); 56 | } 57 | 58 | void GameGUI::setDebugChunkInformation(int value){ 59 | std::stringstream ss; 60 | ss << "Chunk-Updates: " << value; 61 | debug_ChunkInformations = ss.str(); 62 | } 63 | 64 | void GameGUI::setDebugPolycountInformation(long value){ 65 | std::stringstream ss; 66 | ss << "Polycount: " << value; 67 | debug_PolycountInformation = ss.str(); 68 | } 69 | 70 | void GameGUI::setDebugGpuUploads(int value){ 71 | std::stringstream ss; 72 | ss << "GPU-Uploads: " << value; 73 | debug_GPU_Uploads = ss.str(); 74 | } 75 | 76 | void GameGUI::setDebugDirectLightsCount(int value){ 77 | std::stringstream ss; 78 | ss << "Direct-Lights: " << value; 79 | debug_DirectLights = ss.str(); 80 | } 81 | 82 | void GameGUI::setDebugBounceLightsCount(int value){ 83 | std::stringstream ss; 84 | ss << "Bounce-Lights: " << value; 85 | debug_BounceLights = ss.str(); 86 | } -------------------------------------------------------------------------------- /FoxelEngine/Vec2.cpp: -------------------------------------------------------------------------------- 1 | #include "Vec2.h" 2 | #include 3 | 4 | const double PI = 3.141592653589; 5 | 6 | Vec2::Vec2(void){ 7 | x = 0; 8 | y = 0; 9 | } 10 | 11 | Vec2::Vec2(float x,float y){ 12 | Vec2::x = x; 13 | Vec2::y = y; 14 | } 15 | 16 | void Vec2::operator+=(float skalar){ 17 | Vec2::x += skalar; 18 | Vec2::y += skalar; 19 | } 20 | 21 | void Vec2::operator+=(Vec2 vector){ 22 | Vec2::x += vector.x; 23 | Vec2::y += vector.y; 24 | } 25 | 26 | void Vec2::operator-=(float skalar){ 27 | Vec2::x -= skalar; 28 | Vec2::y -= skalar; 29 | } 30 | 31 | void Vec2::operator-=(Vec2 vector){ 32 | Vec2::x -= vector.x; 33 | Vec2::y -= vector.y; 34 | } 35 | 36 | Vec2 Vec2::operator*(float skalar){ 37 | Vec2 tmp = *this; 38 | tmp.x *= skalar; 39 | tmp.y *= skalar; 40 | return tmp; 41 | } 42 | 43 | Vec2 Vec2::operator*(Vec2 vector){ 44 | Vec2 tmp = *this; 45 | tmp.x *= vector.x; 46 | tmp.y *= vector.y; 47 | return tmp; 48 | } 49 | 50 | Vec2 Vec2::operator+(float skalar){ 51 | Vec2 tmp = *this; 52 | tmp.x += skalar; 53 | tmp.y += skalar; 54 | return tmp; 55 | } 56 | 57 | Vec2 Vec2::operator+(Vec2 vector){ 58 | Vec2 tmp = *this; 59 | tmp.x += vector.x; 60 | tmp.y += vector.y; 61 | return tmp; 62 | } 63 | 64 | Vec2 Vec2::operator-(float skalar){ 65 | Vec2 tmp = *this; 66 | tmp.x -= skalar; 67 | tmp.y -= skalar; 68 | return tmp; 69 | } 70 | 71 | Vec2 Vec2::operator-(Vec2 vector){ 72 | Vec2 tmp = *this; 73 | tmp.x -= vector.x; 74 | tmp.y -= vector.y; 75 | return tmp; 76 | } 77 | 78 | Vec2 Vec2::operator-(){ 79 | Vec2 tmp = *this; 80 | tmp.x *= -1; 81 | tmp.y *= -1; 82 | return tmp; 83 | } 84 | 85 | float Vec2::length(){ 86 | return (float) sqrt((x * x) + (y * y)); 87 | } 88 | 89 | void Vec2::normalize(){ 90 | float num = 1.0f / length(); 91 | x *= num; 92 | y *= num; 93 | } 94 | 95 | float Vec2::dot(Vec2 left, Vec2 right) 96 | { 97 | return (((left.x * right.x) + (left.y * right.y))); 98 | } 99 | 100 | void Vec2::rotate(Vec2 center, double phi){ 101 | double xx,yy,xxx,yyy; 102 | 103 | phi *= (PI / 180); // degToRad 104 | 105 | xx = x - center.x; 106 | yy = y - center.y; 107 | 108 | xxx = xx * cos(phi) + yy * sin(phi); 109 | yyy = -xx * sin(phi) + yy * cos(phi); 110 | 111 | Vec2::x = xxx + center.x; 112 | Vec2::y = yyy + center.y; 113 | } 114 | 115 | Vec2::~Vec2(void) 116 | { 117 | } 118 | -------------------------------------------------------------------------------- /FoxelEngine/GL_Screen.cpp: -------------------------------------------------------------------------------- 1 | #include "GL_Screen.h" 2 | #include 3 | 4 | GL_Screen::GL_Screen(int w, int h, bool isFullscreen) 5 | { 6 | screenWidth = w; 7 | screenHeight = h; 8 | 9 | SDL_WM_SetCaption("Foxel Engine", 0); 10 | SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); 11 | SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); 12 | SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); 13 | SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); 14 | 15 | SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); 16 | SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); 17 | 18 | SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 8); 19 | SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 8); 20 | SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 8); 21 | SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 8); 22 | 23 | SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); 24 | 25 | // Fenster erstellen 26 | if(isFullscreen){ 27 | screen = SDL_SetVideoMode(screenWidth,screenHeight,32,SDL_HWSURFACE | 28 | SDL_GL_DOUBLEBUFFER | SDL_OPENGL | SDL_RESIZABLE | 29 | SDL_FULLSCREEN); 30 | }else{ 31 | screen = SDL_SetVideoMode(screenWidth,screenHeight,32,SDL_HWSURFACE | 32 | SDL_GL_DOUBLEBUFFER | SDL_OPENGL | SDL_RESIZABLE); 33 | } 34 | if(screen == NULL){ 35 | std::cout << SDL_GetError(); 36 | getchar(); 37 | } 38 | 39 | resize(screenWidth,screenHeight); 40 | glEnable(GL_CULL_FACE); 41 | glEnable(GL_BLEND); 42 | glBlendFunc(GL_SRC_ALPHA, GL_ONE); 43 | } 44 | 45 | void GL_Screen::resize(int w, int h){ 46 | screenWidth = w; 47 | screenHeight = h; 48 | 49 | ar =(float) screenWidth / (float) screenHeight; 50 | 51 | SDL_UpdateRect(0,0,0,0,0); 52 | 53 | glClearColor(0.1f, 0.1f, 0.1f, 0.0f); 54 | glViewport(0, 0, screenWidth, screenHeight); 55 | glMatrixMode(GL_PROJECTION); 56 | glEnable(GL_TEXTURE_2D); 57 | } 58 | 59 | void GL_Screen::load3DView(){ 60 | glEnable(GL_BLEND); 61 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 62 | glViewport(0,0,screenWidth,screenHeight); 63 | glLoadIdentity(); 64 | glFrustum(-ar, ar, -1.0, 1.0, 2.0, 16000.0); 65 | glMatrixMode(GL_MODELVIEW); 66 | } 67 | 68 | void GL_Screen::load2DView(){ 69 | glMatrixMode(GL_PROJECTION); 70 | glLoadIdentity(); 71 | glViewport(0, 0, screenWidth, screenHeight); 72 | glOrtho(0, screenWidth, 0, screenHeight , -128, 128); 73 | glMatrixMode(GL_MODELVIEW); 74 | glLoadIdentity(); 75 | } 76 | 77 | SDL_Surface* GL_Screen::getSurface(){ 78 | return screen; 79 | } 80 | 81 | int GL_Screen::getHeight(){ 82 | return screenHeight; 83 | } 84 | 85 | int GL_Screen::getWidth(){ 86 | return screenWidth; 87 | } 88 | 89 | GL_Screen::~GL_Screen(void) 90 | { 91 | } 92 | -------------------------------------------------------------------------------- /FoxelEngine/Vec3.cpp: -------------------------------------------------------------------------------- 1 | #include "Vec3.h" 2 | #include 3 | 4 | Vec3::Vec3(void) : Vec2(){ 5 | z = 0; 6 | } 7 | 8 | Vec3::Vec3(Vec3d vector){ 9 | x = (float)vector.x; 10 | y = (float)vector.y; 11 | z = (float)vector.z; 12 | } 13 | 14 | Vec3::Vec3(float x,float y,float z) : Vec2(x,y){ 15 | Vec3::z = z; 16 | } 17 | 18 | float Vec3::length(){ 19 | return (float) sqrt((x * x) + (y * y) + (z * z)); 20 | } 21 | 22 | void Vec3::normalize(){ 23 | float num = 1.0f / length(); 24 | x *= num; 25 | y *= num; 26 | z *= num; 27 | } 28 | 29 | float Vec3::dot(Vec3 left, Vec3 right) 30 | { 31 | return (((left.x * right.x) + (left.y * right.y)) + (left.z * right.z)); 32 | } 33 | 34 | void Vec3::operator+=(float skalar){ 35 | Vec3::x += skalar; 36 | Vec3::y += skalar; 37 | Vec3::z += skalar; 38 | } 39 | 40 | void Vec3::operator+=(Vec3 vector){ 41 | Vec3::x += vector.x; 42 | Vec3::y += vector.y; 43 | Vec3::z += vector.z; 44 | } 45 | 46 | void Vec3::operator-=(float skalar){ 47 | Vec3::x -= skalar; 48 | Vec3::y -= skalar; 49 | Vec3::z -= skalar; 50 | } 51 | 52 | void Vec3::operator-=(Vec3 vector){ 53 | Vec3::x -= vector.x; 54 | Vec3::y -= vector.y; 55 | Vec3::z -= vector.z; 56 | } 57 | 58 | Vec3 Vec3::operator*(float skalar){ 59 | Vec3 tmp = *this; 60 | tmp.x *= skalar; 61 | tmp.y *= skalar; 62 | tmp.z *= skalar; 63 | return tmp; 64 | } 65 | 66 | Vec3 Vec3::operator*(Vec3 vector){ 67 | Vec3 tmp = *this; 68 | tmp.x *= vector.x; 69 | tmp.y *= vector.y; 70 | tmp.z *= vector.z; 71 | return tmp; 72 | } 73 | 74 | Vec3 Vec3::operator-(){ 75 | Vec3 tmp = *this; 76 | tmp.x *= -1; 77 | tmp.y *= -1; 78 | tmp.z *= -1; 79 | return tmp; 80 | } 81 | 82 | Vec3 Vec3::operator-(Vec3 vector){ 83 | Vec3 tmp = *this; 84 | tmp.x -= vector.x; 85 | tmp.y -= vector.y; 86 | tmp.z -= vector.z; 87 | return tmp; 88 | } 89 | 90 | Vec3 Vec3::operator+(Vec3 vector){ 91 | Vec3 tmp = *this; 92 | tmp.x += vector.x; 93 | tmp.y += vector.y; 94 | tmp.z += vector.z; 95 | return tmp; 96 | } 97 | 98 | bool Vec3::operator!=(Vec3 vector){ 99 | const float t = 0.5f; 100 | if(x > vector.x - t && x < vector.x + t 101 | && y > vector.y - t && y < vector.y + t 102 | && z > vector.z - t && z < vector.z + t){ 103 | return false; 104 | } 105 | return true; 106 | } 107 | 108 | /* 109 | Just use it for normalized vectors! 110 | */ 111 | bool Vec3::isAxisOriented(){ 112 | if(x == 1 || x == -1 || y == 1 || y == -1 || z == 1 || z == -1) return true; 113 | else return false; 114 | } 115 | 116 | Vec3::~Vec3(void) 117 | { 118 | } 119 | -------------------------------------------------------------------------------- /FoxelEngine/ShaderProgram.cpp: -------------------------------------------------------------------------------- 1 | #include "ShaderProgram.h" 2 | #include 3 | 4 | using namespace GLSL; 5 | ProgramTyp ShaderProgram::ActiveProgram; 6 | ShaderProgram::ShaderProgram(ProgramTyp typ){ 7 | programObject = glCreateProgram(); 8 | switch(typ){ 9 | case PROGRAM_BASIC: fragmentShader = new Shader("Shader/Basic.frag"); 10 | vertexSchader = new Shader("Shader/Basic.vert"); 11 | glBindAttribLocation(programObject,0, "in_Position"); 12 | glBindAttribLocation(programObject,1, "in_Color"); 13 | glBindAttribLocation(programObject,2, "in_Normal"); 14 | break; 15 | case PROGRAM_FOXEL: fragmentShader = new Shader("Shader/Foxel.frag"); 16 | vertexSchader = new Shader("Shader/Foxel.vert"); 17 | glBindAttribLocation(programObject,0, "in_Position"); 18 | glBindAttribLocation(programObject,1, "in_Color"); 19 | glBindAttribLocation(programObject,2, "in_Normal"); 20 | break; 21 | case PROGRAM_MODEL: fragmentShader = new Shader("Shader/Model.frag"); 22 | vertexSchader = new Shader("Shader/Model.vert"); 23 | glBindAttribLocation(programObject,0, "in_Position"); 24 | glBindAttribLocation(programObject,1, "in_Color"); 25 | glBindAttribLocation(programObject,2, "in_Normal"); 26 | break; 27 | case PROGRAM_POST: fragmentShader = new Shader("Shader/Post.frag"); 28 | vertexSchader = new Shader("Shader/Post.vert"); 29 | break; 30 | } 31 | if(fragmentShader->allRight() && vertexSchader->allRight()){ 32 | glAttachShader(programObject, fragmentShader->getShaderObject()); 33 | glAttachShader(programObject, vertexSchader->getShaderObject()); 34 | glLinkProgram(programObject); 35 | } 36 | // Get Linker Log 37 | Shader::printShaderLog(programObject); 38 | delete fragmentShader, vertexSchader; 39 | } 40 | 41 | ShaderProgram::~ShaderProgram(void) 42 | { 43 | } 44 | 45 | GLuint ShaderProgram::getProgram(){ 46 | return programObject; 47 | } 48 | 49 | void ShaderProgram::useProg(ProgramTyp typ){ 50 | if(progMap.find(typ) != progMap.end()){ 51 | glUseProgram(progMap[typ]->getProgram()); 52 | ActiveProgram = typ; 53 | }else if(typ == PROGRAM_NULL){ 54 | glUseProgram(NULL); 55 | }else{ 56 | progMap[typ] = new ShaderProgram(typ); 57 | useProg(typ); 58 | } 59 | } 60 | 61 | GLint ShaderProgram::getUnifLoc(ProgramTyp typ, const GLchar *name){ 62 | if(progMap.find(typ) == progMap.end()){ 63 | progMap[typ] = new ShaderProgram(typ); 64 | } 65 | return glGetUniformLocation(progMap[typ]->getProgram(), name); 66 | } 67 | 68 | GLint ShaderProgram::getActiveUnifLoc(const GLchar *name){ 69 | return glGetUniformLocation(progMap[ActiveProgram]->getProgram(), name); 70 | } -------------------------------------------------------------------------------- /FoxelEngine/ColorPanel.cpp: -------------------------------------------------------------------------------- 1 | #include "ColorPanel.h" 2 | 3 | ColorPanel::ColorPanel(Vec2 position, Vec2 size) : Entity_2D(position,size) 4 | { 5 | Vec2 border(6.0f,6.0f); 6 | Vec2 upper(0.0f,0.0f); 7 | float h = size.y/14; 8 | slider_emit = new SlideControl(position + border, Vec2(size.x - border.x*2, h),"E: "); upper.y += h+2; 9 | slider_blue = new SlideControl(position + upper + border, Vec2(size.x - border.x*2, h),"B: ");upper.y += h+2; 10 | slider_green = new SlideControl(position + upper + border, Vec2(size.x - border.x*2, h),"G: "); upper.y += h+2; 11 | slider_red = new SlideControl(position + upper + border, Vec2(size.x - border.x*2, h), "R: "); 12 | slider_emit->setValue(0.0f); 13 | 14 | 15 | } 16 | 17 | 18 | ColorPanel::~ColorPanel(void) 19 | { 20 | delete slider_red; 21 | delete slider_green; 22 | delete slider_blue; 23 | delete slider_emit; 24 | } 25 | 26 | void ColorPanel::draw() 27 | { 28 | drawBackground(); 29 | slider_red->draw(); 30 | slider_green->draw(); 31 | slider_blue->draw(); 32 | slider_emit->draw(); 33 | drawColorCircle(); 34 | } 35 | 36 | float clamp(float value) 37 | { 38 | if(value < 0.0f) value = 0.0f; 39 | if(value > 1.0f) value = 1.0f; 40 | return value; 41 | } 42 | 43 | void ColorPanel::drawColorCircle() 44 | { 45 | Vec2 center = position + Vec2(size.x * 0.5f,size.y - 64.0f); 46 | 47 | //glPolygonMode(GL_FRONT, GL_LINE); 48 | 49 | glTranslatef(center.x, center.y, 0.0); 50 | glColor3ub(color.getRed(),color.getGreen(),color.getBlue()); 51 | glutSolidCube(120); 52 | glTranslatef(-center.x, -center.y, 0.0); 53 | } 54 | 55 | void ColorPanel::resize(Vec2 position) 56 | { 57 | this->position = position; 58 | Vec2 border(6.0f,6.0f); 59 | Vec2 upper(0.0f,0.0f); 60 | float h = size.y/14; 61 | 62 | slider_red->setPosition(position + border);upper.y += h+2; 63 | slider_green->setPosition(position+upper +border);upper.y += h+2; 64 | slider_blue->setPosition(position+upper +border);upper.y += h+2; 65 | slider_emit->setPosition(position+upper +border); 66 | } 67 | 68 | void ColorPanel::mouseInteraction() 69 | { 70 | if(slider_red->mouseIntersect()) slider_red->changeValue(-Screen::getMouseMotion().x); 71 | if(slider_green->mouseIntersect()) slider_green->changeValue(-Screen::getMouseMotion().x); 72 | if(slider_blue->mouseIntersect()) slider_blue->changeValue(-Screen::getMouseMotion().x); 73 | if(slider_emit->mouseIntersect()) slider_emit->changeValue(-Screen::getMouseMotion().x); 74 | color.setColor((unsigned char)(slider_red->getValue()*255.0f), (unsigned char)(slider_green->getValue()*255.0f), (unsigned char)(slider_blue->getValue()*255.0f), (unsigned char)(slider_emit->getValue()*255.0f)); 75 | } 76 | 77 | Color ColorPanel::getColor(){ 78 | return color; 79 | } 80 | -------------------------------------------------------------------------------- /FoxelEngine/Shader/Post.frag: -------------------------------------------------------------------------------- 1 | #version 330 2 | 3 | in vec2 uv; 4 | layout(location = 0) out vec4 color; 5 | //layout(location = 1) out vec3 normal; 6 | 7 | 8 | uniform sampler2D renderedTexture; 9 | uniform sampler2D normalTexture; 10 | uniform sampler2D positionTexture; 11 | uniform sampler2D depthTexture; 12 | uniform sampler1D bounceTexture; 13 | 14 | uniform int displayMode; 15 | uniform int bounceLightCount; 16 | uniform vec2 screen; 17 | 18 | float LinearizeDepth(vec2 uv) 19 | { 20 | float n = 1.0; // camera z near 21 | float f = 2000.0; // camera z far 22 | float z = texture2D(depthTexture, uv).x; 23 | return 1 - ((2.0 * n) / (f + n - z * (f - n))); 24 | } 25 | 26 | 27 | void main(){ 28 | float d = LinearizeDepth(uv); 29 | 30 | if(displayMode == 1){ 31 | if(uv.x < 0.5 && uv.y > 0.5){ 32 | color = texture2D(renderedTexture,uv*2); 33 | }else if(uv.x > 0.5 && uv.y > 0.5){ 34 | color = texture2D(normalTexture,uv*2); 35 | 36 | }else if(uv.x < 0.5 && uv.y < 0.5){ 37 | color = texture2D(positionTexture,uv*2); 38 | }else{ 39 | color = texture2D(renderedTexture,uv*2); 40 | float hsv = max(color.r , color.g ); 41 | hsv = max(hsv,color.b); 42 | 43 | color = vec4(hsv * hsv*6,hsv,hsv/(hsv*6),1.0); 44 | 45 | } 46 | }else if(displayMode == 2){ 47 | color = texture2D(renderedTexture,uv); 48 | }else{ 49 | 50 | vec3 px_color = texture2D(renderedTexture,uv).rgb; 51 | vec3 px_normal = texture2D(normalTexture,uv).rgb*2-1; 52 | vec3 px_position = texture2D(positionTexture,uv).rgb; 53 | vec3 rad_color = vec3(0,0,0); 54 | 55 | float size = bounceLightCount*3; 56 | for(int i = 0; i < size; i+=3){ 57 | vec3 gi_position = texelFetch(bounceTexture,i,0).rgb; 58 | 59 | 60 | 61 | 62 | 63 | 64 | vec3 ray = normalize(gi_position - px_position); 65 | float face = dot(ray,px_normal); 66 | 67 | 68 | if(face > 0){ 69 | float phi = dot(texelFetch(bounceTexture,i+1,0).rgb,ray); 70 | if(phi < 0){ 71 | vec3 gi_color = texelFetch(bounceTexture,i+2,0).rgb; 72 | 73 | float brightnes = 0.0f; 74 | brightnes -= phi /3; 75 | brightnes *= face; 76 | brightnes /= 8 / (gi_color.r + gi_color.g + gi_color.b) * pow(length(gi_position - px_position)*8,2); 77 | 78 | // Todo Material farbe 79 | rad_color += gi_color * brightnes; 80 | //px_color += 100; 81 | } 82 | } 83 | 84 | } 85 | // todo multiply pixel color 86 | px_color += rad_color; 87 | // test 88 | //vec3 test_color = texelFetch(bounceTexture,int(gl_FragCoord.x/4),0).rgb; 89 | //test_color += 1; 90 | //test_color /= 2; 91 | //color = vec4(test_color,1.0); 92 | color = vec4(px_color,1.0); 93 | 94 | 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /FoxelEngine/Core.cpp: -------------------------------------------------------------------------------- 1 | #include "Core.h" 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | using namespace GLSL; 7 | 8 | Core::Core(){ 9 | running = false; 10 | userState = ON_MAIN_MENU; 11 | config = new Config(); 12 | sdlEvent = new SDL_Event(); 13 | player = NULL; 14 | world = NULL; 15 | 16 | debugMode = true; 17 | tickrate = 32; 18 | tick = 0; 19 | } 20 | 21 | bool Core::init(int argc, char *argv[]){ 22 | config->readConfig("config.cfg"); 23 | //world->init(); 24 | 25 | // SDL Initialisieren 26 | if(SDL_Init(SDL_INIT_EVERYTHING) < 0){ 27 | std::cout << "SDL konnte nicht initialisiert werden: " << SDL_GetError() << "\n"; 28 | getchar(); 29 | return false; 30 | }else{ 31 | screen = new Screen(config->getScreenW(),config->getScreenH(), config->isFullscreen()); 32 | // GLEW INIT 33 | GLenum err = glewInit(); 34 | glutInit(&argc,argv); 35 | if (GLEW_OK != err){ 36 | std::cout << "Error: " << glewGetErrorString(err) 37 | << std::endl; 38 | } 39 | cout << "Using GLEW " << glewGetString(GLEW_VERSION) << "\n\n"; 40 | 41 | mainMenu = new Main_Menu(); 42 | Event::BasicEvent::initEventSystem(); 43 | PM::useProg(PROGRAM_BASIC); 44 | PM::useProg(PROGRAM_NULL); 45 | FoxelManager::startChunkThreads(Config::getChunkThreads()); 46 | running = true; 47 | return true; 48 | } 49 | } 50 | 51 | void Core::startGame(){ 52 | userState = ON_GAME; 53 | postPro = new PostProcessor(); 54 | delete world; 55 | delete player; 56 | 57 | player = new Player(PLAYER_FOX); 58 | world = new World(); 59 | 60 | screen->hideMouse(); 61 | 62 | // load data 63 | postPro->load(); 64 | world->load(); 65 | } 66 | 67 | void Core::startEditor(){ 68 | userState = ON_EDIT; 69 | //delete world, player; 70 | editor = new MapEditor::Editor(); 71 | } 72 | 73 | void Core::update(float* time){ 74 | tick += *time; 75 | switch(userState){ 76 | case ON_GAME: 77 | player->update(time); 78 | if(tick > tickrate){ 79 | world->update(); 80 | tick = 0; 81 | } 82 | break; 83 | case ON_GAME_PAUSE: 84 | player->update(time); 85 | mainMenu->update(); 86 | break; 87 | case ON_MAIN_MENU: mainMenu->update(); break; 88 | case ON_EDIT: editor->update(time); break; 89 | } 90 | } 91 | 92 | void Core::render(){ 93 | screen->reset(); 94 | switch(userState){ 95 | //========================================# 96 | case ON_GAME: PM::useProg(PROGRAM_FOXEL); 97 | screen->load3DView(); 98 | postPro->setupToDraw(); 99 | player->render(); 100 | world->render(); 101 | postPro->draw(); 102 | world->drawGui(); 103 | break; 104 | //========================================# 105 | case ON_MAIN_MENU: //PM::useProg(PROGRAM_FOXEL); 106 | screen->load3DView(); 107 | mainMenu->draw(); 108 | break; 109 | 110 | //========================================# 111 | case ON_GAME_PAUSE: PM::useProg(PROGRAM_FOXEL); 112 | screen->load3DView(); 113 | player->render(); 114 | world->render(); 115 | PM::useProg(PROGRAM_NULL); 116 | mainMenu->draw(); 117 | break; 118 | 119 | //========================================# 120 | case ON_EDIT: editor->draw(); 121 | break; 122 | //========================================# 123 | } 124 | screen->swap(); 125 | } 126 | 127 | Core::~Core(void){ 128 | } -------------------------------------------------------------------------------- /FoxelEngine/Pistol.cpp: -------------------------------------------------------------------------------- 1 | #include "Pistol.h" 2 | #include "ShaderProgram.h" 3 | #include "Convert.h" 4 | 5 | 6 | Pistol::Pistol(void) : PropDynamic(){ 7 | model = new Model(); 8 | objMatrix = Matrix4::Identity(); 9 | bulletType = NORMAL; 10 | cooldown = 250; 11 | } 12 | 13 | 14 | void Pistol::load(){ 15 | Screen::ViewMatrix.translate(position); 16 | Screen::updateViewMatix(); 17 | model->load("Models/Pistol.obj"); 18 | Screen::ViewMatrix.translate(position); 19 | } 20 | 21 | void Pistol::update(float* time){ 22 | //PropDynamic::update(time); 23 | rVelocity = (rVelocity * (0.95)); 24 | objMatrix = Matrix4::Identity(); 25 | 26 | if(cooldown > 0) cooldown -= (int)*time; 27 | //objMatrix = objMatrix * Matrix4::CreateFromAxisAngle(Vec3(0,0,1),-rotation.z+90); 28 | //objMatrix = objMatrix * Matrix4::CreateFromAxisAngle(Vec3(0,1,0), rotation.x+90); 29 | //objMatrix.translate(1,4,1); 30 | } 31 | 32 | void Pistol::forceR(Vec3d rForce){ 33 | rVelocity += (rForce*0.05); 34 | } 35 | 36 | void Pistol::draw(){ 37 | //Screen::buildProjectionMatrix(45, Screen::getAspectRatio(), 1.0, 1600.0); 38 | Screen::ViewMatrix = Matrix4::Identity(); 39 | Screen::ViewMatrix.translate(3,-3,-8); 40 | Screen::ViewMatrix.rotate((float)(-90+rVelocity.x), 1.0f, 0.0f, 0.0f); 41 | Screen::ViewMatrix.rotate((float)(90+rVelocity.z), 0.0f, 0.0f, 1.0f); 42 | 43 | GLSL::PM::useProg(GLSL::PROGRAM_MODEL); 44 | glUniform3f(GLSL::PM::getActiveUnifLoc("player_position"),-1.5,1.5,4); 45 | Screen::updateViewMatix(); 46 | //glUniform3f(GLSL::PM::getActiveUnifLoc("player_position"),-position.x,-position.y,-position.z); 47 | glUniformMatrix4fv(GLSL::PM::getActiveUnifLoc("objMatrix"),1,false,objMatrix.matrix); 48 | model->draw(); 49 | } 50 | 51 | void Pistol::shoot(Vec3 position, Vec3 direction){ 52 | if(cooldown <= 0){ 53 | BulletManager::addBullet(new Bullet(position + direction * 16, direction * 1024, bulletType)); 54 | rVelocity.x += 10; 55 | cooldown = 250; 56 | } 57 | } 58 | 59 | void Pistol::shoot2(Vec3 position, Vec3 direction){ 60 | if(cooldown <= 0){ 61 | BulletManager::addBullet(new Bullet(position + direction * 16, direction * 256, bulletType)); 62 | 63 | BulletManager::addBullet(new Bullet(position + Vec3( 1,0, 1) + direction * 16, direction * 196, bulletType)); 64 | BulletManager::addBullet(new Bullet(position + Vec3(-1,0, 1) + direction * 16, direction * 196, bulletType)); 65 | BulletManager::addBullet(new Bullet(position + Vec3( 1,0,-1) + direction * 16, direction * 196, bulletType)); 66 | BulletManager::addBullet(new Bullet(position + Vec3(-1,0,-1) + direction * 16, direction * 196, bulletType)); 67 | 68 | BulletManager::addBullet(new Bullet(position + Vec3( 0,0,-1) + direction * 16, direction * 196, bulletType)); 69 | BulletManager::addBullet(new Bullet(position + Vec3( 0,0, 1) + direction * 16, direction * 196, bulletType)); 70 | BulletManager::addBullet(new Bullet(position + Vec3( 1,0, 0) + direction * 16, direction * 196, bulletType)); 71 | BulletManager::addBullet(new Bullet(position + Vec3(-1,0, 0) + direction * 16, direction * 196, bulletType)); 72 | 73 | BulletManager::addBullet(new Bullet(position + Vec3( 0,0,-2) + direction * 16, direction * 196, bulletType)); 74 | BulletManager::addBullet(new Bullet(position + Vec3( 0,0, 2) + direction * 16, direction * 196, bulletType)); 75 | BulletManager::addBullet(new Bullet(position + Vec3( 2,0, 0) + direction * 16, direction * 196, bulletType)); 76 | BulletManager::addBullet(new Bullet(position + Vec3(-2,0, 0) + direction * 16, direction * 196, bulletType)); 77 | 78 | 79 | rVelocity.x += 1; 80 | cooldown = 10; 81 | } 82 | } 83 | 84 | Pistol::~Pistol(void) 85 | { 86 | } 87 | -------------------------------------------------------------------------------- /FoxelEngine/Maps/Test_Map3.foxel: -------------------------------------------------------------------------------- 1 | C 2 2 1 2 | B 0 0 0 7 7 7 1 204 204 204 0 3 | B 0 0 120 7 7 127 1 204 204 204 0 4 | B 0 0 8 7 7 119 1 0 89 255 0 5 | B 0 0 0 7 7 127 1 204 204 204 0 6 | 7 | C 2 2 0 8 | B 0 0 120 7 7 127 1 204 204 204 0 9 | B 0 0 120 7 7 127 1 204 204 204 0 10 | 11 | C 2 1 1 12 | B 0 0 0 7 127 7 1 204 204 204 0 13 | B 0 0 120 7 127 127 1 204 204 204 0 14 | B 0 0 8 7 127 119 1 0 89 255 0 15 | B 0 120 0 7 127 127 1 204 204 204 0 16 | 17 | C 2 1 0 18 | B 0 0 120 7 127 127 1 204 204 204 0 19 | B 0 120 120 7 127 127 1 204 204 204 0 20 | 21 | C 2 0 1 22 | B 0 120 0 7 127 7 1 204 204 204 0 23 | B 0 120 120 7 127 127 1 204 204 204 0 24 | B 0 120 8 7 127 119 1 0 89 255 0 25 | 26 | C 2 0 0 27 | B 0 120 120 7 127 127 1 204 204 204 0 28 | 29 | C 1 2 1 30 | B 0 0 0 127 7 7 1 204 204 204 0 31 | B 0 0 120 127 7 127 1 204 204 204 0 32 | B 0 0 8 7 7 119 1 204 0 50 0 33 | B 120 0 8 127 7 119 1 0 89 255 0 34 | B 0 0 0 127 7 127 1 204 204 204 0 35 | 36 | C 1 2 0 37 | B 0 0 120 127 7 127 1 204 204 204 0 38 | B 0 0 120 127 7 127 1 204 204 204 0 39 | 40 | C 1 1 1 41 | B 0 0 0 127 127 7 1 204 204 204 0 42 | B 0 0 120 127 127 127 1 204 204 204 0 43 | B 0 0 8 7 127 119 1 204 0 50 0 44 | B 120 0 8 127 127 119 1 0 89 255 0 45 | B 0 120 0 127 127 127 1 204 204 204 0 46 | B 64 16 120 79 31 127 0 204 204 204 184 47 | B 64 16 120 79 31 127 1 204 204 204 184 48 | B 80 72 8 111 87 39 1 0 255 0 0 49 | B 80 56 8 111 71 39 1 0 255 0 0 50 | 51 | C 1 1 0 52 | B 0 0 120 127 127 127 1 204 204 204 0 53 | B 0 120 120 127 127 127 1 204 204 204 0 54 | 55 | C 1 0 1 56 | B 0 120 0 127 127 7 1 204 204 204 0 57 | B 0 120 120 127 127 127 1 204 204 204 0 58 | B 0 120 8 7 127 119 1 204 0 50 0 59 | B 120 120 8 127 127 119 1 0 89 255 0 60 | 61 | C 1 0 0 62 | B 0 120 120 127 127 127 1 204 204 204 0 63 | 64 | C 0 2 1 65 | B 120 0 0 127 7 7 1 204 204 204 0 66 | B 120 0 120 127 7 127 1 204 204 204 0 67 | B 120 0 8 127 7 119 1 204 0 50 0 68 | B 120 0 0 127 7 127 1 204 204 204 0 69 | 70 | C 0 2 0 71 | B 120 0 120 127 7 127 1 204 204 204 0 72 | B 120 0 120 127 7 127 1 204 204 204 0 73 | 74 | C 0 1 1 75 | B 120 0 0 127 127 7 1 204 204 204 0 76 | B 120 0 120 127 127 127 1 204 204 204 0 77 | B 120 0 8 127 127 119 1 204 0 50 0 78 | B 120 120 0 127 127 127 1 204 204 204 0 79 | 80 | C 0 1 0 81 | B 120 0 120 127 127 127 1 204 204 204 0 82 | B 120 120 120 127 127 127 1 204 204 204 0 83 | 84 | C 0 0 1 85 | B 120 120 0 127 127 7 1 204 204 204 0 86 | B 120 120 120 127 127 127 1 204 204 204 0 87 | B 120 120 8 127 127 119 1 204 0 50 0 88 | 89 | C 0 0 0 90 | B 120 120 120 127 127 127 1 204 204 204 0 91 | 92 | C 2 2 2 93 | B 0 0 0 7 7 7 1 204 204 204 0 94 | B 0 0 0 7 7 7 1 204 204 204 0 95 | B 0 0 8 7 7 23 1 204 204 204 0 96 | 97 | C 2 1 2 98 | B 0 0 0 7 127 7 1 204 204 204 0 99 | B 0 120 0 7 127 7 1 204 204 204 0 100 | B 0 0 8 7 127 23 1 204 204 204 0 101 | 102 | C 2 0 2 103 | B 0 120 0 7 127 7 1 204 204 204 0 104 | B 0 120 8 7 127 23 1 204 204 204 0 105 | 106 | C 1 2 2 107 | B 0 0 0 127 7 7 1 204 204 204 0 108 | B 0 0 0 127 7 7 1 204 204 204 0 109 | B 0 0 8 127 7 23 1 204 204 204 0 110 | 111 | C 1 1 2 112 | B 0 0 0 127 127 7 1 204 204 204 0 113 | B 0 120 0 127 127 7 1 204 204 204 0 114 | B 0 0 8 127 127 23 1 204 204 204 0 115 | B 64 16 0 79 31 7 0 204 204 204 184 116 | B 64 16 0 79 31 7 1 204 204 204 184 117 | 118 | C 1 0 2 119 | B 0 120 0 127 127 7 1 204 204 204 0 120 | B 0 120 8 127 127 23 1 204 204 204 0 121 | 122 | C 0 2 2 123 | B 120 0 0 127 7 7 1 204 204 204 0 124 | B 120 0 0 127 7 7 1 204 204 204 0 125 | B 120 0 8 127 7 23 1 204 204 204 0 126 | 127 | C 0 1 2 128 | B 120 0 0 127 127 7 1 204 204 204 0 129 | B 120 120 0 127 127 7 1 204 204 204 0 130 | B 120 0 8 127 127 23 1 204 204 204 0 131 | 132 | C 0 0 2 133 | B 120 120 0 127 127 7 1 204 204 204 0 134 | B 120 120 8 127 127 23 1 204 204 204 0 135 | B 120 120 8 127 127 23 1 204 204 204 0 136 | 137 | -------------------------------------------------------------------------------- /FoxelEngine/BrushBox.cpp: -------------------------------------------------------------------------------- 1 | #include "BrushBox.h" 2 | #include "Editor.h" 3 | #include "Map.h" 4 | 5 | using namespace MapEditor; 6 | 7 | BrushBox::BrushBox(void){ 8 | size.x = size.y = size.z = 16.0f; 9 | snapedPosition.x = snapedPosition.y = snapedPosition.y = 16.0f; 10 | anzIndex = 24; 11 | anzVertex = 8; 12 | indices = BoxI; 13 | colors = BoxC; 14 | vertices = BoxV; 15 | rebuildMesh(); 16 | painting = false; 17 | } 18 | 19 | BrushBox::~BrushBox(void) 20 | { 21 | } 22 | 23 | void BrushBox::rebuildMesh(){ 24 | vertices[ 3] = size.x; 25 | vertices[ 7] = size.y; 26 | vertices[11] = size.z; 27 | vertices[12] = size.x; vertices[13] = size.y; vertices[14] = size.z; 28 | vertices[16] = size.y; vertices[17] = size.z; 29 | vertices[18] = size.x; vertices[20] = size.z; 30 | vertices[21] = size.x; vertices[22] = size.y; 31 | load(); // update to GPU 32 | } 33 | 34 | void BrushBox::draw(){ 35 | Screen::ViewMatrix.translate(snapedPosition.x,snapedPosition.y,snapedPosition.z); 36 | Screen::updateViewMatix(); 37 | glBindVertexArray(vao); 38 | glEnableVertexAttribArray(0); 39 | glEnableVertexAttribArray(1); 40 | glDrawElements(GL_LINES,anzIndex,GL_UNSIGNED_INT,indices); 41 | glDisableVertexAttribArray(0); 42 | glDisableVertexAttribArray(1); 43 | glBindVertexArray(0); 44 | Screen::ViewMatrix.translate(-snapedPosition.x,-snapedPosition.y,-snapedPosition.z); 45 | Screen::updateViewMatix(); 46 | } 47 | 48 | void BrushBox::move(Vec3 value){ 49 | moved += value; 50 | bool was_moved = false; 51 | if(moved.x > Editor::getGridDeep()){ 52 | was_moved = true; 53 | snapedPosition.x += Editor::getGridDeep(); 54 | }else if(moved.x < -Editor::getGridDeep()){ 55 | was_moved = true; 56 | snapedPosition.x -= Editor::getGridDeep(); 57 | } 58 | if(moved.y > Editor::getGridDeep()){ 59 | was_moved = true; 60 | snapedPosition.y += Editor::getGridDeep(); 61 | }else if(moved.y < -Editor::getGridDeep()){ 62 | was_moved = true; 63 | snapedPosition.y -= Editor::getGridDeep(); 64 | } 65 | if(moved.z > Editor::getGridDeep()){ 66 | was_moved = true; 67 | snapedPosition.z += Editor::getGridDeep(); 68 | }else if(moved.z < -Editor::getGridDeep()){ 69 | was_moved = true; 70 | snapedPosition.z -= Editor::getGridDeep(); 71 | } 72 | if(was_moved){ 73 | moved.x = 0; 74 | moved.y = 0; 75 | moved.z = 0; 76 | } 77 | } 78 | 79 | void BrushBox::makeBlock(){ 80 | Vec3 start, stop; 81 | 82 | if(paintStart.x <= paintStop.x){ 83 | start.x = paintStart.x; stop.x = paintStop.x + size.x-1; 84 | }else{ 85 | start.x = paintStop.x; stop.x = paintStart.x + size.x-1; 86 | } 87 | if(paintStart.y <= paintStop.y){ 88 | start.y = paintStart.y; stop.y = paintStop.y + size.y-1; 89 | }else{ 90 | start.y = paintStop.y; stop.y = paintStart.y + size.y-1; 91 | } 92 | if(paintStart.z <= paintStop.z){ 93 | start.z = paintStart.z; stop.z = paintStop.z + size.z-1; 94 | }else{ 95 | start.z = paintStop.z; stop.z = paintStart.z + size.z-1; 96 | } 97 | /* 98 | if(start.x < 0){ start.x++;} 99 | if(start.y < 0){ start.y++;} 100 | if(start.z < 0){ start.z++;} 101 | if(stop.x < 0){ stop.x++;} 102 | if(stop.y < 0){ stop.y++;} 103 | if(stop.z < 0){ stop.z++;} 104 | */ 105 | std::cout << "Start: " << start.x << "\t" << start.y << "\t" << start.z << std::endl; 106 | std::cout << "Stop: " << stop.x << "\t" << stop.y << "\t" << stop.z << std::endl; 107 | Map::createBlock(start,stop,paintID, color); 108 | } 109 | 110 | void BrushBox::startPaint(){ 111 | if(!painting){ 112 | paintStart = snapedPosition; 113 | painting = true; 114 | } 115 | } 116 | 117 | void BrushBox::stopPaint(){ 118 | if(painting){ 119 | paintStop = snapedPosition; 120 | painting = false; 121 | makeBlock(); 122 | } 123 | } 124 | 125 | void BrushBox::setPaintID(int id){ 126 | paintID = id; 127 | } 128 | 129 | void BrushBox::setColor(Color color){ 130 | this->color = color; 131 | } -------------------------------------------------------------------------------- /FoxelEngine/Core_inputs.cpp: -------------------------------------------------------------------------------- 1 | #include"Core.h" 2 | 3 | void Core::inputs(){ 4 | 5 | /* Schau nach, ob Events anliegen */ 6 | while (SDL_PollEvent (sdlEvent)){ /* Solange noch Events vorhanden sind */ 7 | 8 | specialInputs(); 9 | switch(userState){ 10 | case ON_GAME: inputOnGame(); 11 | break; 12 | 13 | case ON_MAIN_MENU: inputOnMenu(); 14 | break; 15 | 16 | case ON_GAME_PAUSE: inputOnMenu(); 17 | break; 18 | 19 | case ON_EDIT: inputOnEdit(); 20 | break; 21 | } 22 | } 23 | } 24 | 25 | void Core::specialInputs(){ 26 | switch (sdlEvent->type){ 27 | case SDL_QUIT: 28 | exit (0); 29 | break; 30 | 31 | case SDL_KEYDOWN: /* Tastaturevent */ 32 | switch(sdlEvent->key.keysym.sym){ 33 | case SDLK_F1: config->switchDebugMode(); break; 34 | case SDLK_F2: config->setDisplayMode(DisplayMode::DISPLAY_QUAD); break; 35 | case SDLK_F3: config->setDisplayMode(DisplayMode::DISPLAY_WITHOUT_RAD); break; 36 | case SDLK_F4: config->setDisplayMode(DisplayMode::DISPLAY_NORMAL); break; 37 | } 38 | break; 39 | 40 | case SDL_MOUSEBUTTONDOWN: /* Tastaturevent */ 41 | switch(sdlEvent->button.button){ 42 | case SDL_BUTTON_LEFT: screen->setKlickLeft(true); break; 43 | case SDL_BUTTON_RIGHT: screen->setKlickRight(true); break; 44 | default: break; 45 | } 46 | break; 47 | 48 | case SDL_MOUSEBUTTONUP: /* Tastaturevent */ 49 | switch(sdlEvent->button.button){ 50 | case SDL_BUTTON_LEFT: screen->setKlickLeft(false); break; 51 | case SDL_BUTTON_RIGHT: screen->setKlickRight(false); break; 52 | default: break; 53 | } 54 | break; 55 | 56 | case SDL_MOUSEMOTION: 57 | screen->catchMousePosition(Vec2(sdlEvent->motion.x, sdlEvent->motion.y)); 58 | screen->catchMouseMotion(Vec2(sdlEvent->motion.xrel, sdlEvent->motion.yrel)); 59 | break; 60 | 61 | case SDL_VIDEORESIZE: 62 | screen->resize(sdlEvent->resize.w,sdlEvent->resize.h); 63 | if(userState == ON_EDIT){ editor->resize();} 64 | break; 65 | } 66 | } 67 | void Core::inputOnGame(){ 68 | switch (sdlEvent->type) 69 | { /* Schau nach, welcher Event eingetroffen ist */ 70 | case SDL_KEYDOWN: /* Tastaturevent */ 71 | switch(sdlEvent->key.keysym.sym){ 72 | case SDLK_ESCAPE: 73 | userState = ON_GAME_PAUSE; 74 | screen->showMouse(); 75 | break; 76 | } 77 | player->catchKeyDown(sdlEvent->key.keysym.sym); 78 | break; 79 | 80 | case SDL_KEYUP: /* Tastaturevent */ 81 | player->catchKeyUp(sdlEvent->key.keysym.sym); 82 | break; 83 | 84 | case SDL_MOUSEMOTION: /* Mausevent */ 85 | player->catchMouseMotion(sdlEvent->motion.xrel, sdlEvent->motion.yrel); 86 | break; 87 | 88 | case SDL_MOUSEBUTTONDOWN: 89 | player->getControler()->catchMouseClick(sdlEvent->button.button); 90 | break; 91 | case SDL_MOUSEBUTTONUP: 92 | player->getControler()->catchMouseRelease(sdlEvent->button.button); 93 | break; 94 | 95 | default: /* unbeachteter Event */ 96 | break; 97 | } 98 | } 99 | void Core::inputOnMenu(){ 100 | switch (sdlEvent->type){ 101 | case SDL_KEYDOWN: /* Tastaturevent */ 102 | switch(sdlEvent->key.keysym.sym){ 103 | case SDLK_ESCAPE: 104 | running = false; break; 105 | } 106 | break; 107 | 108 | case SDL_KEYUP: 109 | break; 110 | 111 | default: /* unbeachteter Event */ 112 | break; 113 | } 114 | } 115 | void Core::inputOnEdit(){ 116 | switch (sdlEvent->type){ 117 | case SDL_KEYDOWN: /* Tastaturevent */ 118 | switch(sdlEvent->key.keysym.sym){ 119 | case SDLK_ESCAPE: userState = ON_MAIN_MENU; 120 | screen->showMouse(); 121 | } 122 | editor->catchKeyDown(sdlEvent->key.keysym.sym); 123 | break; 124 | 125 | case SDL_KEYUP: 126 | editor->catchKeyUp(sdlEvent->key.keysym.sym); 127 | break; 128 | 129 | case SDL_MOUSEBUTTONDOWN: 130 | editor->getControler()->catchMouseClick(sdlEvent->button.button); 131 | break; 132 | case SDL_MOUSEBUTTONUP: 133 | editor->getControler()->catchMouseRelease(sdlEvent->button.button); 134 | break; 135 | 136 | default: /* unbeachteter Event */ 137 | break; 138 | } 139 | } -------------------------------------------------------------------------------- /FoxelEngine/Player.cpp: -------------------------------------------------------------------------------- 1 | #include "Player.h" 2 | 3 | Player::Player(int typ) : PropDynamic(){ 4 | playerTyp = typ; 5 | switch(playerTyp){ 6 | case PLAYER_NORMAL: health = 100; armor = 0; noclip = false; 7 | rotation.x = 270; rotation.z = -45; 8 | case PLAYER_EDIT: health = 100; armor = 100; noclip = true; 9 | rotation.x = 335; rotation.z = -45; 10 | position.x = 4; position.y = -10; position.z = 3; 11 | case PLAYER_FOX: health = 100; armor = 0; noclip = true; 12 | rotation.x = 290; rotation.z = -45; 13 | } 14 | 15 | position = Vec3d(720,128,256); 16 | 17 | maxMoveSpeed = 0.025f; 18 | accelerateValue = 0.0001f; 19 | pistol = new Pistol(); 20 | pistol->load(); 21 | camera = new Camera(); 22 | camera->setRotation(rotation); 23 | controler = new PlayerControler(playerTyp); 24 | } 25 | 26 | void Player::catchKeyDown(SDLKey sym){ 27 | controler->getKeyDown(sym); 28 | } 29 | 30 | void Player::catchKeyUp(SDLKey sym){ 31 | controler->getKeyUp(sym); 32 | } 33 | 34 | void Player::catchMouseMotion(float x, float y){ 35 | drx = x/16.0f; 36 | dry = y/16.0f; 37 | rotation.z += drx; 38 | rotation.x += dry; 39 | if(rotation.z > 360) rotation.z -= 360; 40 | if(rotation.x > 360) rotation.x = 360; 41 | if(rotation.z < 0 ) rotation.z += 360; 42 | if(rotation.x < 180 ) rotation.x = 180; 43 | } 44 | 45 | void Player::update(float* time){ 46 | if(controler->sprint){ 47 | accelerateValue = 0.001f; 48 | maxMoveSpeed = 0.25f; 49 | }else{ 50 | accelerateValue = 0.0001f; 51 | maxMoveSpeed = 0.025f; 52 | } 53 | if(controler->backward){ 54 | float speed = accelerateValue **time ; 55 | velocity.x -= speed * sin(-Convert::degToRad(&rotation.z))*sin(Convert::degToRad(&rotation.x)); 56 | velocity.y += speed * cos(-Convert::degToRad(&rotation.z))*sin(Convert::degToRad(&rotation.x)); 57 | if(noclip) velocity.z += speed * cos(Convert::degToRad(&rotation.x)); 58 | } 59 | if(controler->forward){ 60 | float speed = accelerateValue **time ; 61 | velocity.x += speed * sin(-Convert::degToRad(&rotation.z))*sin(Convert::degToRad(&rotation.x)); 62 | velocity.y -= speed * cos(-Convert::degToRad(&rotation.z))*sin(Convert::degToRad(&rotation.x)); 63 | if(noclip) velocity.z -= speed * cos(Convert::degToRad(&rotation.x)); 64 | } 65 | if(controler->right){ 66 | float speed = accelerateValue **time ; 67 | velocity.x += speed * cos(Convert::degToRad(&rotation.z)); 68 | velocity.y -= speed * sin(Convert::degToRad(&rotation.z)); 69 | } 70 | if(controler->left){ 71 | float speed = accelerateValue **time ; 72 | velocity.x -= speed * cos(Convert::degToRad(&rotation.z)); 73 | velocity.y += speed * sin(Convert::degToRad(&rotation.z)); 74 | } 75 | if(controler->shoot){ 76 | pistol->shoot(position, calcDirVector()); 77 | controler->shoot = false; 78 | } 79 | if(controler->zoom){ 80 | pistol->shoot2(position, calcDirVector()); 81 | } 82 | 83 | 84 | PropDynamic::update(time); 85 | camera->setPosition(-position); 86 | camera->setRotation(rotation); 87 | pistol->forceR(Vec3d(-dry,0,-drx)); 88 | 89 | pistol->update(time); 90 | createEvents(); 91 | 92 | FoxelManager::setLodCenter(position); 93 | 94 | //std:: cout << "x\t" << position.x << "\ty\t" << position.y << "\tz\t" << position.z << std::endl; 95 | } 96 | 97 | void Player::render(){ 98 | 99 | GLSL::PM::useProg(GLSL::PROGRAM_MODEL); 100 | //pistol->draw(); 101 | camera->setupView(); 102 | } 103 | 104 | /* 105 | ==================================== 106 | calculate the (view)direction vector 107 | ==================================== 108 | */ 109 | Vec3 Player::calcDirVector(){ 110 | Vec3 direction; 111 | direction.x = (float) sin(-Convert::degToRad(&rotation.z)) * (float)sin(Convert::degToRad(&rotation.x)); 112 | direction.y = (float)-cos(-Convert::degToRad(&rotation.z)) * (float)sin(Convert::degToRad(&rotation.x)); 113 | direction.z = (float)-cos(Convert::degToRad(&rotation.x)); 114 | return direction; 115 | } 116 | 117 | void Player::createEvents(){ 118 | 119 | // TODO 120 | //if(playerTyp != PLAYER_EDIT && controler->setFoxel){ 121 | // if(controler->setFoxel){ // debug 122 | // new Event::setFoxel(&position, 1); 123 | //} 124 | } 125 | 126 | PlayerControler* Player::getControler(){ 127 | return controler; 128 | } 129 | 130 | void Player::setTyp(int typ){ 131 | playerTyp = typ; 132 | controler->controleMode = typ; 133 | } 134 | 135 | Player::~Player(void){ 136 | } 137 | -------------------------------------------------------------------------------- /FoxelEngine/Model.cpp: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS // to disable the fscanf warnings 2 | #include "Model.h" 3 | #include "ShaderProgram.h" 4 | 5 | using namespace std; 6 | using namespace GLSL; 7 | 8 | GLuint Model::anzIndex, Model::anzVertex; 9 | GLVertex* Model::vertices; 10 | GLuint Model::vao, *Model::indices, Model::vbos[2]; 11 | bool Model::loaded = false; 12 | 13 | Model::Model(){ 14 | 15 | } 16 | 17 | Model::~Model(){ 18 | 19 | } 20 | 21 | /* 22 | ======================================================== 23 | Load the objFile into the system Memory and converting 24 | the Model-Data to an usable Mesh. At the end it put that 25 | Mesh into thy GPU-RAM 26 | ======================================================== 27 | */ 28 | bool Model::load(char* objFile){ 29 | if(!loaded){ 30 | FILE* file = fopen(objFile,"r"); 31 | if(file == NULL){ 32 | cout << "Can't open model file: " << objFile << endl; 33 | return false; 34 | } 35 | vector v_Vertex; vector v_VertexIndices; 36 | vector v_Normal; vector v_NormalIndices; 37 | vector v_Textur; vector v_TexturIndices; 38 | 39 | char lineTyp[256]; 40 | bool done = false; 41 | Vertex cVertex; 42 | Normal cNormal; 43 | Textur cTextur; 44 | while(!done){ 45 | if((fscanf(file, "%s",lineTyp) == EOF)){ 46 | done = true; 47 | break; 48 | }else{ 49 | if(strcmp(lineTyp, "v") == 0){ 50 | fscanf(file,"%f %f %f\n",&cVertex.x,&cVertex.y,&cVertex.z); 51 | v_Vertex.push_back(cVertex); 52 | }else if(strcmp(lineTyp,"vt") == 0){ 53 | fscanf(file,"%f %f\n",&cTextur.u,&cTextur.v); 54 | v_Textur.push_back(cTextur); 55 | }else if(strcmp(lineTyp,"vn") == 0){ 56 | fscanf(file,"%f %f %f\n",&cNormal.a,&cNormal.b,&cNormal.c); 57 | v_Normal.push_back(cNormal); 58 | }else if(strcmp(lineTyp,"f") == 0){ 59 | string vertex1,vertex2,vertex3; 60 | unsigned int vertexIndex[3], texturIndex[3], normalIndex[3]; 61 | int matches = fscanf(file, "%u/%u/%u %u/%u/%u %u/%u/%u\n", 62 | &vertexIndex[0], &texturIndex[0], &normalIndex[0], 63 | &vertexIndex[1], &texturIndex[1], &normalIndex[1], 64 | &vertexIndex[2], &texturIndex[2], &normalIndex[2]); 65 | if (matches == 9){ 66 | v_VertexIndices.push_back(vertexIndex[0]-1); 67 | v_VertexIndices.push_back(vertexIndex[1]-1); 68 | v_VertexIndices.push_back(vertexIndex[2]-1); 69 | v_TexturIndices.push_back(texturIndex[0]-1); 70 | v_TexturIndices.push_back(texturIndex[1]-1); 71 | v_TexturIndices.push_back(texturIndex[2]-1); 72 | v_NormalIndices.push_back(normalIndex[0]-1); 73 | v_NormalIndices.push_back(normalIndex[1]-1); 74 | v_NormalIndices.push_back(normalIndex[2]-1); 75 | } 76 | } 77 | } 78 | } 79 | 80 | // Now sorting the data 81 | anzVertex = (GLuint)v_Vertex.size(); 82 | anzIndex = (GLuint)v_VertexIndices.size(); 83 | vertices = new GLVertex[anzVertex]; 84 | indices = new GLuint[anzIndex]; 85 | for(unsigned int i = 0; i < anzVertex; i++){ 86 | vertices[i].x = v_Vertex[i].x; 87 | vertices[i].y = v_Vertex[i].y; 88 | vertices[i].z = v_Vertex[i].z; 89 | } 90 | for(unsigned int i = 0; i < anzIndex; i++){ 91 | indices[i] = v_VertexIndices[i]; 92 | 93 | vertices[v_VertexIndices[i]].a = v_Normal[v_NormalIndices[i]].a; 94 | vertices[v_VertexIndices[i]].b = v_Normal[v_NormalIndices[i]].b; 95 | vertices[v_VertexIndices[i]].c = v_Normal[v_NormalIndices[i]].c; 96 | 97 | vertices[v_VertexIndices[i]].u = v_Textur[v_TexturIndices[i]].u; 98 | vertices[v_VertexIndices[i]].v = v_Textur[v_TexturIndices[i]].v; 99 | } 100 | 101 | glGenVertexArrays(1,&vao); 102 | glBindVertexArray(vao); 103 | glGenBuffers(3,vbos); 104 | 105 | const size_t normalOffset = sizeof(vertices->x); 106 | const size_t vertexSize = sizeof(vertices[0]); 107 | 108 | 109 | // vertex data 110 | glBindBuffer(GL_ARRAY_BUFFER,vbos[0]); 111 | glBufferData(GL_ARRAY_BUFFER,anzVertex*sizeof(GLVertex),vertices,GL_STATIC_DRAW); 112 | glVertexAttribPointer(0,3,GL_FLOAT, GL_FALSE,sizeof(GL_FLOAT)*8,0); 113 | glVertexAttribPointer(1,2,GL_FLOAT,GL_FALSE,sizeof(GL_FLOAT)*8,BUFFER_OFFSET(normalOffset)); 114 | glVertexAttribPointer(2,3,GL_FLOAT,GL_FALSE,sizeof(GL_FLOAT)*8,BUFFER_OFFSET(3*sizeof(GLfloat))); 115 | 116 | // index data 117 | glBindBuffer(GL_ARRAY_BUFFER,vbos[1]); 118 | glBufferData(GL_ARRAY_BUFFER,anzIndex*sizeof(GL_UNSIGNED_INT),indices,GL_STATIC_DRAW); 119 | 120 | glBindVertexArray(0); 121 | loaded = true; 122 | return true; 123 | } 124 | return false; 125 | } 126 | 127 | void Model::draw(){ 128 | 129 | glBindVertexArray(vao); 130 | glEnableVertexAttribArray(0); 131 | glEnableVertexAttribArray(2); 132 | glVertexAttrib4f(1,1.0f,0.25f,0.0125f,0.5f); 133 | glDrawElements(GL_TRIANGLES,anzIndex,GL_UNSIGNED_INT,indices); 134 | glDisableVertexAttribArray(0); 135 | glDisableVertexAttribArray(2); 136 | glBindVertexArray(0); 137 | 138 | } -------------------------------------------------------------------------------- /FoxelEngine/Matrix4.cpp: -------------------------------------------------------------------------------- 1 | #include "Matrix4.h" 2 | #include "Convert.h" 3 | using namespace std; 4 | 5 | 6 | Matrix4::Matrix4(void){ 7 | for(int n = 0; n < M_SIZE*M_SIZE; n++){ 8 | if(n % 5 == 0) matrix[n] = 0.0f; // identity 9 | else matrix[n] = 0.0f; 10 | } 11 | } 12 | 13 | 14 | Matrix4::~Matrix4(void) 15 | { 16 | } 17 | 18 | Matrix4 Matrix4::Identity(){ 19 | Matrix4 id; 20 | for(int i = 0; i < M_SIZE*M_SIZE; i+=5){ 21 | id.matrix[i] = 1.0f; 22 | } 23 | return id; 24 | } 25 | 26 | void Matrix4::scale(float x, float y, float z){ 27 | Matrix4 scaly = Matrix4::Identity(); 28 | scaly.matrix[ 0] = x; 29 | scaly.matrix[ 5] = y; 30 | scaly.matrix[10] = z; 31 | *this = *this * scaly; 32 | } 33 | 34 | /* ========================= 35 | Transponierte Translation 36 | ========================= 37 | */ 38 | void Matrix4::translate(float x,float y,float z){ 39 | Matrix4 trans = Matrix4::Identity(); 40 | trans.matrix[12] = x; 41 | trans.matrix[13] = y; 42 | trans.matrix[14] = z; 43 | *this = *this * trans; 44 | } 45 | /* ========================= 46 | Transponierte Translation 47 | ========================= 48 | */ 49 | void Matrix4::translate(Vec3 vector){ 50 | Matrix4 trans = Matrix4::Identity(); 51 | trans.matrix[12] = vector.x; 52 | trans.matrix[13] = vector.y; 53 | trans.matrix[14] = vector.z; 54 | *this = *this * trans; 55 | } 56 | /* ====================== 57 | Transponierte Rotation 58 | ====================== 59 | */ 60 | void Matrix4::rotate(float angle, float x, float y, float z){ 61 | angle = Convert::degToRad(&angle); 62 | if(x > 0.001){ 63 | Matrix4 rotX = Matrix4::Identity(); 64 | rotX.matrix[ 5] = cos(angle); 65 | rotX.matrix[ 9] = -sin(angle); 66 | rotX.matrix[ 6] = sin(angle); 67 | rotX.matrix[10] = cos(angle); 68 | *this = *this * rotX; 69 | } 70 | if(y > 0.001){ 71 | Matrix4 rotY = Matrix4::Identity(); 72 | rotY.matrix[ 0] = cos(angle); 73 | rotY.matrix[ 8] = sin(angle); 74 | rotY.matrix[ 2] = -sin(angle); 75 | rotY.matrix[10] = cos(angle); 76 | *this = *this * rotY; 77 | } 78 | if(z > 0.001){ 79 | Matrix4 rotZ = Matrix4::Identity(); 80 | rotZ.matrix[0] = cos(angle); 81 | rotZ.matrix[4] = -sin(angle); 82 | rotZ.matrix[1] = sin(angle); 83 | rotZ.matrix[5] = cos(angle); 84 | *this = *this * rotZ; 85 | } 86 | } 87 | 88 | Matrix4 Matrix4::RotateX(float angle){ 89 | Matrix4 rotX = Matrix4::Identity(); 90 | rotX.matrix[ 5] = cos(angle); 91 | rotX.matrix[ 9] = -sin(angle); 92 | rotX.matrix[ 6] = sin(angle); 93 | rotX.matrix[10] = cos(angle); 94 | return rotX; 95 | } 96 | 97 | Matrix4 Matrix4::RotateY(float angle){ 98 | Matrix4 rotY = Matrix4::Identity(); 99 | rotY.matrix[ 0] = cos(angle); 100 | rotY.matrix[ 8] = sin(angle); 101 | rotY.matrix[ 2] = -sin(angle); 102 | rotY.matrix[10] = cos(angle); 103 | return rotY; 104 | } 105 | 106 | Matrix4 Matrix4::RotateZ(float angle){ 107 | Matrix4 rotZ = Matrix4::Identity(); 108 | rotZ.matrix[0] = cos(angle); 109 | rotZ.matrix[4] = -sin(angle); 110 | rotZ.matrix[1] = sin(angle); 111 | rotZ.matrix[5] = cos(angle); 112 | return rotZ; 113 | } 114 | 115 | Matrix4 Matrix4::CreateFromAxisAngle(Vec3 axis, float angle){ 116 | Matrix4 mat; 117 | angle = Convert::degToRad(angle); 118 | float num = cos(-angle); 119 | float num2 = sin(-angle); 120 | float num3 = 1.0f - num; 121 | axis.normalize(); 122 | mat.matrix[0] = ((num3 * axis.x) * axis.x) + num; 123 | mat.matrix[1] = ((num3 * axis.x) * axis.y) - (num2 * axis.z); 124 | mat.matrix[2] = ((num3 * axis.x) * axis.z) + (num2 * axis.y); 125 | mat.matrix[3] = 0.0f; 126 | mat.matrix[4] = ((num3 * axis.x) * axis.y) + (num2 * axis.z); 127 | mat.matrix[5] = ((num3 * axis.y) * axis.y) + num; 128 | mat.matrix[6] = ((num3 * axis.y) * axis.z) - (num2 * axis.x); 129 | mat.matrix[7] = 0.0f; 130 | mat.matrix[8] = ((num3 * axis.x) * axis.z) - (num2 * axis.y); 131 | mat.matrix[9] = ((num3 * axis.y) * axis.z) + (num2 * axis.x); 132 | mat.matrix[10] = ((num3 * axis.z) * axis.z) + num; 133 | mat.matrix[11] = 0.0f; 134 | mat.matrix[12] = 0.0f; 135 | mat.matrix[13] = 0.0f; 136 | mat.matrix[14] = 0.0f; 137 | mat.matrix[15] = 1.0f; 138 | return mat; 139 | } 140 | 141 | float* Matrix4::getMatrix(){ 142 | return matrix; 143 | } 144 | /* ============================ 145 | Transponierte Multiplikation 146 | ============================ 147 | */ 148 | Matrix4 Matrix4::operator*(Matrix4 B){ 149 | Matrix4 C; 150 | for(int i = 0; i < M_SIZE; i++){ 151 | for(int s = 0; s < M_SIZE; s++){ 152 | for(int z = 0; z < M_SIZE; z++){ 153 | C.matrix[M_SIZE*s+i] += matrix[M_SIZE*z+i] * B.matrix[M_SIZE*s+z]; 154 | } 155 | } 156 | } 157 | return C; 158 | } 159 | 160 | void Matrix4::printMatrix(){ 161 | cout << endl << "_________________________" << endl; 162 | for(int i = 0; i < M_SIZE*M_SIZE; i++){ 163 | if(i != 0 && i % 4 == 0) cout << "\n\n\n\n\n"; 164 | cout << matrix[i] << "\t"; 165 | } 166 | cout << endl << "_________________________" << endl; 167 | } -------------------------------------------------------------------------------- /FoxelEngine/View.cpp: -------------------------------------------------------------------------------- 1 | #include "View.h" 2 | #include 3 | #include 4 | #include 5 | #include "Editor.h" 6 | 7 | using namespace MapEditor; 8 | using namespace GLSL; 9 | 10 | int lines = 0; // debug 11 | 12 | View::View(ViewModus viewMode, Vec2 position, Vec2 size) : Entity_2D(position, size){ 13 | this->viewMode = viewMode; 14 | if(viewMode == VIEW_3D) ePlayer = new Player(PLAYER_EDIT); 15 | zoom = 4; 16 | } 17 | 18 | View::~View(void){ 19 | } 20 | 21 | void View::setUp(){ 22 | 23 | glMatrixMode(GL_PROJECTION); //old 24 | glLoadIdentity(); //old 25 | glViewport((GLsizei)position.x, (GLsizei)position.y, (GLsizei)size.x, (GLsizei)size.y); 26 | glLoadIdentity(); 27 | 28 | glOrtho(-size.x/2, size.x/2, -size.y/2, size.y/2,-65536,65536); // old 29 | Screen::buildOrthoMatrix(-size.x/2, size.x/2, -size.y/2, size.y/2,-65536,65536); 30 | 31 | glMatrixMode(GL_MODELVIEW); // old 32 | glLoadIdentity(); // old 33 | Screen::ViewMatrix = Matrix4::Identity(); 34 | 35 | const float xMin = -size.x/2+1; 36 | const float xMax = size.x/2; 37 | const float yMin = -size.y/2+1; 38 | const float yMax = size.y/2; 39 | // draw Background 40 | PM::useProg(PROGRAM_NULL); 41 | glBegin(GL_QUADS); 42 | glColor3f(0.02f,0.02f,0.02f); glVertex3f(xMin,yMin, -128); 43 | glVertex3f(xMax,yMin, -128); 44 | glColor3f(0.15f,0.15f,0.15f); glVertex3f(xMax,yMax, -128); 45 | glVertex3f(xMin,yMax, -128); 46 | glEnd(); 47 | 48 | // draw boxline 49 | glColor3f(0.5f,0.5f,0.5f); 50 | glBegin(GL_LINE_LOOP); 51 | glVertex3f(xMin,yMin, -127.5); 52 | glVertex3f(xMin,yMax, -127.5); 53 | glVertex3f(xMax,yMax, -127.5); 54 | glVertex3f(xMax,yMin, -127.5); 55 | glEnd(); 56 | 57 | glScalef(zoom,zoom,zoom); //old 58 | Screen::ViewMatrix.scale(zoom,zoom,zoom); 59 | 60 | if(viewMode > 0){ 61 | drawGrid(); 62 | } 63 | 64 | 65 | switch(viewMode){ 66 | case VIEW_TOP: 67 | { 68 | glRotatef(0,0,0,0); 69 | glTranslatef(-viewPosition.x,-viewPosition.y,0); 70 | Screen::ViewMatrix.rotate(0,0,0,0); 71 | Screen::ViewMatrix.translate(-viewPosition.x,-viewPosition.y,0); 72 | break; 73 | } 74 | case VIEW_FRONT: 75 | { 76 | glRotatef(-90,1,0,0); 77 | glTranslatef(-viewPosition.x,0,-viewPosition.y); 78 | Screen::ViewMatrix.rotate(-90,1,0,0); 79 | Screen::ViewMatrix.translate(-viewPosition.x,0,-viewPosition.y); 80 | break; 81 | } 82 | case VIEW_RIGHT: 83 | { 84 | glRotatef(-90,1,0,0); 85 | glRotatef(90,0,0,1); 86 | glTranslatef(0, viewPosition.x, -viewPosition.y); 87 | Screen::ViewMatrix.rotate(-90,1,0,0); 88 | Screen::ViewMatrix.rotate(90,0,0,1); 89 | Screen::ViewMatrix.translate(0, viewPosition.x, -viewPosition.y); 90 | break; 91 | } 92 | } 93 | 94 | if(viewMode == VIEW_3D){ 95 | glDisable(GL_BLEND); 96 | glEnable(GL_DEPTH_TEST); 97 | float ar = (float) size.x / (float) size.y; 98 | PM::useProg(PROGRAM_FOXEL); 99 | Screen::buildProjectionMatrix(90.0f,ar,1.0f,2048.0f); 100 | ePlayer->render(); 101 | Screen::updateViewMatix(); 102 | Screen::updateProjMatix(); 103 | } 104 | PM::useProg(PROGRAM_BASIC); 105 | Screen::updateViewMatix(); 106 | Screen::updateProjMatix(); 107 | 108 | } 109 | 110 | void View::update(float* time){ 111 | if(viewMode == VIEW_3D) ePlayer->update(time); 112 | } 113 | 114 | void View::draw(){ 115 | if(viewMode == VIEW_3D){ 116 | PM::useProg(PROGRAM_FOXEL); 117 | } 118 | } 119 | 120 | void View::drawGrid(){ 121 | glColor3f(0.2f,0.2f,0.2f); 122 | lines = 0; 123 | glTranslatef(-viewPosition.x,-viewPosition.y,0); 124 | glBegin(GL_LINES); 125 | // vertical lines 126 | int rasterXR = (int)(viewPosition.x + size.x/(2*zoom)); 127 | int rasterXL = (int)(viewPosition.x - size.x/(2*zoom)); 128 | int rasterYU = (int)(viewPosition.y + size.y/(2*zoom)); 129 | int rasterYD = (int)(viewPosition.y - size.y/(2*zoom)); 130 | rasterYD -= rasterYD % Editor::getGridDeep(); 131 | rasterXL -= rasterXL % Editor::getGridDeep(); 132 | for(int x = rasterXL; x <= rasterXR; x += Editor::getGridDeep()){ 133 | if(x % 128 == 0){ 134 | glColor3f(0.3f,0.1f,0.1f); 135 | }else{ 136 | glColor3f(0.2f,0.2f,0.2f); 137 | } 138 | glVertex3i(x,(int)( size.y/(2*zoom)+viewPosition.y), 0); 139 | glVertex3i(x,(int)(-size.y/(2*zoom)+viewPosition.y), 0); 140 | lines++; // debug 141 | } 142 | // horizontal lines 143 | 144 | for(int y = rasterYD; y <= rasterYU; y += Editor::getGridDeep()){ 145 | if(y % 128 == 0){ 146 | glColor3f(0.3f,0.1f,0.1f); 147 | }else{ 148 | glColor3f(0.2f,0.2f,0.2f); 149 | } 150 | glVertex3i((int)( size.x/(2*zoom)+viewPosition.x), y, 0); 151 | glVertex3i((int)(-size.x/(2*zoom)+viewPosition.x), y, 0); 152 | } 153 | glEnd(); 154 | glTranslatef(viewPosition.x,viewPosition.y,0); 155 | } 156 | 157 | void View::addZoomValue(float value){ 158 | if(value > 0){ 159 | zoom += zoom; 160 | }else{ 161 | zoom -= zoom/2; 162 | } 163 | std::cout << "zoom:\t" << zoom << "\tgrid:\t" << Editor::getGridDeep() << "\tlines:\t" << lines << std::endl; 164 | } 165 | 166 | void View::moveViewPosition(Vec3 value){ 167 | viewPosition += value * (1.0f/zoom); 168 | } 169 | 170 | ViewModus View::getViewMode(){ 171 | return viewMode; 172 | } 173 | 174 | Player* View::getPlayer(){ 175 | return ePlayer; 176 | } -------------------------------------------------------------------------------- /FoxelEngine/Map.cpp: -------------------------------------------------------------------------------- 1 | #include "Map.h" 2 | #include "FoxelManager.h" 3 | #include 4 | 5 | using namespace std; 6 | string Map::name = "Empty"; 7 | 8 | Map::Map(){ 9 | } 10 | 11 | Map::~Map(void){ 12 | } 13 | 14 | void Map::createBlock(Vec3 start, Vec3 end, short id, Color color){ 15 | int cidX, cidY, cidZ; 16 | stack chunkBrushes; 17 | vector chunkID = FoxelManager::tracingChunkID(start); 18 | 19 | // splitting up in seperate Chunk-Brushes 20 | Vec3 cStart; 21 | 22 | int sx,sy,sz,ex,ey,ez; 23 | 24 | cidX = chunkID[0]; 25 | cStart.x = start.x; 26 | sx = (int)cStart.x % 128; 27 | 28 | int xmod = (int)start.x % 128; 29 | int ymod = (int)start.y % 128; 30 | int zmod = (int)start.z % 128; 31 | 32 | if(xmod < 0) xmod *= -1; 33 | if(ymod < 0) ymod *= -1; 34 | if(zmod < 0) zmod *= -1; 35 | 36 | while(cStart.x - xmod < end.x){ 37 | if(cStart.x > start.x) sx = 0; 38 | // brush between 2 chunks 39 | int cxmod = (int)cStart.x % 128; 40 | if(cxmod < 0) cxmod *= -1; 41 | if(cStart.x + 128 - cxmod < end.x){ 42 | ex = 127; 43 | }else{ 44 | ex = (int)end.x % 128;; 45 | } 46 | 47 | cidY = chunkID[1]; 48 | cStart.y = start.y; 49 | sy = (int)cStart.y % 128; 50 | while(cStart.y - ymod < end.y){ 51 | if(cStart.y > start.y) sy = 0; 52 | // brush between 2 chunks 53 | int cymod = (int)cStart.y % 128; 54 | if(cymod < 0) cymod *= -1; 55 | if(cStart.y + 128 - cymod < end.y){ 56 | ey = 127; 57 | }else{ 58 | ey = (int)end.y % 128;; 59 | } 60 | 61 | cidZ = chunkID[2]; 62 | cStart.z = start.z; 63 | sz = (int)cStart.z % 128; 64 | while(cStart.z - zmod < end.z){ 65 | if(cStart.z > start.z) sz = 0; 66 | // brush between 2 chunks 67 | int czmod = (int)cStart.z % 128; 68 | if(czmod < 0) czmod *= -1; 69 | if(cStart.z + 128 - czmod < end.z){ 70 | ez = 127; 71 | }else{ 72 | ez = (int)end.z % 128;; 73 | } 74 | 75 | ChunkBrush cBrush; 76 | 77 | if(sx < 0) sx += 128; 78 | if(sy < 0) sy += 128; 79 | if(sz < 0) sz += 128; 80 | 81 | if(ex < 0) ex += 128; 82 | if(ey < 0) ey += 128; 83 | if(ez < 0) ez += 128; 84 | 85 | cBrush.sX = sx; 86 | cBrush.sY = sy; 87 | cBrush.sZ = sz; 88 | 89 | cBrush.eX = ex; 90 | cBrush.eY = ey; 91 | cBrush.eZ = ez; 92 | 93 | cBrush.idX = cidX; 94 | cBrush.idY = cidY; 95 | cBrush.idZ = cidZ; 96 | 97 | cBrush.cR = color.getRed(); 98 | cBrush.cG = color.getGreen(); 99 | cBrush.cB = color.getBlue(); 100 | cBrush.em = color.getAlpha(); 101 | 102 | cBrush.id = id; 103 | 104 | chunkBrushes.push(cBrush); 105 | cStart.z += 128; 106 | cidZ++; 107 | } 108 | cStart.y += 128; 109 | cidY++; 110 | } 111 | cStart.x += 128; 112 | cidX++; 113 | } 114 | 115 | // send to FoxelManager 116 | while(chunkBrushes.size() != 0){ 117 | FoxelManager::addBrush(chunkBrushes.top()); 118 | chunkBrushes.pop(); 119 | } 120 | //FoxelManager::update(); 121 | } 122 | 123 | void Map::update(){ 124 | FoxelManager::update(); 125 | } 126 | 127 | bool Map::load(string mapName){ 128 | FoxelManager::deleteAll(); 129 | name = mapName; 130 | char header; 131 | fstream file; 132 | FoxelManager* chunk; 133 | // TODO Error catching 134 | file.open("Maps/" + mapName + ".foxel", ios::in); 135 | 136 | if(file.good()){ 137 | unsigned short sX,sY,sZ; // Start Point x y z; 138 | unsigned short eX,eY,eZ; // End Point x y z; 139 | unsigned short cR,cG,cB,em; // Color 140 | short id; // Foxel id 141 | 142 | while(!file.eof()){ 143 | file >> header; 144 | switch(header){ 145 | case 'C': 146 | int idX,idY,idZ; 147 | file >> idX >> idY >> idZ; 148 | chunk = new FoxelManager(idX,idY,idZ); 149 | break; 150 | case 'B': 151 | file >> sX >> sY >> sZ >> eX >> eY >> eZ >> id >> cR >> cG >> cB >> em; 152 | chunk->brushes.push_back(new Brush((unsigned char)sX,(unsigned char)sY,(unsigned char)sZ,(unsigned char)eX,(unsigned char)eY,(unsigned char)eZ,id,(unsigned char)cR,(unsigned char)cG,(unsigned char)cB,(unsigned char)em)); 153 | break; 154 | default: break; 155 | } 156 | } 157 | } 158 | FoxelManager::loadAllChunks(); 159 | return true; 160 | } 161 | 162 | void Map::save(string mapName){ 163 | name = mapName; 164 | fstream file; 165 | file.open("Maps/" + mapName + ".foxel", ios::out); 166 | std::vector* fm = FoxelManager::getChunkList(); 167 | 168 | for(int i = 0; i < fm->size(); i++){ 169 | if(fm->at(i)->brushes.size() > 0){ // is there any brush? 170 | file << "C " << fm->at(i)->myID[0] << " " << fm->at(i)->myID[1] << " " << fm->at(i)->myID[2] << endl; 171 | for(int j = 0; j < fm->at(i)->brushes.size(); j++){ 172 | file << "B " << (short)fm->at(i)->brushes[j]->sX << " " << (short)fm->at(i)->brushes[j]->sY << " " << (short)fm->at(i)->brushes[j]->sZ 173 | << " " << (short)fm->at(i)->brushes[j]->eX << " " << (short)fm->at(i)->brushes[j]->eY << " " << (short)fm->at(i)->brushes[j]->eZ 174 | << " " << (short)fm->at(i)->brushes[j]->id << " " << (short)fm->at(i)->brushes[j]->cR << " " << (short)fm->at(i)->brushes[j]->cG 175 | << " " << (short)fm->at(i)->brushes[j]->cB << " " << (short)fm->at(i)->brushes[j]->em << endl; 176 | } 177 | file << endl; 178 | } 179 | } 180 | file.close(); 181 | } -------------------------------------------------------------------------------- /FoxelEngine/Maps/Test_Map4.foxel: -------------------------------------------------------------------------------- 1 | C 3 2 1 2 | B 0 0 0 7 7 7 1 204 204 204 0 3 | B 0 8 0 7 127 7 1 204 204 204 0 4 | B 0 0 120 7 7 127 1 204 204 204 0 5 | B 0 8 120 7 127 127 1 204 204 204 0 6 | B 0 120 8 7 127 119 1 0 121 204 0 7 | 8 | C 3 2 0 9 | B 0 0 120 7 7 127 1 204 204 204 0 10 | B 0 8 120 7 127 127 1 204 204 204 0 11 | 12 | C 3 1 1 13 | B 0 0 0 7 127 7 1 204 204 204 0 14 | B 0 0 120 7 127 127 1 204 204 204 0 15 | B 0 0 8 7 7 119 1 216 204 204 0 16 | 17 | C 3 1 0 18 | B 0 0 120 7 127 127 1 204 204 204 0 19 | 20 | C 3 0 1 21 | B 0 120 0 7 127 7 1 204 204 204 0 22 | B 0 120 120 7 127 127 1 204 204 204 0 23 | B 0 120 8 7 127 119 1 216 204 204 0 24 | 25 | C 3 0 0 26 | B 0 120 120 7 127 127 1 204 204 204 0 27 | 28 | C 2 2 1 29 | B 0 0 0 127 7 7 1 204 204 204 0 30 | B 0 8 0 127 127 7 1 204 204 204 0 31 | B 0 0 120 127 7 127 1 204 204 204 0 32 | B 0 0 8 7 7 119 1 216 204 204 0 33 | B 0 8 8 7 127 127 1 216 204 204 0 34 | B 0 8 120 127 127 127 1 204 204 204 0 35 | B 8 120 8 127 127 119 1 0 121 204 0 36 | 37 | C 2 2 0 38 | B 0 0 120 127 7 127 1 204 204 204 0 39 | B 0 8 120 127 127 127 1 204 204 204 0 40 | 41 | C 2 1 1 42 | B 0 0 0 127 127 7 1 204 204 204 0 43 | B 0 0 120 127 127 127 1 204 204 204 0 44 | B 0 120 8 7 127 119 1 216 204 204 0 45 | B 0 0 8 127 7 119 1 216 204 204 0 46 | 47 | C 2 1 0 48 | B 0 0 120 127 127 127 1 204 204 204 0 49 | 50 | C 2 0 1 51 | B 0 120 0 127 127 7 1 204 204 204 0 52 | B 0 120 120 127 127 127 1 204 204 204 0 53 | B 0 120 8 127 127 119 1 216 204 204 0 54 | 55 | C 2 0 0 56 | B 0 120 120 127 127 127 1 204 204 204 0 57 | 58 | C 1 2 1 59 | B 0 0 0 127 7 7 1 204 204 204 0 60 | B 120 8 0 127 127 7 1 204 204 204 0 61 | B 0 0 120 127 7 127 1 204 204 204 0 62 | B 0 0 8 7 7 119 1 216 165 0 0 63 | B 8 0 8 127 7 119 1 216 204 204 0 64 | B 120 8 8 127 127 127 1 216 204 204 0 65 | B 120 8 120 127 127 127 1 204 204 204 0 66 | 67 | C 1 2 0 68 | B 0 0 120 127 7 127 1 204 204 204 0 69 | B 120 8 120 127 127 127 1 204 204 204 0 70 | 71 | C 1 1 1 72 | B 0 0 0 127 127 7 1 204 204 204 0 73 | B 0 0 120 127 127 127 1 204 204 204 0 74 | B 40 48 120 55 63 127 0 204 204 204 255 75 | B 40 48 120 55 63 127 1 204 204 204 255 76 | B 0 0 8 7 127 119 1 216 165 0 0 77 | B 8 120 8 127 127 119 1 216 204 204 0 78 | B 8 0 8 127 7 119 1 216 204 204 0 79 | 80 | C 1 1 0 81 | B 0 0 120 127 127 127 1 204 204 204 0 82 | 83 | C 1 0 1 84 | B 0 120 0 127 127 7 1 204 204 204 0 85 | B 0 120 120 127 127 127 1 204 204 204 0 86 | B 0 120 8 7 127 119 1 216 165 0 0 87 | B 8 120 8 127 127 119 1 216 204 204 0 88 | 89 | C 1 0 0 90 | B 0 120 120 127 127 127 1 204 204 204 0 91 | 92 | C 0 2 1 93 | B 120 0 0 127 7 7 1 204 204 204 0 94 | B 120 0 120 127 7 127 1 204 204 204 0 95 | B 120 0 8 127 7 119 1 216 165 0 0 96 | 97 | C 0 2 0 98 | B 120 0 120 127 7 127 1 204 204 204 0 99 | 100 | C 0 1 1 101 | B 120 0 0 127 127 7 1 204 204 204 0 102 | B 120 0 120 127 127 127 1 204 204 204 0 103 | B 120 0 8 127 127 119 1 216 165 0 0 104 | 105 | C 0 1 0 106 | B 120 0 120 127 127 127 1 204 204 204 0 107 | 108 | C 0 0 1 109 | B 120 120 0 127 127 7 1 204 204 204 0 110 | B 120 120 120 127 127 127 1 204 204 204 0 111 | B 120 120 8 127 127 119 1 216 165 0 0 112 | 113 | C 0 0 0 114 | B 120 120 120 127 127 127 1 204 204 204 0 115 | 116 | C 3 3 1 117 | B 0 0 0 7 7 7 1 204 204 204 0 118 | B 0 0 120 7 7 127 1 204 204 204 0 119 | B 0 0 8 7 7 119 1 0 121 204 0 120 | 121 | C 3 3 0 122 | B 0 0 120 7 7 127 1 204 204 204 0 123 | 124 | C 2 3 1 125 | B 0 0 0 127 7 7 1 204 204 204 0 126 | B 0 0 8 7 7 127 1 216 204 204 0 127 | B 0 0 120 127 7 127 1 204 204 204 0 128 | B 8 0 8 127 7 119 1 0 121 204 0 129 | 130 | C 2 3 0 131 | B 0 0 120 127 7 127 1 204 204 204 0 132 | 133 | C 1 3 1 134 | B 120 0 0 127 7 7 1 204 204 204 0 135 | B 120 0 8 127 7 127 1 216 204 204 0 136 | B 120 0 120 127 7 127 1 204 204 204 0 137 | 138 | C 1 3 0 139 | B 120 0 120 127 7 127 1 204 204 204 0 140 | 141 | C 3 2 2 142 | B 0 0 0 7 7 7 1 204 204 204 0 143 | B 0 0 0 7 7 15 1 204 204 204 0 144 | B 0 8 0 7 127 7 1 204 204 204 0 145 | 146 | C 3 1 2 147 | B 0 0 0 7 127 7 1 204 204 204 0 148 | B 0 0 0 7 127 15 1 204 204 204 0 149 | 150 | C 3 0 2 151 | B 0 120 0 7 127 7 1 204 204 204 0 152 | B 0 120 0 7 127 15 1 204 204 204 0 153 | 154 | C 2 2 2 155 | B 0 0 0 127 7 7 1 204 204 204 0 156 | B 0 0 0 127 7 15 1 204 204 204 0 157 | B 0 8 0 127 127 7 1 204 204 204 0 158 | 159 | C 2 1 2 160 | B 0 0 0 127 127 7 1 204 204 204 0 161 | B 0 0 0 127 127 15 1 204 204 204 0 162 | 163 | C 2 0 2 164 | B 0 120 0 127 127 7 1 204 204 204 0 165 | B 0 120 0 127 127 15 1 204 204 204 0 166 | 167 | C 1 2 2 168 | B 0 0 0 127 7 7 1 204 204 204 0 169 | B 0 0 0 127 7 15 1 204 204 204 0 170 | B 120 8 0 127 127 7 1 204 204 204 0 171 | 172 | C 1 1 2 173 | B 0 0 0 127 127 7 1 204 204 204 0 174 | B 0 0 0 127 127 15 1 204 204 204 0 175 | B 40 48 0 55 63 7 0 204 204 204 255 176 | B 40 48 0 55 63 7 1 204 204 204 255 177 | 178 | C 1 0 2 179 | B 0 120 0 127 127 7 1 204 204 204 0 180 | B 0 120 0 127 127 15 1 204 204 204 0 181 | 182 | C 0 2 2 183 | B 120 0 0 127 7 7 1 204 204 204 0 184 | B 120 0 0 127 7 15 1 204 204 204 0 185 | 186 | C 0 1 2 187 | B 120 0 0 127 127 7 1 204 204 204 0 188 | B 120 0 0 127 127 15 1 204 204 204 0 189 | 190 | C 0 0 2 191 | B 120 120 0 127 127 7 1 204 204 204 0 192 | B 120 120 0 127 127 15 1 204 204 204 0 193 | 194 | C 3 3 2 195 | B 0 0 0 7 7 7 1 204 204 204 0 196 | 197 | C 2 3 2 198 | B 0 0 0 127 7 7 1 204 204 204 0 199 | 200 | C 1 3 2 201 | B 120 0 0 127 7 7 1 204 204 204 0 202 | 203 | -------------------------------------------------------------------------------- /FoxelEngine/Editor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Editor.h" 3 | 4 | using namespace MapEditor; 5 | using namespace GLSL; 6 | 7 | int Editor::gridDeep = 8; 8 | 9 | Editor::Editor(void) : GameMenu(){ 10 | playMode = false; 11 | controler = new Controler(); 12 | toolBox = new ToolBox(Vec2(0,0),Vec2(128,(float)Screen::getHeight())); 13 | brush = new BrushBox(); 14 | center = new Axes(); 15 | 16 | center->load(); 17 | 18 | Vec2 viewSize; 19 | viewSize.x = (float)(Screen::getWidth() / 2) - toolBox->getSize().x; 20 | viewSize.y = (float)(Screen::getHeight() / 2); 21 | views.push_back(new View(VIEW_RIGHT , Vec2( 0 + toolBox->getSize().x, 0 ), viewSize)); 22 | views.push_back(new View(VIEW_TOP , Vec2(viewSize.x + toolBox->getSize().x,viewSize.y), viewSize)); 23 | views.push_back(new View(VIEW_FRONT , Vec2(viewSize.x + toolBox->getSize().x, 0 ), viewSize)); 24 | views.push_back(new View(VIEW_3D , Vec2( 0 + toolBox->getSize().x, viewSize.y), viewSize)); 25 | 26 | colorPanel = new ColorPanel(Vec2(Screen::getWidth() - 128 ,Screen::getHeight()-220), Vec2(128,220)); 27 | brush->setColor(colorPanel->getColor()); 28 | } 29 | 30 | Editor::~Editor(void){ 31 | } 32 | 33 | void Editor::draw(){ 34 | Screen::load2DView(); 35 | toolBox->draw(); 36 | colorPanel->draw(); 37 | PM::useProg(PROGRAM_FOXEL); 38 | for(int i = 0; i < 4; i++){ 39 | views[i]->setUp(); 40 | views[i]->draw(); 41 | glDisable(GL_BLEND); 42 | glEnable(GL_DEPTH_TEST); 43 | FoxelManager::render(); 44 | PM::useProg(PROGRAM_BASIC); 45 | brush->draw(); 46 | center->render(); 47 | glEnable(GL_BLEND); 48 | glDisable(GL_DEPTH_TEST); 49 | } 50 | PM::useProg(PROGRAM_NULL); 51 | } 52 | 53 | void Editor::update(float* time){ 54 | Map::update(); 55 | toolBox->update(); 56 | bool mouseIsMoving = Screen::getMouseMotion().x != 0 || Screen::getMouseMotion().y != 0; 57 | 58 | if(controler->Grab || controler->midleMouseButton){ 59 | // stay on active view 60 | }else{ 61 | activeView = catchActiveView(); 62 | } 63 | if(controler->Tab){ 64 | if(playMode == true){ 65 | playMode = false; 66 | Screen::showMouse(); 67 | }else{ 68 | playMode = true; 69 | Screen::hideMouse(); 70 | } 71 | controler->Tab = false; 72 | } 73 | for(int i = 0; i < views.size(); i++){ 74 | views[i]->update(time); 75 | } 76 | 77 | // on 3D view 78 | if(playMode && mouseIsMoving){ 79 | views[3]->getPlayer()->catchMouseMotion(-Screen::getMouseMotion().x, Screen::getMouseMotion().y); 80 | } 81 | 82 | if(controler->Grab){ 83 | Screen::hideMouse(); 84 | if(controler->leftMouseButton){ 85 | brush->startPaint(); 86 | brush->setPaintID(1); 87 | }else if(controler->rightMouseButton){ 88 | brush->startPaint(); 89 | brush->setPaintID(0); 90 | }else{ 91 | brush->stopPaint(); 92 | } 93 | // Move Brush 94 | if(!controler->midleMouseButton && mouseIsMoving && activeView != NULL){ 95 | switch(activeView->getViewMode()){ 96 | case VIEW_TOP: brush->move(Vec3(-Screen::getMouseMotion().x / activeView->zoom,-Screen::getMouseMotion().y / activeView->zoom,0.0f)); break; 97 | case VIEW_FRONT: brush->move(Vec3(-Screen::getMouseMotion().x / activeView->zoom,0.0f,-Screen::getMouseMotion().y / activeView->zoom)); break; 98 | case VIEW_RIGHT: brush->move(Vec3(0.0f,Screen::getMouseMotion().x / activeView->zoom,-Screen::getMouseMotion().y / activeView->zoom)); break; 99 | } 100 | } 101 | 102 | } 103 | 104 | // color panel 105 | if(mouseIsMoving && controler->leftMouseButton && colorPanel->mouseIntersect()){ 106 | colorPanel->mouseInteraction(); 107 | brush->setColor(colorPanel->getColor()); 108 | } 109 | 110 | // Move View if midleMouse Button is pressed 111 | if(controler->midleMouseButton && mouseIsMoving && activeView != NULL){ 112 | activeView->moveViewPosition(Vec3(Screen::getMouseMotion().x, Screen::getMouseMotion().y,0)); 113 | } 114 | 115 | if(controler->wheelState != 0 && activeView != NULL){ 116 | activeView->addZoomValue((float)controler->wheelState); 117 | controler->wheelState = 0; 118 | } 119 | } 120 | 121 | void Editor::catchMouseClick(Vec2 pos){ 122 | 123 | } 124 | 125 | View* Editor::catchActiveView(){ 126 | for(int i = 0; i < views.size(); i++){ 127 | if((Screen::getMousePosition().x > views[i]->getPosition().x 128 | && Screen::getMousePosition().x < views[i]->getPosition().x + views[i]->getSize().x) 129 | && Screen::getMousePosition().y > views[i]->getPosition().y 130 | && Screen::getMousePosition().y < views[i]->getPosition().y + views[i]->getSize().y){ 131 | return views[i]; 132 | } 133 | } 134 | return NULL; 135 | } 136 | 137 | void Editor::resize(){ 138 | toolBox->resize(); 139 | 140 | Vec2 viewSize; 141 | viewSize.x = (float)(Screen::getWidth() / 2) - toolBox->getSize().x; 142 | viewSize.y = (float)(Screen::getHeight() / 2); 143 | views[0]->setPosition(Vec2(0 + toolBox->getSize().x, 0)); 144 | views[1]->setPosition(Vec2(viewSize.x + toolBox->getSize().x,viewSize.y)); 145 | views[2]->setPosition(Vec2(viewSize.x + toolBox->getSize().x, 0 )); 146 | views[3]->setPosition(Vec2( 0 + toolBox->getSize().x, viewSize.y)); 147 | 148 | for(int i = 0; i < views.size(); i++){ 149 | views[i]->setSize(viewSize); 150 | } 151 | 152 | colorPanel->resize(Vec2(Screen::getWidth() - 128 ,Screen::getHeight()-220)); 153 | } 154 | 155 | void Editor::catchKeyDown(SDLKey sym){ 156 | controler->catchKeyDown(sym); 157 | if(playMode) views[3]->getPlayer()->catchKeyDown(sym); 158 | } 159 | 160 | void Editor::catchKeyUp(SDLKey sym){ 161 | controler->catchKeyUp(sym); 162 | views[3]->getPlayer()->catchKeyUp(sym); 163 | } 164 | 165 | int Editor::getGridDeep(){ 166 | return gridDeep; 167 | } 168 | 169 | Controler* Editor::getControler(){ 170 | return controler; 171 | } -------------------------------------------------------------------------------- /FoxelEngine/Screen.cpp: -------------------------------------------------------------------------------- 1 | #include "Screen.h" 2 | #include "ShaderProgram.h" 3 | 4 | using namespace GLSL; 5 | 6 | float Screen::ar = 0; 7 | bool Screen::klickLeft = false; 8 | bool Screen::klickRight = false; 9 | bool Screen::isResized = false; 10 | int Screen::screenWidth = 0; 11 | int Screen::screenHeight = 0; 12 | Matrix4 Screen::ProjMatrix; 13 | Matrix4 Screen::ViewMatrix; 14 | 15 | Vec2 Screen::mousePosition = Vec2(); 16 | Vec2 Screen::mouseMotion = Vec2(); 17 | 18 | 19 | Screen::Screen(int w, int h, bool isFullscreen) 20 | { 21 | screenWidth = w; 22 | screenHeight = h; 23 | 24 | SDL_WM_SetCaption("Foxel Engine", 0); 25 | SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); 26 | SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); 27 | SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); 28 | SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); 29 | 30 | SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); 31 | SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); 32 | 33 | SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 8); 34 | SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 8); 35 | SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 8); 36 | SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 8); 37 | 38 | SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0); 39 | SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0); 40 | 41 | //SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); // vsync 42 | 43 | // Fenster erstellen 44 | if(isFullscreen){ 45 | screen = SDL_SetVideoMode(screenWidth,screenHeight,32,SDL_HWSURFACE | 46 | SDL_GL_DOUBLEBUFFER | SDL_OPENGL | SDL_RESIZABLE | 47 | SDL_FULLSCREEN); 48 | }else{ 49 | screen = SDL_SetVideoMode(screenWidth,screenHeight,32,SDL_HWSURFACE | 50 | SDL_GL_DOUBLEBUFFER | SDL_OPENGL | SDL_RESIZABLE); 51 | } 52 | if(screen == NULL){ 53 | std::cout << SDL_GetError(); 54 | getchar(); 55 | } 56 | 57 | resize(screenWidth,screenHeight); 58 | 59 | glEnable(GL_CULL_FACE); 60 | glEnable(GL_BLEND); 61 | glBlendFunc(GL_SRC_ALPHA, GL_ONE); 62 | } 63 | 64 | void Screen::resize(int w, int h){ 65 | isResized = true; 66 | screenWidth = w; 67 | screenHeight = h; 68 | 69 | ar =(float) screenWidth / (float) screenHeight; 70 | 71 | SDL_UpdateRect(0,0,0,0,0); 72 | 73 | glClearColor(0.1f, 0.1f, 0.1f, 0.1f); 74 | glViewport(0, 0, screenWidth, screenHeight); 75 | glMatrixMode(GL_PROJECTION); 76 | glEnable(GL_TEXTURE_2D); 77 | } 78 | 79 | void Screen::load3DView(){ 80 | glDisable(GL_BLEND); 81 | glEnable(GL_DEPTH_TEST); 82 | glViewport(0,0,screenWidth,screenHeight); 83 | buildProjectionMatrix(75, ar, 1.0, 2500.0); 84 | } 85 | 86 | void Screen::load2DView(){ 87 | glMatrixMode(GL_PROJECTION); 88 | glLoadIdentity(); 89 | glViewport(0, 0, screenWidth, screenHeight); 90 | glOrtho(0, screenWidth, 0, screenHeight , -128, 128); 91 | glMatrixMode(GL_MODELVIEW); 92 | glLoadIdentity(); 93 | } 94 | 95 | void Screen::updateViewMatix(){ 96 | glUniformMatrix4fv(PM::getActiveUnifLoc("viewMatrix"), 1, GL_FALSE, ViewMatrix.matrix); 97 | } 98 | 99 | void Screen::updateProjMatix(){ 100 | glUniformMatrix4fv(PM::getActiveUnifLoc("projMatrix"), 1, GL_FALSE, ProjMatrix.matrix); 101 | } 102 | 103 | void Screen::buildProjectionMatrix(float fov, float ratio, float nearPlane, float farPlane) { 104 | float f = 1.0f / tan (fov * ( (float)M_PI / 360.0f)); 105 | 106 | ProjMatrix = Matrix4::Identity(); 107 | ProjMatrix.matrix[0] = f / ratio; 108 | ProjMatrix.matrix[1 * 4 + 1] = f; 109 | ProjMatrix.matrix[2 * 4 + 2] = (farPlane + nearPlane) / (nearPlane - farPlane); 110 | ProjMatrix.matrix[3 * 4 + 2] = (2.0f * farPlane * nearPlane) / (nearPlane - farPlane); 111 | ProjMatrix.matrix[2 * 4 + 3] = -1.0f; 112 | ProjMatrix.matrix[3 * 4 + 3] = 0.0f; 113 | 114 | glUniformMatrix4fv(PM::getActiveUnifLoc("projMatrix"), 1, GL_FALSE, ProjMatrix.matrix); 115 | } 116 | 117 | void Screen::buildOrthoMatrix(float left, float right, float bottom, float top, float nearPlane, float farPlane){ 118 | ProjMatrix = Matrix4::Identity(); 119 | ProjMatrix.matrix[ 0] = 2.0f / (right - left); 120 | ProjMatrix.matrix[ 5] = 2.0f / (top - bottom); 121 | ProjMatrix.matrix[10] = -2.0f / (farPlane - nearPlane); 122 | ProjMatrix.matrix[12] = -(right + left) / (right - left); 123 | ProjMatrix.matrix[13] = -(top + bottom) / (top - bottom); 124 | ProjMatrix.matrix[14] = -(farPlane + nearPlane) / (farPlane - nearPlane); 125 | glUniformMatrix4fv(PM::getActiveUnifLoc("projMatrix"), 1, GL_FALSE, ProjMatrix.matrix); 126 | } 127 | 128 | void Screen::catchMousePosition(Vec2 position){ 129 | position.y += Screen::getHeight() - 2 *position.y; 130 | mousePosition = position; 131 | } 132 | 133 | void Screen::swap(){ 134 | isResized = false; 135 | SDL_GL_SwapBuffers(); 136 | } 137 | 138 | void Screen::catchMouseMotion(Vec2 value){ 139 | value.x *= -1; 140 | mouseMotion = value; 141 | } 142 | 143 | void Screen::reset(){ 144 | mouseMotion.x = 0; 145 | mouseMotion.y = 0; 146 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 147 | } 148 | 149 | void Screen::showMouse(){ 150 | SDL_ShowCursor (SDL_ENABLE); 151 | SDL_WM_GrabInput (SDL_GRAB_OFF); 152 | } 153 | 154 | void Screen::hideMouse(){ 155 | SDL_ShowCursor (SDL_DISABLE); 156 | SDL_WM_GrabInput (SDL_GRAB_ON); 157 | } 158 | 159 | SDL_Surface* Screen::getSurface(){ 160 | return screen; 161 | } 162 | 163 | GLfloat* Screen::getProjectionMatrix(){ 164 | return ProjMatrix.matrix; 165 | } 166 | 167 | GLfloat* Screen::getViewMatrix(){ 168 | return ViewMatrix.matrix; 169 | } 170 | 171 | int Screen::getWidth(){ 172 | return screenWidth; 173 | } 174 | 175 | int Screen::getHeight(){ 176 | return screenHeight; 177 | } 178 | 179 | float Screen::getAspectRatio(){ 180 | return ar; 181 | } 182 | 183 | Vec2 Screen::getMousePosition(){ 184 | return mousePosition; 185 | } 186 | 187 | Vec2 Screen::getMouseMotion(){ 188 | return mouseMotion; 189 | } 190 | 191 | void Screen::setKlickLeft(bool boolean){ 192 | klickLeft = boolean; 193 | } 194 | 195 | void Screen::setKlickRight(bool boolean){ 196 | klickRight = boolean; 197 | } 198 | 199 | bool Screen::wasResized(){ 200 | return isResized; 201 | } 202 | 203 | bool Screen::isKlickLeft(){ 204 | return klickLeft; 205 | } 206 | 207 | bool Screen::isKlickRight(){ 208 | return klickRight; 209 | } 210 | 211 | Screen::~Screen(void) 212 | { 213 | } 214 | -------------------------------------------------------------------------------- /FoxelEngine/Maps/Test_Map5.foxel: -------------------------------------------------------------------------------- 1 | C 3 2 1 2 | B 0 0 0 7 7 7 1 204 204 204 0 3 | B 0 8 0 7 127 7 1 204 204 204 0 4 | B 0 0 120 7 7 127 1 204 204 204 0 5 | B 0 8 120 7 127 127 1 204 204 204 0 6 | B 0 120 8 7 127 119 1 0 121 204 0 7 | 8 | C 3 2 0 9 | B 0 0 120 7 7 127 1 204 204 204 0 10 | B 0 8 120 7 127 127 1 204 204 204 0 11 | 12 | C 3 1 1 13 | B 0 0 0 7 127 7 1 204 204 204 0 14 | B 0 0 120 7 127 127 1 204 204 204 0 15 | B 0 0 8 7 7 119 1 216 204 204 0 16 | 17 | C 3 1 0 18 | B 0 0 120 7 127 127 1 204 204 204 0 19 | 20 | C 3 0 1 21 | B 0 120 0 7 127 7 1 204 204 204 0 22 | B 0 120 120 7 127 127 1 204 204 204 0 23 | B 0 120 8 7 127 119 1 216 204 204 0 24 | 25 | C 3 0 0 26 | B 0 120 120 7 127 127 1 204 204 204 0 27 | 28 | C 2 2 1 29 | B 0 0 0 127 7 7 1 204 204 204 0 30 | B 0 8 0 127 127 7 1 204 204 204 0 31 | B 0 0 120 127 7 127 1 204 204 204 0 32 | B 0 0 8 7 7 119 1 216 204 204 0 33 | B 0 8 8 7 127 127 1 216 204 204 0 34 | B 0 8 120 127 127 127 1 204 204 204 0 35 | B 8 120 8 127 127 119 1 0 121 204 0 36 | B 48 80 120 63 95 127 1 255 255 255 255 37 | B 48 80 120 63 95 127 1 204 204 204 0 38 | B 48 80 120 63 95 127 1 204 204 204 0 39 | B 48 80 120 63 95 127 1 204 204 204 0 40 | B 48 80 120 63 95 127 1 204 204 204 0 41 | B 48 80 120 63 95 127 1 204 204 204 0 42 | B 48 80 120 63 95 127 1 204 204 204 0 43 | B 48 80 120 63 95 127 0 204 204 204 0 44 | B 48 80 120 63 95 127 1 204 204 204 0 45 | B 72 64 120 87 79 127 0 255 255 255 255 46 | B 72 64 120 87 79 127 1 255 255 255 255 47 | 48 | C 2 2 0 49 | B 0 0 120 127 7 127 1 204 204 204 0 50 | B 0 8 120 127 127 127 1 204 204 204 0 51 | 52 | C 2 1 1 53 | B 0 0 0 127 127 7 1 204 204 204 0 54 | B 0 0 120 127 127 127 1 204 204 204 0 55 | B 0 120 8 7 127 119 1 216 204 204 0 56 | B 0 0 8 127 7 119 1 216 204 204 0 57 | 58 | C 2 1 0 59 | B 0 0 120 127 127 127 1 204 204 204 0 60 | 61 | C 2 0 1 62 | B 0 120 0 127 127 7 1 204 204 204 0 63 | B 0 120 120 127 127 127 1 204 204 204 0 64 | B 0 120 8 127 127 119 1 216 204 204 0 65 | 66 | C 2 0 0 67 | B 0 120 120 127 127 127 1 204 204 204 0 68 | 69 | C 1 2 1 70 | B 0 0 0 127 7 7 1 204 204 204 0 71 | B 120 8 0 127 127 7 1 204 204 204 0 72 | B 0 0 120 127 7 127 1 204 204 204 0 73 | B 0 0 8 7 7 119 1 216 165 0 0 74 | B 8 0 8 127 7 119 1 216 204 204 0 75 | B 120 8 8 127 127 127 1 216 204 204 0 76 | B 120 8 120 127 127 127 1 204 204 204 0 77 | 78 | C 1 2 0 79 | B 0 0 120 127 7 127 1 204 204 204 0 80 | B 120 8 120 127 127 127 1 204 204 204 0 81 | 82 | C 1 1 1 83 | B 0 0 0 127 127 7 1 204 204 204 0 84 | B 0 0 120 127 127 127 1 204 204 204 0 85 | B 40 48 120 55 63 127 0 204 204 204 255 86 | B 40 48 120 55 63 127 1 204 204 204 255 87 | B 0 0 8 7 127 119 1 216 165 0 0 88 | B 8 120 8 127 127 119 1 216 204 204 0 89 | B 8 0 8 127 7 119 1 216 204 204 0 90 | 91 | C 1 1 0 92 | B 0 0 120 127 127 127 1 204 204 204 0 93 | 94 | C 1 0 1 95 | B 0 120 0 127 127 7 1 204 204 204 0 96 | B 0 120 120 127 127 127 1 204 204 204 0 97 | B 0 120 8 7 127 119 1 216 165 0 0 98 | B 8 120 8 127 127 119 1 216 204 204 0 99 | 100 | C 1 0 0 101 | B 0 120 120 127 127 127 1 204 204 204 0 102 | 103 | C 0 2 1 104 | B 120 0 0 127 7 7 1 204 204 204 0 105 | B 120 0 120 127 7 127 1 204 204 204 0 106 | B 120 0 8 127 7 119 1 216 165 0 0 107 | 108 | C 0 2 0 109 | B 120 0 120 127 7 127 1 204 204 204 0 110 | 111 | C 0 1 1 112 | B 120 0 0 127 127 7 1 204 204 204 0 113 | B 120 0 120 127 127 127 1 204 204 204 0 114 | B 120 0 8 127 127 119 1 216 165 0 0 115 | 116 | C 0 1 0 117 | B 120 0 120 127 127 127 1 204 204 204 0 118 | 119 | C 0 0 1 120 | B 120 120 0 127 127 7 1 204 204 204 0 121 | B 120 120 120 127 127 127 1 204 204 204 0 122 | B 120 120 8 127 127 119 1 216 165 0 0 123 | 124 | C 0 0 0 125 | B 120 120 120 127 127 127 1 204 204 204 0 126 | 127 | C 3 3 1 128 | B 0 0 0 7 7 7 1 204 204 204 0 129 | B 0 0 120 7 7 127 1 204 204 204 0 130 | B 0 0 8 7 7 119 1 0 121 204 0 131 | 132 | C 3 3 0 133 | B 0 0 120 7 7 127 1 204 204 204 0 134 | 135 | C 2 3 1 136 | B 0 0 0 127 7 7 1 204 204 204 0 137 | B 0 0 8 7 7 127 1 216 204 204 0 138 | B 0 0 120 127 7 127 1 204 204 204 0 139 | B 8 0 8 127 7 119 1 0 121 204 0 140 | 141 | C 2 3 0 142 | B 0 0 120 127 7 127 1 204 204 204 0 143 | 144 | C 1 3 1 145 | B 120 0 0 127 7 7 1 204 204 204 0 146 | B 120 0 8 127 7 127 1 216 204 204 0 147 | B 120 0 120 127 7 127 1 204 204 204 0 148 | 149 | C 1 3 0 150 | B 120 0 120 127 7 127 1 204 204 204 0 151 | 152 | C 3 2 2 153 | B 0 0 0 7 7 7 1 204 204 204 0 154 | B 0 0 0 7 7 15 1 204 204 204 0 155 | B 0 8 0 7 127 7 1 204 204 204 0 156 | 157 | C 3 1 2 158 | B 0 0 0 7 127 7 1 204 204 204 0 159 | B 0 0 0 7 127 15 1 204 204 204 0 160 | 161 | C 3 0 2 162 | B 0 120 0 7 127 7 1 204 204 204 0 163 | B 0 120 0 7 127 15 1 204 204 204 0 164 | 165 | C 2 2 2 166 | B 0 0 0 127 7 7 1 204 204 204 0 167 | B 0 0 0 127 7 15 1 204 204 204 0 168 | B 0 8 0 127 127 7 1 204 204 204 0 169 | B 48 80 0 63 95 7 1 255 255 255 255 170 | B 48 80 0 63 95 7 1 204 204 204 0 171 | B 48 80 0 63 95 7 1 204 204 204 0 172 | B 48 80 0 63 95 7 1 204 204 204 0 173 | B 48 80 0 63 95 7 1 204 204 204 0 174 | B 48 80 0 63 95 7 1 204 204 204 0 175 | B 48 80 0 63 95 7 1 204 204 204 0 176 | B 48 80 0 63 95 7 0 204 204 204 0 177 | B 48 80 0 63 95 7 1 204 204 204 0 178 | B 72 64 0 87 79 7 0 255 255 255 255 179 | B 72 64 0 87 79 7 1 255 255 255 255 180 | 181 | C 2 1 2 182 | B 0 0 0 127 127 7 1 204 204 204 0 183 | B 0 0 0 127 127 15 1 204 204 204 0 184 | 185 | C 2 0 2 186 | B 0 120 0 127 127 7 1 204 204 204 0 187 | B 0 120 0 127 127 15 1 204 204 204 0 188 | 189 | C 1 2 2 190 | B 0 0 0 127 7 7 1 204 204 204 0 191 | B 0 0 0 127 7 15 1 204 204 204 0 192 | B 120 8 0 127 127 7 1 204 204 204 0 193 | 194 | C 1 1 2 195 | B 0 0 0 127 127 7 1 204 204 204 0 196 | B 0 0 0 127 127 15 1 204 204 204 0 197 | B 40 48 0 55 63 7 0 204 204 204 255 198 | B 40 48 0 55 63 7 1 204 204 204 255 199 | 200 | C 1 0 2 201 | B 0 120 0 127 127 7 1 204 204 204 0 202 | B 0 120 0 127 127 15 1 204 204 204 0 203 | 204 | C 0 2 2 205 | B 120 0 0 127 7 7 1 204 204 204 0 206 | B 120 0 0 127 7 15 1 204 204 204 0 207 | 208 | C 0 1 2 209 | B 120 0 0 127 127 7 1 204 204 204 0 210 | B 120 0 0 127 127 15 1 204 204 204 0 211 | 212 | C 0 0 2 213 | B 120 120 0 127 127 7 1 204 204 204 0 214 | B 120 120 0 127 127 15 1 204 204 204 0 215 | 216 | C 3 3 2 217 | B 0 0 0 7 7 7 1 204 204 204 0 218 | 219 | C 2 3 2 220 | B 0 0 0 127 7 7 1 204 204 204 0 221 | 222 | C 1 3 2 223 | B 120 0 0 127 7 7 1 204 204 204 0 224 | B 120 0 0 127 7 7 1 204 204 204 0 225 | B 120 0 0 127 7 7 1 204 204 204 0 226 | 227 | -------------------------------------------------------------------------------- /FoxelEngine/FoxelManager.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "Foxel.h" 7 | #include "DrawableGameComponent.h" 8 | #include "Foxel_Interaction.h" 9 | #include "ShaderProgram.h" 10 | #include "Screen.h" 11 | #include "Vec3d.h" 12 | #include "Vec3.h" 13 | #include "Map.h" 14 | #include "BitCube.h" 15 | #include 16 | #include 17 | #include "Color.h" 18 | #include "Light.h" 19 | 20 | #define BUFFER_OFFSET(i) (reinterpret_cast(i)) // for VBO 21 | 22 | 23 | struct LightVertex{ 24 | GLubyte* position; 25 | GLbyte* normal; 26 | GLubyte* color; 27 | LightVertex(GLubyte* position, GLbyte* normal, GLubyte* color){ 28 | this->position = position; 29 | this->normal = normal; 30 | this->color = color; 31 | } 32 | }; 33 | 34 | struct MYVertex{ 35 | GLubyte x,y,z; 36 | GLbyte u,v,w; // normal 37 | GLubyte r,g,b; 38 | bool used; 39 | int indexofset; 40 | }; 41 | 42 | struct FoxelSetter{ 43 | char x,y,z; 44 | char id; 45 | }; 46 | 47 | static const char UP = 1; 48 | static const char DOWN = 2; 49 | static const char LEFT = 4; 50 | static const char RIGHT = 8; 51 | static const char FRONT = 16; 52 | static const char BACK = 32; 53 | 54 | static const int idUP = 1; 55 | static const int idDOWN = -1; 56 | static const int idFRONT = 1; 57 | static const int idBACK = -1; 58 | static const int idLEFT = 1; 59 | static const int idRIGHT = -1; 60 | 61 | // render modes 62 | static const char POINT_MODE = 1; 63 | static const char POLYGON_MODE = 2; 64 | static const float LIGHT_MAP_SIZE = 8; 65 | 66 | static char renderMode = POLYGON_MODE; 67 | static unsigned long vertexCount; 68 | static long polyCount; 69 | static const int BITSIZE = 128; 70 | static const int BITSIZE_129 = 129; 71 | static const int BITSIZE_129_X2 = BITSIZE_129*BITSIZE_129; 72 | static const int BITSIZE_X3 = BITSIZE*BITSIZE*BITSIZE; 73 | 74 | static int lodCenter[3]; 75 | 76 | static GLfloat debugChunkBoxV[] = {0.0f , 0.0f , 0.0f , 77 | 128.0f, 0.0f , 0.0f , 78 | 0.0f , 128.0f, 0.0f , 79 | 0.0f , 0.0f , 128.0f, 80 | 128.0f, 128.0f, 128.0f, 81 | 0.0f , 128.0f, 128.0f, 82 | 128.0f, 0.0f , 128.0f, 83 | 128.0f, 128.0f, 0.0f ,}; 84 | 85 | static GLuint debugChunkBoxI[] = {0,1, 0,2, 0,3, 4,5, 4,6, 4,7, 86 | 1,6, 2,5, 3,5, 2,7, 3,6, 1,7}; 87 | 88 | static bool firstInit = true; 89 | static bool running = true; 90 | static unsigned char globalLevelOfDetail; 91 | static std::vector vertexGridList; // vertexGridList for every thread 92 | static std::vector lightMapList; 93 | static std::vector threads; 94 | static boost::mutex setupQueueLock; 95 | static int NumberOfBounceLights; 96 | 97 | 98 | 99 | class FoxelManager{ 100 | friend class Map; 101 | // Z X Y 102 | BitCube* bitGrid; 103 | GLuint vbos[4]; 104 | GLuint vao; 105 | Foxel* foxel; 106 | Vec3d position; 107 | 108 | bool treadUse; 109 | bool needSetup; 110 | bool doneSetup; 111 | bool readyToDraw; 112 | bool steady; // unstady from putting in setupQueue to finished gpu upload 113 | GLubyte* vertices; 114 | GLubyte* colors; 115 | GLbyte* normals; 116 | GLuint* indices; 117 | unsigned int anzFoxel; 118 | unsigned int anzVertex; 119 | unsigned int anzIndex, constAnzIndex; 120 | unsigned int anzPolygon; 121 | unsigned char lod; // level of detail 122 | std::vector gi_Lights; 123 | std::vector directLights; 124 | std::queue setterBuffer; 125 | std::vectormyID; 126 | std::vectormyNeighborUp , myNeighborDown , 127 | myNeighborLeft , myNeighborRight, 128 | myNeighborBack , myNeighborFront; 129 | std::vector brushes; 130 | 131 | static float* BounceLights; 132 | 133 | 134 | public: 135 | FoxelManager(void); 136 | ~FoxelManager(void); 137 | static void deleteAll(); 138 | void setupFoxels(int threadID, bool genLightMap); 139 | static long getPolyCount(); 140 | long getVertexCount(); 141 | bool rayHit(Vec3* start, Vec3* end); 142 | static void startChunkThreads(int count); 143 | static void render(); 144 | static void switchDebug(); 145 | static void settingFoxel(Event::setFoxel* setterEvent); 146 | static void makeBlock(Vec3 start, Vec3 end, int id); 147 | static void addBrush(ChunkBrush brush); 148 | static void makeLine(Vec3 start, Vec3 direction, int id); 149 | static bool detectBulletHit(Vec3* position, Vec3* direction); 150 | static void update(); 151 | static void setGlobalLod(unsigned char nlod); 152 | static void setLodCenter(Vec3d center); 153 | 154 | 155 | 156 | static int getNumberOfCurrentChunkUpdates(); 157 | static int getNumberOfPendingGpuUploads(); 158 | static int getNumberOfDirectLights(); 159 | static int getNumberOfBounceLights(); 160 | static float* getBounceLightArray(); 161 | 162 | private: 163 | FoxelManager(int x, int y, int z); 164 | void addLightPoints(unsigned char x, unsigned char y, unsigned char z, char visState, MYVertex*** lightMap); 165 | void addPolygonVertices(int x, int y, int z, char visState, const unsigned char clod, std::vector* v_Index, MYVertex* vertexGrid); 166 | void packVertices(std::vector* v_Index, MYVertex* vertexGrid); 167 | void packLightMap(MYVertex*** lightMap); 168 | void buildBrush(Brush* brush); 169 | void clearSetterBuffer(); 170 | BitCube* generateLodGrid(const unsigned char clod); 171 | void uploadToGPU(); 172 | void setLevelOfDetail(unsigned char nlod); 173 | static void loadAllChunks(); 174 | static std::vector* getChunkList(); 175 | static std::vector tracingChunkID(Vec3 point); 176 | static void FoxelThreadLoop(int threadID); 177 | static void generateBounceLightArray(); 178 | static Vec3 tracingFoxelPositionInChunk(Vec3 point, std::vector chunkID); 179 | static void countBounceLights(); 180 | void setVertexToBrushColor(GLubyte* vertex, GLubyte* color, GLbyte* normal); 181 | Color detectBrushColor(Vec3* position); 182 | void illuminateDirectly(); 183 | void illuminateLightMap(); 184 | std::vector* getDirectLights(); 185 | std::vector getSuroundingDirectlights(); 186 | void initialise(); 187 | void drawChunk(); 188 | 189 | 190 | }; 191 | 192 | static std::vector chunks; 193 | static std::map,FoxelManager*> idMap; 194 | static std::queue setupQueue; 195 | static std::queue uploadQueue; 196 | -------------------------------------------------------------------------------- /FoxelEngine/Maps/Test_Map.foxel: -------------------------------------------------------------------------------- 1 | C 3 2 1 2 | B 0 0 0 7 7 7 1 204 204 204 0 3 | B 0 8 0 7 127 7 1 204 204 204 0 4 | B 0 0 120 7 7 127 1 204 204 204 0 5 | B 0 8 120 7 127 127 1 204 204 204 0 6 | B 0 120 8 7 127 119 1 0 121 204 0 7 | 8 | C 3 2 0 9 | B 0 0 120 7 7 127 1 204 204 204 0 10 | B 0 8 120 7 127 127 1 204 204 204 0 11 | 12 | C 3 1 1 13 | B 0 0 0 7 127 7 1 204 204 204 0 14 | B 0 0 120 7 127 127 1 204 204 204 0 15 | B 0 0 8 7 7 119 1 216 204 204 0 16 | 17 | C 3 1 0 18 | B 0 0 120 7 127 127 1 204 204 204 0 19 | 20 | C 3 0 1 21 | B 0 120 0 7 127 7 1 204 204 204 0 22 | B 0 120 120 7 127 127 1 204 204 204 0 23 | B 0 120 8 7 127 119 1 216 204 204 0 24 | 25 | C 3 0 0 26 | B 0 120 120 7 127 127 1 204 204 204 0 27 | 28 | C 2 2 1 29 | B 0 0 0 127 7 7 1 204 204 204 0 30 | B 0 8 0 127 127 7 1 204 204 204 0 31 | B 0 0 120 127 7 127 1 204 204 204 0 32 | B 0 0 8 7 7 119 1 216 204 204 0 33 | B 0 8 8 7 127 127 1 216 204 204 0 34 | B 0 8 120 127 127 127 1 204 204 204 0 35 | B 8 120 8 127 127 119 1 0 121 204 0 36 | B 48 80 120 63 95 127 1 204 204 204 0 37 | B 48 80 120 63 95 127 1 204 204 204 0 38 | B 48 80 120 63 95 127 1 204 204 204 0 39 | B 48 80 120 63 95 127 1 204 204 204 0 40 | B 48 80 120 63 95 127 1 204 204 204 0 41 | B 48 80 120 63 95 127 1 204 204 204 0 42 | B 48 80 120 63 95 127 0 204 204 204 0 43 | B 48 80 120 63 95 127 1 204 204 204 0 44 | B 72 64 120 87 79 127 0 255 255 255 255 45 | B 72 64 120 87 79 127 1 255 255 255 255 46 | 47 | C 2 2 0 48 | B 0 0 120 127 7 127 1 204 204 204 0 49 | B 0 8 120 127 127 127 1 204 204 204 0 50 | 51 | C 2 1 1 52 | B 0 0 0 127 127 7 1 204 204 204 0 53 | B 0 0 120 127 127 127 1 204 204 204 0 54 | B 0 120 8 7 127 119 1 216 204 204 0 55 | B 0 0 8 127 7 119 1 216 204 204 0 56 | B 56 56 120 71 71 127 0 255 255 255 255 57 | B 56 56 120 71 71 127 1 255 255 255 255 58 | B 96 16 8 127 47 23 1 255 38 0 0 59 | B 96 16 24 127 47 39 1 255 38 0 0 60 | 61 | C 2 1 0 62 | B 0 0 120 127 127 127 1 204 204 204 0 63 | 64 | C 2 0 1 65 | B 0 120 0 127 127 7 1 204 204 204 0 66 | B 0 120 120 127 127 127 1 204 204 204 0 67 | B 0 120 8 127 127 119 1 216 204 204 0 68 | 69 | C 2 0 0 70 | B 0 120 120 127 127 127 1 204 204 204 0 71 | 72 | C 1 2 1 73 | B 0 0 0 127 7 7 1 204 204 204 0 74 | B 120 8 0 127 127 7 1 204 204 204 0 75 | B 0 0 120 127 7 127 1 204 204 204 0 76 | B 0 0 8 7 7 119 1 216 165 0 0 77 | B 8 0 8 127 7 119 1 216 204 204 0 78 | B 120 8 8 127 127 127 1 216 204 204 0 79 | B 120 8 120 127 127 127 1 204 204 204 0 80 | 81 | C 1 2 0 82 | B 0 0 120 127 7 127 1 204 204 204 0 83 | B 120 8 120 127 127 127 1 204 204 204 0 84 | 85 | C 1 1 1 86 | B 0 0 0 127 127 7 1 204 204 204 0 87 | B 0 0 120 127 127 127 1 204 204 204 0 88 | B 40 48 120 55 63 127 0 204 204 204 255 89 | B 40 48 120 55 63 127 1 204 204 204 255 90 | B 0 0 8 7 127 119 1 216 165 0 0 91 | B 8 120 8 127 127 119 1 216 204 204 0 92 | B 8 0 8 127 7 119 1 216 204 204 0 93 | 94 | C 1 1 0 95 | B 0 0 120 127 127 127 1 204 204 204 0 96 | 97 | C 1 0 1 98 | B 0 120 0 127 127 7 1 204 204 204 0 99 | B 0 120 120 127 127 127 1 204 204 204 0 100 | B 0 120 8 7 127 119 1 216 165 0 0 101 | B 8 120 8 127 127 119 1 216 204 204 0 102 | 103 | C 1 0 0 104 | B 0 120 120 127 127 127 1 204 204 204 0 105 | 106 | C 0 2 1 107 | B 120 0 0 127 7 7 1 204 204 204 0 108 | B 120 0 120 127 7 127 1 204 204 204 0 109 | B 120 0 8 127 7 119 1 216 165 0 0 110 | 111 | C 0 2 0 112 | B 120 0 120 127 7 127 1 204 204 204 0 113 | 114 | C 0 1 1 115 | B 120 0 0 127 127 7 1 204 204 204 0 116 | B 120 0 120 127 127 127 1 204 204 204 0 117 | B 120 0 8 127 127 119 1 216 165 0 0 118 | 119 | C 0 1 0 120 | B 120 0 120 127 127 127 1 204 204 204 0 121 | 122 | C 0 0 1 123 | B 120 120 0 127 127 7 1 204 204 204 0 124 | B 120 120 120 127 127 127 1 204 204 204 0 125 | B 120 120 8 127 127 119 1 216 165 0 0 126 | 127 | C 0 0 0 128 | B 120 120 120 127 127 127 1 204 204 204 0 129 | 130 | C 3 3 1 131 | B 0 0 0 7 7 7 1 204 204 204 0 132 | B 0 0 120 7 7 127 1 204 204 204 0 133 | B 0 0 8 7 7 119 1 0 121 204 0 134 | 135 | C 3 3 0 136 | B 0 0 120 7 7 127 1 204 204 204 0 137 | 138 | C 2 3 1 139 | B 0 0 0 127 7 7 1 204 204 204 0 140 | B 0 0 8 7 7 127 1 216 204 204 0 141 | B 0 0 120 127 7 127 1 204 204 204 0 142 | B 8 0 8 127 7 119 1 0 121 204 0 143 | 144 | C 2 3 0 145 | B 0 0 120 127 7 127 1 204 204 204 0 146 | 147 | C 1 3 1 148 | B 120 0 0 127 7 7 1 204 204 204 0 149 | B 120 0 8 127 7 127 1 216 204 204 0 150 | B 120 0 120 127 7 127 1 204 204 204 0 151 | 152 | C 1 3 0 153 | B 120 0 120 127 7 127 1 204 204 204 0 154 | 155 | C 3 2 2 156 | B 0 0 0 7 7 7 1 204 204 204 0 157 | B 0 0 0 7 7 15 1 204 204 204 0 158 | B 0 8 0 7 127 7 1 204 204 204 0 159 | 160 | C 3 1 2 161 | B 0 0 0 7 127 7 1 204 204 204 0 162 | B 0 0 0 7 127 15 1 204 204 204 0 163 | 164 | C 3 0 2 165 | B 0 120 0 7 127 7 1 204 204 204 0 166 | B 0 120 0 7 127 15 1 204 204 204 0 167 | 168 | C 2 2 2 169 | B 0 0 0 127 7 7 1 204 204 204 0 170 | B 0 0 0 127 7 15 1 204 204 204 0 171 | B 0 8 0 127 127 7 1 204 204 204 0 172 | B 48 80 0 63 95 7 1 255 255 255 255 173 | B 48 80 0 63 95 7 1 204 204 204 0 174 | B 48 80 0 63 95 7 1 204 204 204 0 175 | B 48 80 0 63 95 7 1 204 204 204 0 176 | B 48 80 0 63 95 7 1 204 204 204 0 177 | B 48 80 0 63 95 7 1 204 204 204 0 178 | B 48 80 0 63 95 7 1 204 204 204 0 179 | B 48 80 0 63 95 7 0 204 204 204 0 180 | B 48 80 0 63 95 7 1 204 204 204 0 181 | B 72 64 0 87 79 7 0 255 255 255 255 182 | B 72 64 0 87 79 7 1 255 255 255 255 183 | 184 | C 2 1 2 185 | B 0 0 0 127 127 7 1 204 204 204 0 186 | B 0 0 0 127 127 15 1 204 204 204 0 187 | B 56 56 0 71 71 7 0 255 255 255 255 188 | B 56 56 0 71 71 7 1 255 255 255 255 189 | 190 | C 2 0 2 191 | B 0 120 0 127 127 7 1 204 204 204 0 192 | B 0 120 0 127 127 15 1 204 204 204 0 193 | 194 | C 1 2 2 195 | B 0 0 0 127 7 7 1 204 204 204 0 196 | B 0 0 0 127 7 15 1 204 204 204 0 197 | B 120 8 0 127 127 7 1 204 204 204 0 198 | 199 | C 1 1 2 200 | B 0 0 0 127 127 7 1 204 204 204 0 201 | B 0 0 0 127 127 15 1 204 204 204 0 202 | B 40 48 0 55 63 7 0 204 204 204 255 203 | B 40 48 0 55 63 7 1 204 204 204 255 204 | 205 | C 1 0 2 206 | B 0 120 0 127 127 7 1 204 204 204 0 207 | B 0 120 0 127 127 15 1 204 204 204 0 208 | 209 | C 0 2 2 210 | B 120 0 0 127 7 7 1 204 204 204 0 211 | B 120 0 0 127 7 15 1 204 204 204 0 212 | 213 | C 0 1 2 214 | B 120 0 0 127 127 7 1 204 204 204 0 215 | B 120 0 0 127 127 15 1 204 204 204 0 216 | 217 | C 0 0 2 218 | B 120 120 0 127 127 7 1 204 204 204 0 219 | B 120 120 0 127 127 15 1 204 204 204 0 220 | 221 | C 3 3 2 222 | B 0 0 0 7 7 7 1 204 204 204 0 223 | 224 | C 2 3 2 225 | B 0 0 0 127 7 7 1 204 204 204 0 226 | 227 | C 1 3 2 228 | B 120 0 0 127 7 7 1 204 204 204 0 229 | B 120 0 0 127 7 7 1 204 204 204 0 230 | B 120 0 0 127 7 7 1 204 204 204 0 231 | B 120 0 0 127 7 7 1 204 204 204 0 232 | 233 | -------------------------------------------------------------------------------- /FoxelEngine/PostProcessor.cpp: -------------------------------------------------------------------------------- 1 | #include "PostProcessor.h" 2 | #include "Screen.h" 3 | #include "Config.h" 4 | #include "ShaderProgram.h" 5 | #include "FoxelManager.h" 6 | 7 | using namespace GLSL; 8 | 9 | PostProcessor::PostProcessor(void) 10 | { 11 | } 12 | 13 | 14 | PostProcessor::~PostProcessor(void) 15 | { 16 | } 17 | 18 | bool PostProcessor::load(){ 19 | glGenFramebuffers(1,&framebuffer); 20 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); 21 | 22 | 23 | //------------------------------------------------------------------------------------------------------------------- 24 | // RGB - Texture 25 | glGenTextures(1,&renderedTexture); 26 | glBindTexture(GL_TEXTURE_2D, renderedTexture); 27 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, Screen::getWidth(), Screen::getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, 0); 28 | 29 | // Filtering for RGB - Texture 30 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 31 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 32 | //------------------------------------------------------------------------------------------------------------------- 33 | 34 | 35 | //------------------------------------------------------------------------------------------------------------------- 36 | // RGB - Normal Texture 37 | glGenTextures(1,&normalTexture); 38 | glBindTexture(GL_TEXTURE_2D, normalTexture); 39 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB10, Screen::getWidth(), Screen::getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, 0); 40 | 41 | // Filtering for RGB - Normal Texture 42 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 43 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 44 | //------------------------------------------------------------------------------------------------------------------- 45 | 46 | 47 | //------------------------------------------------------------------------------------------------------------------- 48 | // RGB - Position Texture 49 | glGenTextures(1,&positionTexture); 50 | glBindTexture(GL_TEXTURE_2D, positionTexture); 51 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F, Screen::getWidth(), Screen::getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, 0); 52 | 53 | // Filtering for RGB - Position Texture 54 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 55 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 56 | //------------------------------------------------------------------------------------------------------------------- 57 | 58 | 59 | //------------------------------------------------------------------------------------------------------------------- 60 | // Depth Texture 61 | glGenRenderbuffers(1, &depthrenderbuffer); 62 | glBindRenderbuffer(GL_RENDERBUFFER, depthrenderbuffer); 63 | glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT,Screen::getWidth(), Screen::getHeight()); 64 | glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthrenderbuffer); 65 | glGenTextures(1, &depthTexture); 66 | glBindTexture(GL_TEXTURE_2D, depthTexture); 67 | glTexImage2D(GL_TEXTURE_2D, 0,GL_DEPTH_COMPONENT32, Screen::getWidth(), Screen::getHeight(), 0,GL_DEPTH_COMPONENT, GL_FLOAT, 0); 68 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 69 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 70 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 71 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 72 | //------------------------------------------------------------------------------------------------------------------- 73 | 74 | 75 | // setting up 76 | glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, renderedTexture, 0); 77 | glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, normalTexture, 0); 78 | glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, positionTexture, 0); 79 | glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthTexture, 0); 80 | 81 | GLenum drawBuffers[3] = {GL_COLOR_ATTACHMENT0,GL_COLOR_ATTACHMENT1,GL_COLOR_ATTACHMENT2}; 82 | glDrawBuffers(3, drawBuffers); 83 | 84 | if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE){ 85 | return false; 86 | } 87 | 88 | // Quad 89 | glGenBuffers(1,&quad_vertexbuffer); 90 | glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); 91 | glBufferData(GL_ARRAY_BUFFER, sizeof(g_quad_vertex_buffer_data), g_quad_vertex_buffer_data, GL_STATIC_DRAW); 92 | 93 | return true; 94 | } 95 | 96 | void PostProcessor::setupToDraw(){ 97 | if(Screen::wasResized()){ 98 | load(); 99 | } 100 | 101 | generateBounceLightTexture(); 102 | 103 | glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); 104 | glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 105 | } 106 | 107 | void PostProcessor::draw(){ 108 | 109 | glBindFramebuffer(GL_FRAMEBUFFER, 0); 110 | glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 111 | 112 | PM::useProg(PROGRAM_POST); 113 | 114 | // Activate and Bind Textures 115 | glActiveTexture(GL_TEXTURE0); 116 | glBindTexture(GL_TEXTURE_2D, renderedTexture); 117 | glActiveTexture(GL_TEXTURE1); 118 | glBindTexture(GL_TEXTURE_2D, normalTexture); 119 | glActiveTexture(GL_TEXTURE2); 120 | glBindTexture(GL_TEXTURE_2D, positionTexture); 121 | 122 | glActiveTexture(GL_TEXTURE3); 123 | glBindTexture(GL_TEXTURE_2D, depthTexture); 124 | 125 | glActiveTexture(GL_TEXTURE4); 126 | glBindTexture(GL_TEXTURE_1D, bounceLightTexture); 127 | 128 | // Set our "renderedTexture" sampler to user Texture Unit 0 129 | glUniform1i(PM::getActiveUnifLoc("renderedTexture"), 0); 130 | glUniform1i(PM::getActiveUnifLoc("normalTexture"), 1); 131 | glUniform1i(PM::getActiveUnifLoc("positionTexture"), 2); 132 | glUniform1i(PM::getActiveUnifLoc("depthTexture"), 3); 133 | glUniform1i(PM::getActiveUnifLoc("bounceTexture"), 4); 134 | 135 | int displayMode; 136 | switch(Config::getDisplayMode()){ 137 | case DisplayMode::DISPLAY_QUAD: displayMode = 1; break; 138 | case DisplayMode::DISPLAY_WITHOUT_RAD: displayMode = 2; break; 139 | default: displayMode = 0; 140 | } 141 | glUniform1i(PM::getActiveUnifLoc("displayMode"), displayMode); 142 | glUniform1i(PM::getActiveUnifLoc("bounceLightCount"), FoxelManager::getNumberOfBounceLights()); 143 | glUniform2f(PM::getActiveUnifLoc("screen"),(float)Screen::getWidth(), (float) Screen::getHeight()); 144 | 145 | // 1rst attribute buffer : vertices 146 | glEnableVertexAttribArray(0); 147 | glBindBuffer(GL_ARRAY_BUFFER, quad_vertexbuffer); 148 | glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,0,(void*)0); 149 | 150 | // Draw the triangle ! 151 | glDrawArrays(GL_TRIANGLES, 0, 6); // From index 0 to 3 -> 1 triangle 152 | 153 | glDisableVertexAttribArray(0); 154 | glActiveTexture(GL_TEXTURE0); 155 | glBindTexture(GL_TEXTURE_2D, 0); 156 | glActiveTexture(GL_TEXTURE1); 157 | glBindTexture(GL_TEXTURE_2D, 0); 158 | glActiveTexture(GL_TEXTURE2); 159 | glBindTexture(GL_TEXTURE_2D, 0); 160 | glActiveTexture(GL_TEXTURE3); 161 | glBindTexture(GL_TEXTURE_2D, 0); 162 | glActiveTexture(GL_TEXTURE4); 163 | glBindTexture(GL_TEXTURE_2D, 0); 164 | } 165 | 166 | void PostProcessor::generateBounceLightTexture(){ 167 | //glClampColor(GL_CLAMP_READ_COLOR, GL_FALSE); 168 | //glClampColor(GL_CLAMP_VERTEX_COLOR, GL_FALSE); 169 | //glClampColor(GL_CLAMP_FRAGMENT_COLOR, GL_FALSE); 170 | 171 | 172 | glGenTextures(1,&bounceLightTexture); 173 | glBindTexture(GL_TEXTURE_1D, bounceLightTexture); 174 | glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB16F, FoxelManager::getNumberOfBounceLights() * 3,0,GL_RGB,GL_FLOAT, FoxelManager::getBounceLightArray()); 175 | 176 | // Filtering for RGB - Texture 177 | glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 178 | glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 179 | } -------------------------------------------------------------------------------- /FoxelEngine/FoxelEngine.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Debug 10 | x64 11 | 12 | 13 | Release 14 | Win32 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | {491E58BB-ACA8-43DE-BC54-B39A7536F803} 23 | FoxelEngine 24 | FoxelEngine 25 | 26 | 27 | 28 | Application 29 | true 30 | MultiByte 31 | 32 | 33 | Application 34 | true 35 | MultiByte 36 | 37 | 38 | Application 39 | false 40 | true 41 | MultiByte 42 | 43 | 44 | Application 45 | false 46 | true 47 | MultiByte 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | C:\Program Files %28x86%29\Microsoft SDKs\Windows\v7.0A\Include;$(IncludePath) 67 | 68 | 69 | C:\Program Files %28x86%29\Microsoft SDKs\Windows\v7.0A\Include;C:\Program Files %28x86%29\boost;$(IncludePath) 70 | Foxel Engine Debug 71 | ..\..\..\..\Release\Debug 72 | ..\..\..\..\Release\temp debug 73 | C:\Program Files %28x86%29\boost\lib64;$(LibraryPath) 74 | 75 | 76 | C:\Program Files %28x86%29\Microsoft SDKs\Windows\v7.0A\Include;$(IncludePath) 77 | 78 | 79 | C:\Program Files %28x86%29\Microsoft SDKs\Windows\v7.0A\Include;C:\Program Files %28x86%29\boost;$(IncludePath) 80 | ..\..\..\..\Release\Ausgabe\ 81 | ..\..\..\..\Release\temp\ 82 | Foxel Engine 83 | C:\Program Files %28x86%29\boost\lib64;$(LibraryPath) 84 | 85 | 86 | 87 | Level3 88 | Disabled 89 | 90 | 91 | true 92 | glew32.lib;freeglut.lib;SDL.lib;%(AdditionalDependencies) 93 | 94 | 95 | 96 | 97 | Level3 98 | Disabled 99 | 100 | 101 | true 102 | glew32.lib;freeglut.lib;SDL.lib;%(AdditionalDependencies) 103 | 104 | 105 | 106 | 107 | Level3 108 | MaxSpeed 109 | true 110 | true 111 | 112 | 113 | true 114 | true 115 | true 116 | glew32.lib;freeglut.lib;SDL.lib;%(AdditionalDependencies) 117 | 118 | 119 | 120 | 121 | Level3 122 | MaxSpeed 123 | true 124 | true 125 | false 126 | true 127 | false 128 | Fast 129 | MultiThreadedDLL 130 | false 131 | 132 | 133 | true 134 | true 135 | true 136 | glew32.lib;freeglut.lib;SDL.lib;%(AdditionalDependencies) 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | --------------------------------------------------------------------------------