changed structure of the renderer to modules

This commit is contained in:
Anselme 2015-07-05 23:13:17 +02:00
parent 90126ba79d
commit 009894ca3b
25 changed files with 2470 additions and 245 deletions

19
basicmodule.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "basicmodule.h"
#include "shader.h"
#include "entity.h"
#include "camera.h"
void BasicModule::addEntity(Entity* myEntity)
{
entities.push_back(myEntity);
}
void BasicModule::render(Camera* myCamera)
{
shader->bind();
bindModule();
for(Entity* e : entities)
e->draw(myCamera->getViewMatrix(), myCamera->getProjectionMatrix());
}

27
basicmodule.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef BASICMODULE_H
#define BASICMODULE_H
#include "module.h"
#include <vector>
#include <cstddef>
class Shader;
class Entity;
class Camera;
class BasicModule : public Module
{
protected:
Shader* shader;
std::vector<Entity*> entities;
BasicModule(Shader* myShader = NULL) : shader(myShader) {}
virtual void bindModule() = 0;
public:
void addEntity(Entity* myEntity);
void virtual render(Camera* myCamera);
};
#endif // BASICMODULE_H

15
data/sword.mtl Normal file
View File

@ -0,0 +1,15 @@
#
# generated by kHED
#
newmtl steel
d 1.0
Ka 1.0 1.0 1.0
Ks 0.9 0.9 0.9
Kd 0.3 0.3 0.3
map_Kd res/textures/steel.jpg
newmtl leather
d 1.0
Ka 1.0 1.0 1.0
Ks 0.4 0.4 0.4
Kd 0.9 0.9 0.9
map_Kd res/textures/leather.jpg

2226
data/sword.obj Normal file

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,13 @@
#include "material.h" #include "material.h"
#include "mesh.h" #include "mesh.h"
Entity::Entity(Mesh* myMesh, Material* myMat) : mesh(myMesh), mat(myMat) {}
Entity::Entity(Entity* myParent, Mesh* myMesh, Material* myMat) : mesh(myMesh), mat(myMat)
{
myParent->addChild(this);
}
void Entity::draw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix) void Entity::draw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix)
{ {
glm::mat4 modelViewMatrix = viewMatrix * modelMatrix; glm::mat4 modelViewMatrix = viewMatrix * modelMatrix;
@ -32,3 +39,8 @@ Material* Entity::getMaterial()
{ {
return mat; return mat;
} }
void Entity::addChild(Entity* child)
{
children.push_back(child);
}

View File

@ -2,6 +2,7 @@
#define ENTITY_H #define ENTITY_H
#include "glm/mat4x4.hpp" #include "glm/mat4x4.hpp"
#include <vector>
class Mesh; class Mesh;
class Material; class Material;
@ -10,16 +11,21 @@ class Shader;
class Entity class Entity
{ {
protected: protected:
Entity* parent; std::vector<Entity*> children;
Mesh* mesh; Mesh* mesh;
Material* mat; Material* mat;
glm::mat4 modelMatrix; glm::mat4 modelMatrix;
public: public:
Entity(Entity* myParent, Mesh* myMesh, Material* myMat) : parent(myParent), mesh(myMesh), mat(myMat) {} Entity(Mesh* myMesh, Material* myMat);
/**
* NULL Material is acceptable for this constructor
*/
Entity(Entity* myParent, Mesh* myMesh, Material* myMat);
virtual void draw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix); virtual void draw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix);
glm::mat4* getTransform(); glm::mat4* getTransform();
Shader* getShader(); Shader* getShader();
Material* getMaterial(); Material* getMaterial();
void addChild(Entity* child);
}; };
#endif // ENTITY_H #endif // ENTITY_H

View File

@ -11,7 +11,6 @@ public:
Shader* getShader() {return shader;} Shader* getShader() {return shader;}
virtual void bindAttributes() = 0; virtual void bindAttributes() = 0;
virtual bool requireLights() {return true;}
protected: protected:
Shader* shader; Shader* shader;

13
module.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef MODULE
#define MODULE
class Camera;
class Module
{
public:
virtual void render(Camera* myCamera) = 0;
};
#endif // MODULE

View File

