Large diffs are not rendered by default.

@@ -31,6 +31,7 @@
#include <openlima/util/Color.hpp>
#include <openlima/graphics/PointLight.hpp>
#include <openlima/graphics/SpotLight.hpp>
#include "openlima/graphics/SimplePass.hpp"

using namespace openlima::graphics;
using namespace openlima::sil;
@@ -51,30 +52,33 @@ class MyWindow : public LimaWindow {
dtime lastMessage;
dtime time;
dtime amount;
SimplePass pass;

bool fpsMode;

MyWindow* other;

MyWindow(boost::shared_ptr<IRenderable> renderable,
const char* title, GLfloat* lightColor)
: LimaWindow(title, 640, 480) {
: LimaWindow(title, 640, 480),
pass(Color(0.0f, 0.0f, 0.0f, 1.0f),
Color(0.0f, 0.0f, 0.8f, 1.0f),
Color(1.0f, 1.0f, 1.0f, 1.0f),
Color(0.0f, 0.0f, 0.0f, 1.0f),
96.0f) {

camera = boost::make_shared<PerspectiveCamera>(OPENLIMA_REAL(90.0));
camera->position.z = 30;
env.setCamera(camera);

boost::shared_ptr<CachingRenderNode> node = boost::make_shared<CachingRenderNode>();
node->addChild(renderable);
env.getRenderNode().addChild(node);
env.getRenderNode().addChild(renderable);

fpsMode = false;
lastMessage = 5;
time = 0;
amount = 0;


glShadeModel(GL_SMOOTH);

env.setAmbientColor(Color(0.2f, 0.2f, 0.2f, 1.0f));

@@ -83,14 +87,14 @@ class MyWindow : public LimaWindow {
Vector3f(0, 0, -1),
OPENLIMA_REAL(0.0),
OPENLIMA_REAL(30.0),
Color(0, 0, 0, 1),
Color(1, 1, 1, 1),
Color(0, 0, 0, 1)
Color(0.2f, 0.2f, 0.2f, 1),
Color(1.0f, 1.0f, 1.0f, 1),
Color(1.0f, 1.0f, 1.0f, 1)
);

env.addLight(cameraLight);

env.addLight(
/*env.addLight(
boost::make_shared<PointLight>(
Vector3f(10, 0, 0),
Color(0, 0, 0, 1),
@@ -106,7 +110,7 @@ class MyWindow : public LimaWindow {
Color(0.4f, 0.7f, 0.4f, 1),
Color(0, 0, 0, 1)
)
);
);*/

other = NULL;

@@ -306,7 +310,9 @@ class MyWindow : public LimaWindow {
// You can skip the rendering if you neither call initializeRendering, nor finishRendering.
this->initializeRendering();

pass.setProperties();
env.render(Vector2i(this->getWidth(), this->getHeight()));
pass.unsetProperties();

this->finishRendering();
}
@@ -343,9 +349,16 @@ OPENLIMA_MAIN(int argc, char** argv) {
new FileResourceManager(resourcesDir.string()));

resourceManager->registerReader<StaticMesh>(boost::make_shared<WavefrontObjReader>());
boost::shared_ptr<IRenderable> renderable =
boost::shared_ptr<RenderNode> renderable = boost::make_shared<CachingRenderNode>();
boost::shared_ptr<IRenderable> randomObject =
resourceManager->getResource<StaticMesh>("randomObject.obj");

boost::shared_ptr<IRenderable> monkey =
resourceManager->getResource<StaticMesh>("monkey.obj");
boost::shared_ptr<RenderNode> monkeyTransfromer = boost::make_shared<TranslatingRenderNode>(Vector3f(5, 0, 0));
monkeyTransfromer->addChild(monkey);
renderable->addChild(randomObject);
renderable->addChild(monkeyTransfromer);

if(!renderable) {
std::cout << "Failed to load resource: \"./resources/randomObject.obj\"" << std::endl;
return 1;
@@ -0,0 +1,32 @@
// Copyright (C) 2011 Robert Boehm
// This file is part of openLima.
//
// You should have received a copy of the GNU Lesser General Public License
// along with openLima. If not, see: <http://www.gnu.org/licenses/>.

#ifndef OPENLIMA_GRAPHICS_IPASS_HPP
#define OPENLIMA_GRAPHICS_IPASS_HPP

#include <openlima/util/macros.hpp>
#include <openlima/util/types.hpp>


namespace openlima {
namespace graphics {

class IPass {
public:

OPENLIMA_DLL virtual ~IPass() {}


OPENLIMA_DLL virtual void setProperties() = 0;

OPENLIMA_DLL virtual void unsetProperties() = 0;

};

}
}

#endif /* OPENLIMA_GRAPHICS_IPASS_HPP */
Empty file.
@@ -0,0 +1,43 @@
// Copyright (C) 2011 Robert Boehm
// This file is part of openLima.
//
// You should have received a copy of the GNU Lesser General Public License
// along with openLima. If not, see: <http://www.gnu.org/licenses/>.

#ifndef OPENLIMA_GRAPHICS_SIMPLEPASS_HPP
#define OPENLIMA_GRAPHICS_SIMPLEPASS_HPP

#include <openlima/util/macros.hpp>
#include <openlima/util/types.hpp>
#include <openlima/util/Color.hpp>
#include <openlima/graphics/IPass.hpp>


namespace openlima {
namespace graphics {

class SimplePass : public IPass {
private:
float* ambient;
float* diffuse;
float* specular;
float* emission;
float shininess;

public:
OPENLIMA_DLL SimplePass(openlima::util::Color ambient, openlima::util::Color diffuse,
openlima::util::Color specular, openlima::util::Color emission, float shininess);

OPENLIMA_DLL virtual ~SimplePass();


OPENLIMA_DLL virtual void setProperties();

OPENLIMA_DLL virtual void unsetProperties();

};

}
}

#endif /* OPENLIMA_GRAPHICS_SIMPLEPASS_HPP */
@@ -41,6 +41,8 @@ namespace openlima {

public:

bool smoothShading;

/** The vertices. */
std::vector<openlima::util::Vector3f> vertices;

@@ -60,11 +62,13 @@ namespace openlima {
* @param normals The normals.
* @param vertexIndices The vertex indices.
* @param normalIndices The normal indices.
* @param smoothShading Determines if this mesh should be drawn with smooth shading.
*/
OPENLIMA_DLL StaticMesh(std::vector<openlima::util::Vector3f> vertices,
std::vector<openlima::util::Vector3f> normals,
std::vector<openlima::util::Vector3i> vertexIndices,
std::vector<openlima::util::Vector3i> normalIndices);
std::vector<openlima::util::Vector3i> normalIndices,
bool smoothShading = true);

/**
* Renders this static mesh.
@@ -0,0 +1,24 @@
// Copyright (C) 2011 Robert Boehm
// This file is part of openLima.
//
// You should have received a copy of the GNU Lesser General Public License
// along with openLima. If not, see: <http://www.gnu.org/licenses/>.

#ifndef OPENLIMA_GRAPHICS_WAVEFRONTOBJMATERIAL_HPP
#define OPENLIMA_GRAPHICS_WAVEFRONTOBJMATERIAL_HPP

#include <openlima/util/macros.hpp>
#include <openlima/graphics/Material.hpp>


namespace openlima {
namespace graphics {

class WavefrontObjMaterial : public Material {

};

}
}

#endif /* OPENLIMA_GRAPHICS_WAVEFRONTOBJMATERIAL_HPP */
@@ -0,0 +1,31 @@
// Copyright (C) 2011 Robert Boehm
// This file is part of openLima.
//
// You should have received a copy of the GNU Lesser General Public License
// along with openLima. If not, see: <http://www.gnu.org/licenses/>.

#ifndef OPENLIMA_GRAPHICS_WAVEFRONTOBJMATERIALLIBRARY_HPP
#define OPENLIMA_GRAPHICS_WAVEFRONTOBJMATERIALLIBRARY_HPP

#include <openlima/util/macros.hpp>
#include <map>
#include <string>
#include <boost/smart_ptr.hpp>


namespace openlima {
namespace graphics {

class WavefrontObjMaterialLibrary {
private:
std::map<string, boost::shared_ptr<WavefrontObjMaterial>> materials;

public:
OPENLIMA_DLL boost::shared_ptr<WavefrontObjMaterial> getMaterial(string name);

};

}
}

#endif /* OPENLIMA_GRAPHICS_WAVEFRONTOBJMATERIALLIBRARY_HPP */
@@ -0,0 +1,32 @@
// Copyright (C) 2011 Robert Boehm
// This file is part of openLima.
//
// You should have received a copy of the GNU Lesser General Public License
// along with openLima. If not, see: <http://www.gnu.org/licenses/>.

#ifndef OPENLIMA_GRAPHICS_WAVEFRONTOBJOBJECT_HPP
#define OPENLIMA_GRAPHICS_WAVEFRONTOBJOBJECT_HPP

#include <openlima/util/macros.hpp>
#include <boost/smart_ptr.hpp>
#include <openlima/graphics/IRenderable.hpp>


namespace openlima {
namespace graphics {

class WavefrontObjObject : public IRenderable {
public:
boost::shared_ptr<WavefrontObjMaterial> material;
boost::shared_ptr<StaticMesh> mesh;

//OPENLIMA_DLL WavefrontObjObject();
//OPENLIMA_DLL virtual ~WavefrontObjObject();

OPENLIMA_DLL void render();
};

}
}

#endif /* OPENLIMA_GRAPHICS_WAVEFRONTOBJOBJECT_HPP */
@@ -0,0 +1,23 @@
// Copyright (C) 2011 Robert Boehm
// This file is part of openLima.
//
// You should have received a copy of the GNU Lesser General Public License
// along with openLima. If not, see: <http://www.gnu.org/licenses/>.

#ifndef OPENLIMA_GRAPHICS_WAVEFRONTOBJSCENE_HPP
#define OPENLIMA_GRAPHICS_WAVEFRONTOBJSCENE_HPP

#include <openlima/util/macros.hpp>


namespace openlima {
namespace graphics {

class WavefrontObjScene {

};

}
}

#endif /* OPENLIMA_GRAPHICS_WAVEFRONTOBJSCENE_HPP */
@@ -21,16 +21,16 @@ namespace openlima {
public:

/** The red component. */
Real r;
float r;

/** The green component. */
Real g;
float g;

/** The blue component. */
Real b;
float b;

/** The alpha component. */
Real a;
float a;


/**
@@ -42,7 +42,7 @@ namespace openlima {
* @param b The blue component.
* @param a The alpha component.
*/
OPENLIMA_DLL Color(Real r, Real g, Real b, Real a);
OPENLIMA_DLL Color(float r, float g, float b, float a);

/**
* Copies the given color.
@@ -103,6 +103,13 @@ namespace openlima {
*/
OPENLIMA_DLL u8 getIntA() const;

/**
* Fills the given vector with the color data.
*
* @param vector The vector that should get the color data.
*/
OPENLIMA_DLL void fill(float* vector) const;

/**
* Compares this color with the given other color.
*
@@ -76,6 +76,7 @@ namespace openlima {
glEnable(GL_NORMALIZE);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
//glEnable(GL_COLOR_MATERIAL);


glMatrixMode(GL_PROJECTION);
@@ -92,7 +93,7 @@ namespace openlima {
ambientColor.b,
ambientColor.a,
};
glLightModelfv(GL_AMBIENT, ambientColorFv);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColorFv);

for(size_t i = 0; i < 8; i++) {
if(i < lights.size()) {
Empty file.
@@ -0,0 +1,47 @@
// Copyright (C) 2011 Robert Boehm
// This file is part of openLima.
//
// You should have received a copy of the GNU Lesser General Public License
// along with openLima. If not, see: <http://www.gnu.org/licenses/>.

#include <openlima/graphics/SimplePass.hpp>
#include <openlima/sil/sigl.hpp>

using namespace openlima::util;


namespace openlima {
namespace graphics {

SimplePass::SimplePass(Color ambient, Color diffuse, Color specular, Color emission,
float shininess) : shininess(shininess) {
this->ambient = new float[4];
this->diffuse = new float[4];
this->specular = new float[4];
this->emission = new float[4];
ambient.fill(this->ambient);
diffuse.fill(this->diffuse);
specular.fill(this->specular);
emission.fill(this->emission);
}

SimplePass::~SimplePass() {
delete [] ambient;
delete [] diffuse;
delete [] specular;
delete [] emission;
}

void SimplePass::setProperties() {
glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_EMISSION, emission);
glMaterialf(GL_FRONT, GL_SHININESS, shininess);
}

void SimplePass::unsetProperties() {
}

}
}
@@ -17,11 +17,10 @@ namespace openlima {
StaticMesh::StaticMesh(vector<openlima::util::Vector3f> vertices,
vector<openlima::util::Vector3f> normals,
vector<openlima::util::Vector3i> vertexIndices,
vector<openlima::util::Vector3i> normalIndices) {
this->vertices = vertices;
this->normals = normals;
this->vertexIndices = vertexIndices;
this->normalIndices = normalIndices;
vector<openlima::util::Vector3i> normalIndices,
bool smoothShading/* = true*/)
: vertices(vertices), normals(normals), vertexIndices(vertexIndices),
normalIndices(normalIndices), smoothShading(smoothShading) {
}

void StaticMesh::render() {
Empty file.
Empty file.
@@ -0,0 +1,18 @@
// Copyright (C) 2011 Robert Boehm
// This file is part of openLima.
//
// You should have received a copy of the GNU Lesser General Public License
// along with openLima. If not, see: <http://www.gnu.org/licenses/>.

#include <openlima/graphics/WavefrontObjObject.hpp>


namespace openlima {
namespace graphics {

void WavefrontObjObject::render() {
this->material->render(this->mesh);
}

}
}
Empty file.
@@ -10,7 +10,7 @@
namespace openlima {
namespace util {

Color::Color(Real r, Real g, Real b, Real a) : r(r), g(g), b(b), a(a) {
Color::Color(float r, float g, float b, float a) : r(r), g(g), b(b), a(a) {
// Empty
}

@@ -42,19 +42,26 @@ namespace openlima {
}

u8 Color::getIntR() const {
return static_cast<u8>(this->r * OPENLIMA_REAL(255.0));
return static_cast<u8>(this->r * 255.0f);
}

u8 Color::getIntG() const {
return static_cast<u8>(this->g * OPENLIMA_REAL(255.0));
return static_cast<u8>(this->g * 255.0f);
}

u8 Color::getIntB() const {
return static_cast<u8>(this->b * OPENLIMA_REAL(255.0));
return static_cast<u8>(this->b * 255.0f);
}

u8 Color::getIntA() const {
return static_cast<u8>(this->a * OPENLIMA_REAL(255.0));
return static_cast<u8>(this->a * 255.0f);
}

void Color::fill(float* vector) const {
vector[0] = this->r;
vector[1] = this->g;
vector[2] = this->b;
vector[3] = this->a;
}

bool Color::operator ==(const Color& other) const {