added first working implementation of crappyModule

This commit is contained in:
Anselme 2015-09-09 17:13:13 +02:00
parent a68f7107e1
commit 9ff1710082
10 changed files with 42 additions and 20 deletions

View File

@ -1,23 +1,33 @@
#include "crappymodule.h" #include "crappymodule.h"
#include "camera.h" #include "camera.h"
#include "phongentity.h" #include "phongentity.h"
#include <glm/ext.hpp>
CrappyModule::CrappyModule(Lights::Light* myDirLight, Lights* myPointLights) CrappyModule::CrappyModule(Lights::Light* myDirLight, Lights* myPointLights) :
dirLight(myDirLight),
pointLights(myPointLights)
{ {
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_AMBIENT, glm::value_ptr(glm::vec4(glm::vec3(0.1f), 1)));
glLightfv(GL_LIGHT0, GL_POSITION, glm::value_ptr(glm::vec4(dirLight->position, 0)));
// TODO add point lights
} }
void CrappyModule::renderGL(Camera* myCamera) void CrappyModule::renderGL(Camera* myCamera)
{ {
glLightfv(GL_LIGHT0, GL_DIFFUSE, glm::value_ptr(glm::vec4(dirLight->color, 1)));
glLightfv(GL_LIGHT0, GL_SPECULAR, glm::value_ptr(glm::vec4(dirLight->color, 1)));
for(PhongEntity* e : entities)
e->crappyDraw(myCamera->getViewMatrix(), myCamera->getProjectionMatrix(), dirLight, pointLights);
} }
void CrappyModule::addEntity(PhongEntity* myEntity) void CrappyModule::addEntity(PhongEntity* myEntity)
{ {
entities.push_back(myEntity);
} }
void CrappyModule::clearEntities() void CrappyModule::clearEntities()
{ {
entities.clear();
} }

View File

@ -15,6 +15,15 @@ public:
void clearEntities(); void clearEntities();
virtual void renderGL(Camera* myCamera); virtual void renderGL(Camera* myCamera);
virtual bool requiresModernOpenGL() {return false;}
private:
Lights::Light* dirLight;
Lights* pointLights;
GLuint dirLightLocation;
GLuint nbPointLightsLocation;
GLuint pointLightsLocation;
std::vector<PhongEntity*> entities;
}; };
#endif // CRAPPYMODULE_H #endif // CRAPPYMODULE_H

View File

@ -7,7 +7,7 @@ class Module
{ {
public: public:
virtual void renderGL(Camera* myCamera) = 0; virtual void renderGL(Camera* myCamera) = 0;
virtual bool isAvailable() {return true;} virtual bool requiresModernOpenGL() {return true;}
}; };
#endif // MODULE #endif // MODULE

View File