@ -1,12 +1,14 @@
#include <glew/glew.h> #include <glew/glew.h>
#include "myglwidget.h" #include "myglwidget.h"
#include "scene.h"
#include "glassert.h" #include "glassert.h"
#include "camera.h" #include "camera.h"
#include "sphere.h" #include "sphere.h"
#include "phongmaterial.h" #include "phongmaterial.h"
#include "skybox.h" #include "skyboxmodule.h"
#include "entity.h"
#include "phongmodule.h"
#include "utils.h" #include "utils.h"
#include "lights.h"
#include "texture.h" #include "texture.h"
#include "gridmesh.h" #include "gridmesh.h"
#include "sparrowrenderer.h" #include "sparrowrenderer.h"
@ -31,42 +33,47 @@ MyGLWidget::~MyGLWidget()
delete(controller); delete(controller);
} }
Scene* MyGLWidget::buildScene() void MyGLWidget::buildScene()
{ {
Scene* scene = new Scene(); // init camera
Camera* cam = renderer->getCamera();
Camera* cam = new Camera(width(), height());
cam->moveTo(glm::vec3(0, 0, 3)); cam->moveTo(glm::vec3(0, 0, 3));
cam->lookAt(glm::vec2(0, 0)); cam->lookAt(glm::vec2(0, 0));
scene->setCamera(cam);
// create skybox module
std::string filenames[6] = { std::string filenames[6] = {
"../data/skybox_ft", "../data/skybox_bk", "../data/skybox_ft", "../data/skybox_bk",
"../data/skybox_up", "../data/skybox_dn", "../data/skybox_up", "../data/skybox_dn",
"../data/skybox_lf", "../data/skybox_rt" "../data/skybox_lf", "../data/skybox_rt"
}; };
SkyBox* skybox = new SkyBox(filenames); Texture* skyboxCubemap = new Texture(filenames);
scene->addEntity(skybox); SkyboxModule* skybox = new SkyboxModule(skyboxCubemap);
// create a mesh
//Mesh* myGrid = new GridMesh(10, 10, true); //new Sphere(2); //Mesh* myGrid = new GridMesh(10, 10, true); //new Sphere(2);
Mesh* myGrid = Utils::loadOBJ("../data/sphere.obj"); Mesh* myGrid = Utils::loadOBJ("../data/sword.obj");
myGrid->initGL(); myGrid->initGL();
//
std::string vertSource = Utils::fileToString("../phong.vert"); std::string vertSource = Utils::fileToString("../phong.vert");
std::string fragSource = Utils::fileToString("../phong.frag"); std::string fragSource = Utils::fileToString("../phong.frag");
Shader* shader = new Shader(vertSource, fragSource); Shader* phongShader = new Shader(vertSource, fragSource);
PhongMaterial* mat = new PhongMaterial(shader, glm::vec3(1), glm::vec3(1), 20.0f); PhongMaterial* mat = new PhongMaterial(phongShader, glm::vec3(1), glm::vec3(1), 20.0f);
Texture* tex = new Texture("../data/noise.png"); Texture* tex = new Texture("../data/noise.png");
mat->setTexture(tex); mat->setTexture(tex);
Entity* myEntity = new Entity(NULL, myGrid, mat); Entity* myEntity = new Entity(myGrid, mat);
glm::mat4* transform = myEntity->getTransform(); glm::mat4* transform = myEntity->getTransform();
*transform = glm::translate(glm::rotate(glm::scale(*transform, glm::vec3(0.1f)), 3.1416f/2, glm::vec3(-1, 0, 0)), glm::vec3(-0.5f, -0.5f, 0)); *transform = glm::scale(*transform, glm::vec3(0.01f));
scene->addEntity(myEntity);
scene->addDirectionnalLight(glm::vec3(6, 4, -4), glm::vec3(0.7f, 0.6f, 0.4f)); // sun Lights* directionnalLights = new Lights();
directionnalLights->addLight(glm::vec3(6, 4, -4), glm::vec3(0.7f, 0.6f, 0.4f)); // sun
return scene; PhongModule* myPhongModule = new PhongModule(directionnalLights, new Lights(), phongShader);
myPhongModule->addEntity(myEntity);
renderer->addModule(skybox);
renderer->addModule(myPhongModule);
} }
void MyGLWidget::initializeGL() void MyGLWidget::initializeGL()
@ -74,10 +81,9 @@ void MyGLWidget::initializeGL()
if(renderer != NULL) if(renderer != NULL)
delete(renderer); delete(renderer);
renderer = new SparrowRenderer(width(), height()); renderer = new SparrowRenderer(width(), height());
Scene* scene = buildScene(); buildScene();
controller = new FocusController(new glm::vec3(0)); controller = new FocusController(new glm::vec3(0));
renderer->setScene(scene); controller->setCamera(renderer->getCamera());
controller->setScene(scene);
} }
void MyGLWidget::resizeGL(int width, int height) void MyGLWidget::resizeGL(int width, int height)

