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 "camera.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)
{
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();
}

View File

@ -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<PhongEntity*> entities;
};
#endif // CRAPPYMODULE_H

View File

@ -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

View File

@ -1,7 +1,7 @@
#include "phongentity.h"
#include "shader.h"
#include <glm/glm.hpp>
#include "material.h"
#include "phongmaterial.h"
#include "mesh.h"
#include <glm/ext.hpp>
#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; i<mesh->indiceGroups.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; j<mesh->indiceGroups[i].indices.size(); ++j)
{

View File

@ -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();

View File

@ -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);

View File

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

View File

@ -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

View File

@ -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));
}

View File

@ -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<ModuleNode> modules;
bool modernOpenglAvailable;
std::list<ModuleNode>::iterator getModuleNode(std::string name);
};