@ -1,7 +1,7 @@
#include "phongentity.h" #include "phongentity.h"
#include "shader.h" #include "shader.h"
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include "material.h" #include "phongmaterial.h"
#include "mesh.h" #include "mesh.h"
#include <glm/ext.hpp> #include <glm/ext.hpp>
#include "glassert.h" #include "glassert.h"
@ -44,7 +44,8 @@ void PhongEntity::crappyDraw(const glm::mat4 viewMatrix, const glm::mat4 project
glLoadMatrixf(glm::value_ptr(projectionMatrix)); glLoadMatrixf(glm::value_ptr(projectionMatrix));
for(int i=0; i<mesh->indiceGroups.size(); ++i) for(int i=0; i<mesh->indiceGroups.size(); ++i)
{ {
//Material* mat = (PhongMaterial*)(mesh->indiceGroups[i].material); PhongMaterial* mat = (PhongMaterial*)(mesh->indiceGroups[i].material);
mat->crappyBindAttributes();
glBegin(GL_TRIANGLES); glBegin(GL_TRIANGLES);
for(int j=0; j<mesh->indiceGroups[i].indices.size(); ++j) for(int j=0; j<mesh->indiceGroups[i].indices.size(); ++j)
{ {

View File

@ -29,8 +29,6 @@ protected:
GLuint* vbo; GLuint* vbo;
void drawGroup(int groupId); void drawGroup(int groupId);
void crappyDraw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix, Lights::Light* dirLight, Lights* pointLights);
public: public:
glm::mat4 modelMatrix; glm::mat4 modelMatrix;
@ -38,6 +36,7 @@ public:
~PhongEntity(); ~PhongEntity();
void draw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix, Lights::Light* dirLight, Lights* pointLights); void draw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix, Lights::Light* dirLight, Lights* pointLights);
void crappyDraw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix, Lights::Light* dirLight, Lights* pointLights);
void initGL(bool isDynamic = false); void initGL(bool isDynamic = false);
void destroyGL(); void destroyGL();

View File

@ -21,7 +21,6 @@ public:
void clearEntities(); void clearEntities();
virtual void renderGL(Camera* myCamera); virtual void renderGL(Camera* myCamera);
virtual bool isAvailable() {return GLEW_VERSION_3_3;}
static void setShader(ShaderType slot, Shader* myShader); static void setShader(ShaderType slot, Shader* myShader);
static Shader* getShader(ShaderType slot); static Shader* getShader(ShaderType slot);

View File

@ -9,7 +9,7 @@
SkyboxModule::SkyboxModule(Texture* myCubeMap) SkyboxModule::SkyboxModule(Texture* myCubeMap)
{ {
if(isAvailable()) if(requiresModernOpenGL())
{ {
shader = new Shader(vertSource, fragSource); shader = new Shader(vertSource, fragSource);
cubeMap = myCubeMap; cubeMap = myCubeMap;

View File

@ -23,7 +23,6 @@ public:
SkyboxModule(Texture* myCubeMap); SkyboxModule(Texture* myCubeMap);
~SkyboxModule(); ~SkyboxModule();
virtual void renderGL(Camera* myCamera); virtual void renderGL(Camera* myCamera);
virtual bool isAvailable() {return GLEW_VERSION_3_3;}
}; };
#endif // SKYBOXMODULE_H #endif // SKYBOXMODULE_H

View File

@ -17,13 +17,11 @@ void SparrowRenderer::initGL(int width, int height)
!GLEW_ARB_fragment_program || !GLEW_ARB_fragment_program ||
!GLEW_ARB_texture_float || !GLEW_ARB_texture_float ||
!GLEW_ARB_draw_buffers || !GLEW_ARB_draw_buffers ||
!GLEW_ARB_framebuffer_object) !GLEW_ARB_framebuffer_object ||
!glewIsSupported("GL_VERSION_3_3"))
{ {
fprintf(stderr, "Warning: Shaders not supported!\n"); modernOpenglAvailable = false;
} fprintf(stderr, "Warning: modern OpenGL not supported!\nEnabling fallback crappy rendering mode\n");
if(!GLEW_VERSION_3_3)
{
fprintf(stderr, "Warning: Crappy rendering mode enabled!\n");
} }
std::cout << "OpenGL version " << glGetString(GL_VERSION) << std::endl; std::cout << "OpenGL version " << glGetString(GL_VERSION) << std::endl;
@ -57,11 +55,16 @@ void SparrowRenderer::renderGL()
} }
} }
bool SparrowRenderer::isModernOpenGLAvailable()
{
return modernOpenglAvailable;
}
// module methods // module methods
void SparrowRenderer::addModule(Module* myModule, std::string name) void SparrowRenderer::addModule(Module* myModule, std::string name)
{ {
if(myModule->isAvailable()) if(modernOpenglAvailable || !myModule->requiresModernOpenGL())
modules.push_back(ModuleNode(myModule, name)); modules.push_back(ModuleNode(myModule, name));
} }

View File

@ -15,6 +15,7 @@ public:
void destroyGL(); void destroyGL();
void resizeGL(int width, int height); void resizeGL(int width, int height);
void renderGL(); void renderGL();
bool isModernOpenGLAvailable();
// modules methods // modules methods
void addModule(Module* myModule, std::string name); void addModule(Module* myModule, std::string name);
@ -35,6 +36,7 @@ protected:
Camera* camera; Camera* camera;
std::list<ModuleNode> modules; std::list<ModuleNode> modules;
bool modernOpenglAvailable;
std::list<ModuleNode>::iterator getModuleNode(std::string name); std::list<ModuleNode>::iterator getModuleNode(std::string name);
}; };