View File

@ -3,7 +3,6 @@
#include <QGLWidget> #include <QGLWidget>
class Scene;
class SparrowRenderer; class SparrowRenderer;
class SceneController; class SceneController;
@ -25,7 +24,7 @@ public:
protected: protected:
void initializeGL(); void initializeGL();
Scene* buildScene(); void buildScene();
void resizeGL(int width, int height); void resizeGL(int width, int height);
void paintGL(); void paintGL();

17
phongmodule.cpp Normal file
View File

@ -0,0 +1,17 @@
#include "phongmodule.h"
#include "lights.h"
PhongModule::PhongModule(Lights* myDirLights, Lights* myPointLights, Shader* phongShader) :
BasicModule(phongShader), dirLights(myDirLights), pointLights(myPointLights)
{
nbDirLightsLocation = shader->getLocation("nbDirLights");
dirLightsLocation = shader->getLocation("dirLights");
nbPointLightsLocation = shader->getLocation("nbPointLights");
pointLightsLocation = shader->getLocation("pointLights");
}
void PhongModule::bindModule()
{
dirLights->bind(dirLightsLocation, nbDirLightsLocation, shader);
pointLights->bind(pointLightsLocation, nbPointLightsLocation, shader);
}

24
phongmodule.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef PHONGMODULE_H
#define PHONGMODULE_H
#include "basicmodule.h"
#include "phongmaterial.h"
#include "mesh.h"
#include <glew/glew.h>
class Lights;
class PhongModule : public BasicModule
{
Lights* dirLights;
Lights* pointLights;
GLuint nbDirLightsLocation;
GLuint dirLightsLocation;
GLuint nbPointLightsLocation;
GLuint pointLightsLocation;
public:
PhongModule(Lights* myDirLights, Lights* myPointLights, Shader* phongShader);
virtual void bindModule();
};
#endif // PHONGMODULE_H

View File

@ -1,74 +0,0 @@
#include "scene.h"
#include "glassert.h"
#include <glm/glm.hpp>
#include <glm/ext.hpp>
#include "camera.h"
#include "entity.h"
#include "shader.h"
#include "material.h"
// MAIN METHODS
Scene::~Scene()
{
for(Entity* e : entities)
delete(e);
}
void Scene::drawAll()
{
glm::mat4 viewMatrix = camera->getViewMatrix();
glm::mat4 projectionMatrix = camera->getProjectionMatrix();
for(Entity* e : entities)
{
Shader* shader = e->getShader();
shader->bind();
if(e->getMaterial()->requireLights())
{
directionnalLights.bind(shader->getLocation("dirLights"), shader->getLocation("nbDirLights"), shader);
pointLights.bind(shader->getLocation("pointLights"), shader->getLocation("nbPointLights"), shader);
}
e->draw(viewMatrix, projectionMatrix);
}
}
// ENTITIES
void Scene::addEntity(Entity* parent, Mesh* mesh, Material* mat)
{
entities.push_back(new Entity(parent, mesh, mat));
}
void Scene::addEntity(Mesh* mesh, Material* mat)
{
entities.push_back(new Entity(NULL, mesh, mat));
}
void Scene::addEntity(Entity* entity)
{
entities.push_back(entity);
}
// LIGHTS
void Scene::addDirectionnalLight(const glm::vec3 &position, const glm::vec3 &color)
{
directionnalLights.addLight(position, color);
}
void Scene::addPointLight(const glm::vec3 &position, const glm::vec3 &color)
{
pointLights.addLight(position, color);
}
// CAMERA
void Scene::setCamera(Camera* myCamera)
{
camera = myCamera;
}
Camera* Scene::getCamera()
{
return camera;
}

41
scene.h
View File

