diff --git a/crappymodule.cpp b/crappymodule.cpp index 3d7d258..dd29e8a 100644 --- a/crappymodule.cpp +++ b/crappymodule.cpp @@ -1,23 +1,33 @@ #include "crappymodule.h" #include "camera.h" #include "phongentity.h" +#include -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) { - + 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) { - + entities.push_back(myEntity); } void CrappyModule::clearEntities() { - + entities.clear(); } diff --git a/crappymodule.h b/crappymodule.h index 41e98b3..6478fa6 100644 --- a/crappymodule.h +++ b/crappymodule.h @@ -15,6 +15,15 @@ public: void clearEntities(); virtual void renderGL(Camera* myCamera); + virtual bool requiresModernOpenGL() {return false;} + +private: + Lights::Light* dirLight; + Lights* pointLights; + GLuint dirLightLocation; + GLuint nbPointLightsLocation; + GLuint pointLightsLocation; + std::vector entities; }; #endif // CRAPPYMODULE_H diff --git a/module.h b/module.h index 8cbc2b0..9faf600 100644 --- a/module.h +++ b/module.h @@ -7,7 +7,7 @@ class Module { public: virtual void renderGL(Camera* myCamera) = 0; - virtual bool isAvailable() {return true;} + virtual bool requiresModernOpenGL() {return true;} }; #endif // MODULE diff --git a/phongentity.cpp b/phongentity.cpp index 59a4e57..df50b12 100644 --- a/phongentity.cpp +++ b/phongentity.cpp @@ -1,7 +1,7 @@ #include "phongentity.h" #include "shader.h" #include -#include "material.h" +#include "phongmaterial.h" #include "mesh.h" #include #include "glassert.h" @@ -44,7 +44,8 @@ void PhongEntity::crappyDraw(const glm::mat4 viewMatrix, const glm::mat4 project glLoadMatrixf(glm::value_ptr(projectionMatrix)); for(int i=0; iindiceGroups.size(); ++i) { - //Material* mat = (PhongMaterial*)(mesh->indiceGroups[i].material); + PhongMaterial* mat = (PhongMaterial*)(mesh->indiceGroups[i].material); + mat->crappyBindAttributes(); glBegin(GL_TRIANGLES); for(int j=0; jindiceGroups[i].indices.size(); ++j) { diff --git a/phongentity.h b/phongentity.h index bd3487e..a6ca30c 100644 --- a/phongentity.h +++ b/phongentity.h @@ -29,8 +29,6 @@ protected: GLuint* vbo; void drawGroup(int groupId); - - void crappyDraw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix, Lights::Light* dirLight, Lights* pointLights); public: glm::mat4 modelMatrix; @@ -38,6 +36,7 @@ public: ~PhongEntity(); 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 destroyGL(); diff --git a/phongmodule.h b/phongmodule.h index 21fb4f1..263686f 100644 --- a/phongmodule.h +++ b/phongmodule.h @@ -21,7 +21,6 @@ public: void clearEntities(); virtual void renderGL(Camera* myCamera); - virtual bool isAvailable() {return GLEW_VERSION_3_3;} static void setShader(ShaderType slot, Shader* myShader); static Shader* getShader(ShaderType slot); diff --git a/skyboxmodule.cpp b/skyboxmodule.cpp index c89a1c7..79a3fcc 100644 --- a/skyboxmodule.cpp +++ b/skyboxmodule.cpp @@ -9,7 +9,7 @@ SkyboxModule::SkyboxModule(Texture* myCubeMap) { - if(isAvailable()) + if(requiresModernOpenGL()) { shader = new Shader(vertSource, fragSource); cubeMap = myCubeMap; diff --git a/skyboxmodule.h b/skyboxmodule.h index 67d119f..7868434 100644 --- a/skyboxmodule.h +++ b/skyboxmodule.h @@ -23,7 +23,6 @@ public: SkyboxModule(Texture* myCubeMap); ~SkyboxModule(); virtual void renderGL(Camera* myCamera); - virtual bool isAvailable() {return GLEW_VERSION_3_3;} }; #endif // SKYBOXMODULE_H diff --git a/sparrowrenderer.cpp b/sparrowrenderer.cpp index bb0e8ad..ac80fa7 100644 --- a/sparrowrenderer.cpp +++ b/sparrowrenderer.cpp @@ -17,13 +17,11 @@ void SparrowRenderer::initGL(int width, int height) !GLEW_ARB_fragment_program || !GLEW_ARB_texture_float || !GLEW_ARB_draw_buffers || - !GLEW_ARB_framebuffer_object) + !GLEW_ARB_framebuffer_object || + !glewIsSupported("GL_VERSION_3_3")) { - fprintf(stderr, "Warning: Shaders not supported!\n"); - } - if(!GLEW_VERSION_3_3) - { - fprintf(stderr, "Warning: Crappy rendering mode enabled!\n"); + modernOpenglAvailable = false; + fprintf(stderr, "Warning: modern OpenGL not supported!\nEnabling fallback crappy rendering mode\n"); } std::cout << "OpenGL version " << glGetString(GL_VERSION) << std::endl; @@ -57,11 +55,16 @@ void SparrowRenderer::renderGL() } } +bool SparrowRenderer::isModernOpenGLAvailable() +{ + return modernOpenglAvailable; +} + // module methods void SparrowRenderer::addModule(Module* myModule, std::string name) { - if(myModule->isAvailable()) + if(modernOpenglAvailable || !myModule->requiresModernOpenGL()) modules.push_back(ModuleNode(myModule, name)); } diff --git a/sparrowrenderer.h b/sparrowrenderer.h index e634e89..6760f69 100644 --- a/sparrowrenderer.h +++ b/sparrowrenderer.h @@ -15,6 +15,7 @@ public: void destroyGL(); void resizeGL(int width, int height); void renderGL(); + bool isModernOpenGLAvailable(); // modules methods void addModule(Module* myModule, std::string name); @@ -35,6 +36,7 @@ protected: Camera* camera; std::list modules; + bool modernOpenglAvailable; std::list::iterator getModuleNode(std::string name); };