typedef unsigned int uint;
+
+
Game::Game() : playing(true)
{
srand((int)time(NULL));
Scene* tmp_Scene = new Scene(0, 0, Graphix::getWindowWidth(), Graphix::getWindowHeight(), 45, 0.1f, 15, vec3(0.0f, 0.0f, 0.f));
layer[0] = tmp_Scene;
+
+ //SKYBOX! ---------------------------
+ // tmp_Scene->addObject(new SceneObject(shaderSky, glm::mat4(1.0f), "SkyBox.dae", "skybox.jpg"));
+ //Message::info("Error from before?");
+ //Graphix::getGlError();
+ //skybox = new Shader("skybox_VS.hlsl", "skybox_FS.hlsl");
+ //Message::info("Creating SkyBox Shader");
+ //Graphix::getGlError();
+ //SkyBox = new SceneObject(skybox, mat4(1.f), "SkyBox.dae", "skybox_CUBE.jpg");
+ //Message::info("Creating SkyBox SceneObject"); rotate((float)M_PI_2, vec3(1.f, 0.f, 0.f))
+ //Graphix::getGlError();
+ //Message::info("Done");
+
+ //tmp_Scene->addObject(new SceneObject(shader1, rotate((float)M_PI_2,vec3(1.f,0.f,0.f)), "SkyBox.dae", "skybox.jpg"));
+
+ //tmp_Scene->addObject(SkyBox);
+ //SKYBOX! ----------------------------
+
//Allg Shader
Shader* shader1 = new Shader("basicTexture_VS.hlsl", "lightingTexture_FS.hlsl");
- Shader* shaderSky = new Shader("skybox_VS.hlsl", "skybox_FS.hlsl");
+// Shader* shaderSky = new Shader("skybox_VS.hlsl", "skybox_FS.hlsl");
//Player
- SceneObject* tmp_playerObject = new SceneObject(shader1, translate(vec3(1.f, 0.f, 1.f)), "Player.dae", "model_player.png");
+ SceneObject* tmp_playerObject = new SceneObject(shader1, translate(vec3(1.f, 0.f, 1.f)), "Player.dae", "model_player_2D.png");
//tmp_playerObject->setIntelligenz(new PlayerI(tmp_playerObject));
tmp_Scene->addObject(tmp_playerObject);
// //cout << ((float)(rand() % (size*steps * 2)) / steps - size) << ((float)(rand() % (size*steps * 2)) / steps - size) << ((float)(rand() % (size*steps * 2)) / steps - size) << endl;
//}
//ein Gegner
- tmp_Scene->addObject(new SceneObject(shader1, glm::mat4(1.0f), "Player.dae", "model_player.png"));
+ //tmp_Scene->addObject(new SceneObject(shader1, glm::mat4(1.0f), "Player.dae", "model_player.png"));
//tmp_Scene->addObject(new SceneObject(shader1, translate(vec3(-1.f, 2.f, -2.f)), "../models/box/box.dae", "../Textures/sky_withstars.png"));
//tmp_Scene->addObject(new SceneObject(shader1, translate(vec3(1.f, 3.f, -2.f)), "../models/cow/cow.dae", "../models/cow/texture.jpg"));
//import("level_test.dae", tmp_Scene, shader1);
- //tmp_Scene->addObject(new SceneObject(shaderSky, glm::mat4(1.0f), "SkyBox.dae", "model_skybox.png"));
+
+
}
Graphix::swap();
- GLenum error = glGetError();
-
- if (error != GL_NO_ERROR) {
- switch (error) {
- case GL_INVALID_ENUM:
- Message::error((string)"GL: enum argument out of range.");
- break;
- case GL_INVALID_VALUE:
- Message::error((string)"GL: Numeric argument out of range.");
- break;
- case GL_INVALID_OPERATION:
- Message::error((string)"GL: Operation illegal in current state.");
- break;
- case GL_INVALID_FRAMEBUFFER_OPERATION:
- Message::error((string)"GL: Framebuffer object is not complete.");
- break;
- case GL_OUT_OF_MEMORY:
- Message::error((string)"GL: Not enough memory left to execute command.");
- break;
- default:
- Message::error((string)"GL: Unknown error.");
- }
- }
+ Graphix::getGlError();
+
+// system("pause");
}
}
void Game::draw() const
{
if (playing){
+
+ //viewPort->bindView(*i, lookat->getPosition() + vec3(0.0f, 1.0f, 0.0f));
+ //SkyBox->draw();
+
for (auto i = layer.begin(); i != layer.end(); ++i){
(*i).second->draw();
}
void draw() const;
//bool import(const string &path, Scene *scene, Shader* shader);
+ Shader* skybox;
+ SceneObject* SkyBox;
+
};
//SDL_SetWindowGrab(sdl_window, SDL_TRUE);
//SDL_ShowCursor(SDL_DISABLE);
glEnable(GL_COLOR_MATERIAL);
+ glEnable(GL_TEXTURE_CUBE_MAP);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_CULL_FACE);
SDL_Quit();
}
+unsigned int Graphix::getGlError()
+{
+ GLenum error = glGetError();
+
+ if (error != GL_NO_ERROR) {
+ switch (error) {
+ case GL_INVALID_ENUM:
+ Message::error((string)"GL: enum argument out of range.");
+ break;
+ case GL_INVALID_VALUE:
+ Message::error((string)"GL: Numeric argument out of range.");
+ break;
+ case GL_INVALID_OPERATION:
+ Message::error((string)"GL: Operation illegal in current state.");
+ break;
+ case GL_INVALID_FRAMEBUFFER_OPERATION:
+ Message::error((string)"GL: Framebuffer object is not complete.");
+ break;
+ case GL_OUT_OF_MEMORY:
+ Message::error((string)"GL: Not enough memory left to execute command.");
+ break;
+ default:
+ Message::error((string)"GL: Unknown error.");
+ }
+ }
+ return error;
+}
+
unsigned int Graphix::width = 1024;
unsigned int Graphix::height = 768;
static void cleanup();
static void clear();
+ static unsigned int getGlError();
+
private:
static unsigned int width;
static unsigned int height;
#include "Texture.h"
#include "../Message.h"
+#include "Graphix.h"
+
typedef unsigned int uint;
void Model::useModel(Shader* _shader) const
{
+ _shader->useShader();
uint vao = -1;
auto i = shader_map.find(*_shader);
if (i == shader_map.end())
vao = i->second;
glBindVertexArray(vao);
- _shader->useShader();
+
}
{
if (_texture != nullptr)
{
+ auto tmp = _shader->getUniformLocation("uColorTexture");
+ if (tmp < 0){
+ return;
+ }
int unit = 0;
_texture->bind(unit);
- glUniform1i(_shader->getUniformLocation("uColorTexture"), unit);
+ glUniform1i(tmp, unit);
}
}
void Model::useMMatrix(const mat4& _model, Shader* _shader) const
{
- glUniformMatrix4fv(_shader->getUniformLocation("uModel"), 1, GL_FALSE, value_ptr(_model));
+ int tmp = _shader->getUniformLocation("uModel");
+ if (tmp >= 0)
+ glUniformMatrix4fv(tmp, 1, GL_FALSE, value_ptr(_model));
}
void Model::drawModel(Shader* _shader, Texture* _texture, const mat4& _model) const
{
+ //Message::info("Error from before?");
+ //Graphix::getGlError();
useModel(_shader);
+ //Message::info("Model loading Coordinates");
+ //Graphix::getGlError();
useTexture(_texture, _shader);
+ //Message::info("Model loading Texture");
+ //Graphix::getGlError();
useMMatrix(_model, _shader);
+ //Message::info("Model loading MMatrix");
+ //Graphix::getGlError();
glDrawElements(GL_TRIANGLES, numfaces * 3, GL_UNSIGNED_INT, 0);
+ //Message::info("Model drawing Elements");
+ //Graphix::getGlError();
glBindVertexArray(0);
+ //system("pause");
}
void Model::drawModel() const
unsigned int Model::bindShader(Shader* _shader)
{
+ //Message::info("bindShader");
+ //Graphix::getGlError();
+ //Message::info("Do Stuff");
uint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
+ //Message::info("bindVAO");
+ //Graphix::getGlError();
+
bindBuffer(vertexBuffer, _shader->getAttribLocation("aPosition"));
+ //Message::info("aPosition");
+ //Graphix::getGlError();
bindBuffer(uvBuffer, _shader->getAttribLocation("aUV"), 2);
+ //Message::info("aUV");
+ //Graphix::getGlError();
bindBuffer(normalBuffer, _shader->getAttribLocation("aNormal"));
+ //Message::info("aNormal");
+ //Graphix::getGlError();
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
+ //Message::info("bindIndexBuffer");
+ //Graphix::getGlError();
glBindVertexArray(0);
shader_map[*_shader] = vao;
+ //Message::info("cleanUp");
+ //Graphix::getGlError();
+ //Message::info("Done");
+
return vao;
}
void Model::bindBuffer(const uint &buffer, const uint index, const uint dim)
{
+ //Falls index nicht gefunden werden konnte
+ if (index == (uint)-1)
+ {
+ Message::info("Model: BindBuffer wird ausgelassen da index fehlerhaft ist.");
+ return;
+ }
+
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glEnableVertexAttribArray(index);
glVertexAttribPointer(index, dim, GL_FLOAT, GL_FALSE, 0, 0);
for (auto i = ShaderSet->cbegin(); i != ShaderSet->cend(); ++i)
{
viewPort->bindView(*i,lookat->getPosition()+vec3(0.0f,1.0f,0.0f));
+
+ //don't know if this is really the right place to set the lighting
+ //add ambient light
+ GLfloat ambientcolor[] = { 0.5f, 0.5f, 0.5f, 1.0f };
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientcolor);
+
+ //add positioned light
+ GLfloat lightcolor0[] = { 1.5f, 1.5f, 1.5f, 1.0f };
+ GLfloat lightposition0[] = { 1.0f, 1.0f, 1.0f, 1.0f };
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, lightcolor0);
+ glLightfv(GL_LIGHT0, GL_POSITION, lightposition0);
}
+
- //don't know if this is really the right place to set the lighting
- //add ambient light
- GLfloat ambientcolor[] = { 0.5f, 0.5f, 0.5f, 1.0f };
- glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientcolor);
-
- //add positioned light
- GLfloat lightcolor0[] = { 1.5f, 1.5f, 1.5f, 1.0f };
- GLfloat lightposition0[] = { 1.0f, 1.0f, 1.0f, 1.0f };
- glLightfv(GL_LIGHT0, GL_DIFFUSE, lightcolor0);
- glLightfv(GL_LIGHT0, GL_POSITION, lightposition0);
#include "Scene.h"
#include "Texture.h"
-#define MODEL_contractionspeed 8.f
-#define MassSpeed_relation 3.f
-#define BOX_size 6
+#include "Graphix.h"
using std::string;
collision_ignore(false),
texture(nullptr)
{
+ //Message::info("Error from befor?");
+ //Graphix::getGlError();
new MetaModel(_modelpath);
- modelID = _shader->getUniformLocation("model");
+ //Message::info("Creating Model");
+ //Graphix::getGlError();
+ //modelID = _shader->getUniformLocation("model");
if (texturepath!="")
texture = new Texture(texturepath);
-
+ //Message::info("Creating SkyBox Shader");
+ //Graphix::getGlError();
+
bindShader(shader);
+ //Message::info("Binding Shader");
+ //Graphix::getGlError();
+ //Message::info("Done");
+
}
//SceneObject::SceneObject(Shader* _shader, mat4& _model, Model* model_obj, string texturepath) :
void setMatter(float);
mat4 model;
- __declspec(deprecated)
- unsigned int modelID;
+ //__declspec(deprecated)
+ //unsigned int modelID;
Shader* shader;
GLuint Shader::getAttribLocation(const string& name) const
{
- GLuint ind = glGetAttribLocation(handle, name.c_str());
+ int ind = glGetAttribLocation(handle, name.c_str());
if (ind < 0)
Message::info("GL_GetAttLoc: Kann '" + name + "' nicht finden.");
GLuint Shader::getUniformLocation(const string& name) const
{
- GLuint ind = glGetUniformLocation(handle, name.c_str());
+ int ind = glGetUniformLocation(handle, name.c_str());
if (ind < 0)
Message::info("GL_GetUniLoc: Kann '" + name + "' nicht finden.");
GLuint handle=-1;
auto type = _shaderPath.substr(_shaderPath.find_last_of('_') + 1);
GLenum shaderType;
+
if (type == "VS.hlsl"){
shaderType = GL_VERTEX_SHADER;
}
#include "FreeImage.h"
#include <iostream>
-using std::string;
-using std::cout;
-using std::endl;
+#include "../Message.h"
+#include "Graphix.h"
+using std::string;
-Texture::Texture(const string& _path) : path(_path), handle(-1)
+Texture::Texture(const string& _path) : path(_path), handle(-1), TEXTURE_TYPE(-1)
{
+ //Message::info("Error from before?");
+ //Graphix::getGlError();
+ //Message::info("Do some Stuff");
+
auto i = texture_map.find(_path);
if (i != texture_map.end())
{
glGenTextures(1, &handle);
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, handle);
+ auto path_type = path.substr(path.find_last_of("_")+1);
+ path_type = path_type.substr(0, path_type.find_first_of("."));
+
+ if (path_type == "CUBE")
+ {
+ TEXTURE_TYPE = GL_TEXTURE_CUBE_MAP;
+ }
+ else if (path_type == "2D")
+ {
+ TEXTURE_TYPE = GL_TEXTURE_2D;
+ }
+ else
+ {
+ Message::info("Texture : Undefined Type, was set to default (2D)");
+ TEXTURE_TYPE = GL_TEXTURE_2D;
+ }
+ glBindTexture(TEXTURE_TYPE, handle);
FREE_IMAGE_FORMAT format = FreeImage_GetFileType(("../textures/" + path).c_str());//Automatocally detects the format
if (format == FIF_UNKNOWN)
{
- cout << "Couldn't detect texture file format." << endl;
- system("pause");
- exit(-1);
+ Message::error("Texture: Couldn't detect texture file format.");
}
FIBITMAP* data = FreeImage_Load(format, ("../textures/" + path).c_str());
if (!data)
{
- cout << "Couldn't read texture file." << endl;
- system("pause");
- exit(-1);
+ Message::error("Texture: Couldn't read texture file.");
}
//FIBITMAP* temp = data;
data = FreeImage_ConvertTo32Bits(data);
if (!data)
{
- cout << "Couldn't convert texture file to bit format." << endl;
- system("pause");
- exit(-1);
+ Message::error("Texture: Couldn't convert texture file to bit format.");
}
//FreeImage_Unload(temp);
//unsigned int width, height;
//FIBITMAP *data = FreeImage_Load(FIF_PNG, path.c_str(), PNG_DEFAULT);
+ //Graphix::getGlError();
+// if (TEXTURE_TYPE == GL_TEXTURE_2D)
+ {
+ glTexImage2D(TEXTURE_TYPE, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*)FreeImage_GetBits(data));
+ //Message::info("TexImage");
+ //Graphix::getGlError();
+ //Message::info("Other Stuff");
+ glGenerateMipmap(TEXTURE_TYPE);
+ }
+// else if (TEXTURE_TYPE == GL_TEXTURE_CUBE_MAP)
+
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, (GLvoid*)FreeImage_GetBits(data));
- glGenerateMipmap(GL_TEXTURE_2D);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+ glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ if (TEXTURE_TYPE == -1)
+ {
+ glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(TEXTURE_TYPE, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
+ }
texture_map[_path] = handle;
+ //Graphix::getGlError();
+ //Message::info("Done");
+
}
Texture::~Texture()
void Texture::bind(int unit)
{
glActiveTexture(GL_TEXTURE0 + unit);
- glBindTexture(GL_TEXTURE_2D, handle);
+ glBindTexture(TEXTURE_TYPE, handle);
}
Texture::operator string() const
private:
unsigned int handle;
string path;
+ unsigned int TEXTURE_TYPE;
static str2int_map texture_map;
};
\ No newline at end of file
void ViewPort::bindView(Shader* shader, vec3 pos) const{
shader->useShader();
- glUniformMatrix4fv(shader->getUniformLocation("uProjection"), 1, false, value_ptr(projection));
- glUniformMatrix4fv(shader->getUniformLocation("uView"), 1, false, value_ptr(translate(view,-pos)));
+ int tmp = -1;
+
+ tmp = shader->getUniformLocation("uProjection");
+ if (tmp>=0)
+ glUniformMatrix4fv(tmp, 1, false, value_ptr(projection));
+ tmp = shader->getUniformLocation("uView");
+ if (tmp >= 0)
+ glUniformMatrix4fv(tmp, 1, false, value_ptr(translate(view,-pos)));
}
void ViewPort::rotateView(float angle_x, float angle_y){
void Message::error(string _msg)
{
cerr << currentDateTime() << " E " << _msg << endl;
- system("pause");
+// system("pause");
// exit(-1);
}
<author>Blender User</author>
<authoring_tool>Blender 2.73.0 commit date:2015-01-20, commit time:18:16, hash:bbf09d9</authoring_tool>
</contributor>
- <created>2015-04-16T10:05:45</created>
- <modified>2015-04-16T10:05:45</modified>
+ <created>2015-04-21T11:48:56</created>
+ <modified>2015-04-21T11:48:56</modified>
<unit name="meter" meter="1"/>
<up_axis>Z_UP</up_axis>
</asset>
<library_visual_scenes>
<visual_scene id="Scene" name="Scene">
<node id="Plane" name="Plane" type="NODE">
- <matrix sid="transform">2 0 0 0 0 2 0 0 0 0 2 0 0 0 0 1</matrix>
+ <matrix sid="transform">2 0 0 0 0 -8.74228e-8 -2 0 0 2 -8.74228e-8 0 0 0 0 1</matrix>
<instance_geometry url="#Plane-mesh"/>
</node>
</visual_scene>
void main(){
FragmentColor = texture(uColorTexture, eyeDirection);
+ //FragmentColor = vec4(eyeDirection, 0.5);
}
//Vertex Shader
#version 330
-in vec3 position;
-uniform mat4 projection;
-uniform mat4 model;
-uniform mat4 view;
+in vec3 aPosition;
+
+uniform mat4 uProjection;
+uniform mat4 uModel;
+uniform mat4 uView;
smooth out vec3 eyeDirection;
void main() {
- mat4 invProjection = inverse(projection);
- mat3 invModelview = mat3(1);// transpose(mat3(model));
- vec3 unprojected = (invProjection * vec4(position, 1)).xyz;
+ mat4 invProjection = inverse(uProjection);
+ mat3 invModelview = transpose(mat3(uView));
+ vec3 unprojected = (invProjection * vec4(aPosition, 1)).xyz;
eyeDirection = invModelview * unprojected;
+ //eyeDirection = unprojected;
+ //eyeDirection = aPosition;
- gl_Position = vec4(position,1);
+ gl_Position = vec4(aPosition,1);
}
\ No newline at end of file