@ -1,41 +0,0 @@
#ifndef SCENE_H
#define SCENE_H
#include "lights.h"
#include <glew/glew.h>
#include <vector>
class Entity;
class Camera;
class Mesh;
class Material;
class Shader;
class Scene
{
Lights directionnalLights;
Lights pointLights;
std::vector<Entity*> entities;
Camera* camera;
public:
// main methods
Scene() : camera(NULL) {}
~Scene();
void drawAll();
// entities
void addEntity(Entity* parent, Mesh* mesh, Material* mat);
void addEntity(Mesh* mesh, Material* mat);
void addEntity(Entity* entity);
// lights
void addDirectionnalLight(const glm::vec3 &position, const glm::vec3 &color);
void addPointLight(const glm::vec3 &position, const glm::vec3 &color);
// camera
void setCamera(Camera* myCamera);
Camera* getCamera();
};
#endif // SCENE_H

View File

@ -1,12 +1,10 @@
#include "scenecontroller.h" #include "scenecontroller.h"
#include "scene.h"
#include "camera.h" #include "camera.h"
#include <QObject> #include <QObject>
void SceneController::setScene(Scene* myScene) void SceneController::setCamera(Camera* myCamera)
{ {
scene = myScene; camera = myCamera;
camera = scene->getCamera();
} }
void SceneController::mouseEvent(int button, bool state) void SceneController::mouseEvent(int button, bool state)

View File

@ -3,19 +3,17 @@
#include <cstddef> #include <cstddef>
class Scene;
class Camera; class Camera;
class SceneController class SceneController
{ {
protected: protected:
Camera* camera; Camera* camera;
Scene* scene;
int grabbed; int grabbed;
public: public:
SceneController() : camera(NULL), scene(NULL), grabbed(0) {} SceneController() : camera(NULL), grabbed(0) {}
void setScene(Scene* myScene); void setCamera(Camera* myCamera);
virtual void mouseMove(int dx, int dy) {} virtual void mouseMove(int dx, int dy) {}
virtual void mouseEvent(int button, bool state); virtual void mouseEvent(int button, bool state);
virtual void keyEvent(int key, bool state) {} virtual void keyEvent(int key, bool state) {}

View File

@ -31,8 +31,6 @@ Shader::Shader(const std::string &vertexSource, const std::string &fragmentSourc
printProgramInfoLog(program); printProgramInfoLog(program);
program = 0; program = 0;
} }
else
std::cout << "Shader successfully compiled" << std::endl;
glAssert(glDetachShader(program, vertexShaderId)); glAssert(glDetachShader(program, vertexShaderId));
glAssert(glDetachShader(program, fragmentShaderId)); glAssert(glDetachShader(program, fragmentShaderId));

View File

@ -1,22 +0,0 @@
#ifndef SKYBOX_H
#define SKYBOX_H
#include "entity.h"
#include <glew/glew.h>
#include <string>
class SkyBox : public Entity
{
private:
static const GLfloat skyboxVertices[];
static const std::string vertSource;
static const std::string fragSource;
GLuint vao;
GLuint vbo;
public:
SkyBox(const std::string filename[6]);
~SkyBox();
virtual void draw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix);
};
#endif // SKYBOX_H

View File

@ -1,17 +0,0 @@
#include "skyboxmaterial.h"
#include "texture.h"
SkyBoxMaterial::SkyBoxMaterial(Shader* myShader, const std::string filenames[6]) : Material(myShader)
{
skyboxTex = new Texture(filenames);
}
void SkyBoxMaterial::bindAttributes()
{
skyboxTex->bind(0);
}
bool SkyBoxMaterial::requireLights()
{
return false;
}

View File

@ -1,19 +0,0 @@
#ifndef SKYBOXMATERIAL_H
#define SKYBOXMATERIAL_H
#include "material.h"
class Texture;
class SkyBoxMaterial : public Material
{
public:
SkyBoxMaterial(Shader* myShader, const std::string filenames[6]);
virtual void bindAttributes();
virtual bool requireLights();
private:
Texture* skyboxTex;
};
#endif // SKYBOXMATERIAL_H

View File

@ -1,15 +1,16 @@
#include "skybox.h" #include <glm/mat4x4.hpp>
#include "glassert.h" #include <glm/mat3x3.hpp>
#include "skyboxmodule.h"
#include "entity.h"
#include "shader.h" #include "shader.h"
#include "material.h" #include "texture.h"
#include "skyboxmaterial.h" #include "camera.h"
#include "glm/glm.hpp" #include "glassert.h"
#include "glm/ext.hpp"
SkyBox::SkyBox(const std::string filename[6]) : Entity(NULL, NULL, NULL) SkyboxModule::SkyboxModule(Texture* myCubeMap)
{ {
Shader* shader = new Shader(vertSource, fragSource); shader = new Shader(vertSource, fragSource);
mat = new SkyBoxMaterial(shader, filename); cubeMap = myCubeMap;
// set up vao // set up vao
glAssert(glGenVertexArrays(1, &vao)); glAssert(glGenVertexArrays(1, &vao));
@ -20,27 +21,29 @@ SkyBox::SkyBox(const std::string filename[6]) : Entity(NULL, NULL, NULL)
glAssert(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float)*3, NULL)); glAssert(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float)*3, NULL));
glAssert(glEnableVertexAttribArray(0)); glAssert(glEnableVertexAttribArray(0));
glAssert(glBindVertexArray(0)); glAssert(glBindVertexArray(0));
mvpLocation = shader->getLocation("MVP");
} }
SkyBox::~SkyBox() SkyboxModule::~SkyboxModule()
{ {
glAssert(glDeleteVertexArrays(1, &vao)); glAssert(glDeleteVertexArrays(1, &vao));
glAssert(glDeleteBuffers(1, &vbo)); glAssert(glDeleteBuffers(1, &vbo));
} }
void SkyBox::draw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix) void SkyboxModule::render(Camera* myCamera)
{ {
glm::mat4 mvp = projectionMatrix * glm::mat4(glm::mat3(viewMatrix)); shader->bind();
glm::mat4 mvp = myCamera->getProjectionMatrix() * glm::mat4(glm::mat3(myCamera->getViewMatrix()));
glAssert(glDepthMask(GL_FALSE)); glAssert(glDepthMask(GL_FALSE));
mat->bindAttributes(); cubeMap->bind(0);
Shader* shader = mat->getShader(); shader->bindMatrix(mvpLocation, mvp);
shader->bindMatrix(shader->getLocation("MVP"), mvp);
glAssert(glBindVertexArray(vao)); glAssert(glBindVertexArray(vao));
glAssert(glDrawArrays(GL_TRIANGLES, 0, 36)); glAssert(glDrawArrays(GL_TRIANGLES, 0, 36));
glAssert(glDepthMask(GL_TRUE)); glAssert(glDepthMask(GL_TRUE));
} }
const GLfloat SkyBox::skyboxVertices[] = { const GLfloat SkyboxModule::skyboxVertices[] = {
-1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f,
1.0f, -1.0f, -1.0f, 1.0f, -1.0f, -1.0f,
@ -84,7 +87,7 @@ const GLfloat SkyBox::skyboxVertices[] = {
1.0f, -1.0f, 1.0f 1.0f, -1.0f, 1.0f
}; };
const std::string SkyBox::vertSource = const std::string SkyboxModule::vertSource =
"#version 330 core\n\ "#version 330 core\n\
layout(location = 0)in vec3 inPosition;\n\ layout(location = 0)in vec3 inPosition;\n\
out vec3 varTexCoord;\n\ out vec3 varTexCoord;\n\
@ -95,7 +98,7 @@ const std::string SkyBox::vertSource =
varTexCoord = inPosition;\n\ varTexCoord = inPosition;\n\
}\n"; }\n";
const std::string SkyBox::fragSource = const std::string SkyboxModule::fragSource =
"#version 330 core\n\ "#version 330 core\n\
in vec3 varTexCoord;\n\ in vec3 varTexCoord;\n\
out vec4 outColor;\n\ out vec4 outColor;\n\

28
skyboxmodule.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef SKYBOXMODULE_H
#define SKYBOXMODULE_H
#include <glew/glew.h>
#include "module.h"
#include <string>
class Shader;
class Texture;
class SkyboxModule : public Module
{
static const GLfloat skyboxVertices[];
static const std::string vertSource;
static const std::string fragSource;
GLuint vao;
GLuint vbo;
GLuint mvpLocation;
Shader* shader;
Texture* cubeMap;
public:
SkyboxModule(Texture* myCubeMap);
~SkyboxModule();
virtual void render(Camera* myCamera);
};
#endif // SKYBOXMODULE_H

View File

@ -27,20 +27,20 @@ SOURCES += main.cpp\
shader.cpp \ shader.cpp \
mesh.cpp \ mesh.cpp \
camera.cpp \ camera.cpp \
scene.cpp \
gridmesh.cpp \ gridmesh.cpp \
texture.cpp \ texture.cpp \
phongmaterial.cpp \ phongmaterial.cpp \
scenecontroller.cpp \ scenecontroller.cpp \
sphere.cpp \ sphere.cpp \
skyboxmaterial.cpp \
skybox.cpp \
entity.cpp \ entity.cpp \
utils.cpp \ utils.cpp \
lights.cpp \ lights.cpp \
sparrowrenderer.cpp \ sparrowrenderer.cpp \
resourcebase.cpp \ resourcebase.cpp \
focuscontroller.cpp focuscontroller.cpp \
phongmodule.cpp \
skyboxmodule.cpp \
basicmodule.cpp
HEADERS += mainwindow.h \ HEADERS += mainwindow.h \
myglwidget.h \ myglwidget.h \
@ -48,21 +48,22 @@ HEADERS += mainwindow.h \
mesh.h \ mesh.h \
camera.h \ camera.h \
glassert.h \ glassert.h \
scene.h \
material.h \ material.h \
gridmesh.h \ gridmesh.h \
texture.h \ texture.h \
phongmaterial.h \ phongmaterial.h \
scenecontroller.h \ scenecontroller.h \
sphere.h \ sphere.h \
skyboxmaterial.h \
skybox.h \
entity.h \ entity.h \
utils.h \ utils.h \
lights.h \ lights.h \
sparrowrenderer.h \ sparrowrenderer.h \
resourcebase.h \ resourcebase.h \
focuscontroller.h focuscontroller.h \
phongmodule.h \
skyboxmodule.h \
basicmodule.h \
module.h
FORMS += mainwindow.ui FORMS += mainwindow.ui

View File

@ -3,8 +3,9 @@
#include <iostream> #include <iostream>
#include "glassert.h" #include "glassert.h"
#include "camera.h" #include "camera.h"
#include "basicmodule.h"
SparrowRenderer::SparrowRenderer(int width, int height) SparrowRenderer::SparrowRenderer(int width, int height) : camera(width, height)
{ {
glewExperimental = GL_TRUE; glewExperimental = GL_TRUE;
GLenum err = glewInit(); GLenum err = glewInit();
@ -30,22 +31,26 @@ SparrowRenderer::SparrowRenderer(int width, int height)
glAssert(glViewport(0, 0, width, height)); glAssert(glViewport(0, 0, width, height));
} }
void SparrowRenderer::setScene(Scene* myScene) void SparrowRenderer::addModule(Module* myModule)
{ {
scene = myScene; modules.push_back(myModule);
}
Camera* SparrowRenderer::getCamera()
{
return &camera;
} }
void SparrowRenderer::resize(int width, int height) void SparrowRenderer::resize(int width, int height)
{ {
glAssert(glViewport(0, 0, width, height)); glAssert(glViewport(0, 0, width, height));
if(scene != NULL) camera.resize(width, height);
scene->getCamera()->resize(width, height);
} }
void SparrowRenderer::render() void SparrowRenderer::render()
{ {
glAssert(glClearColor(0.60, 0.65, 0.75, 1.0)); glAssert(glClearColor(0.60, 0.65, 0.75, 1.0));
glAssert(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); glAssert(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT));
if(scene != NULL) for(Module* m : modules)
scene->drawAll(); m->render(getCamera());
} }

View File

@ -1,15 +1,19 @@
#ifndef SPARROWRENDERER_H #ifndef SPARROWRENDERER_H
#define SPARROWRENDERER_H #define SPARROWRENDERER_H
#include "scene.h" #include <vector>
#include "camera.h"
class Module;
class SparrowRenderer class SparrowRenderer
{ {
Scene* scene; Camera camera;
// TODO : data bank std::vector<Module*> modules;
public: public:
SparrowRenderer(int width, int height); SparrowRenderer(int width, int height);
void setScene(Scene* myScene); void addModule(Module* myModule);
Camera* getCamera();
void resize(int width, int height); void resize(int width, int height);
void render(); void render();
}; };