temp commit of crappymodule implementation

This commit is contained in:
Anselme 2015-09-08 17:49:34 +02:00
parent 4d6c9b4a00
commit a68f7107e1
12 changed files with 112 additions and 23 deletions

View File

@ -23,6 +23,7 @@ set(LIB_SRC_LIST
shader.cpp shader.cpp
skyboxmodule.cpp skyboxmodule.cpp
sparrowrenderer.cpp sparrowrenderer.cpp
crappymodule.cpp
sphere.cpp sphere.cpp
texture.cpp texture.cpp
) )

23
crappymodule.cpp Normal file
View File

@ -0,0 +1,23 @@
#include "crappymodule.h"
#include "camera.h"
#include "phongentity.h"
CrappyModule::CrappyModule(Lights::Light* myDirLight, Lights* myPointLights)
{
}
void CrappyModule::renderGL(Camera* myCamera)
{
}
void CrappyModule::addEntity(PhongEntity* myEntity)
{
}
void CrappyModule::clearEntities()
{
}

20
crappymodule.h Normal file
View File

@ -0,0 +1,20 @@
#ifndef CRAPPYMODULE_H
#define CRAPPYMODULE_H
#include "module.h"
#include "lights.h"
class PhongEntity;
class CrappyModule : public Module
{
public:
CrappyModule(Lights::Light* myDirLight, Lights* myPointLights);
void addEntity(PhongEntity* myEntity);
void clearEntities();
virtual void renderGL(Camera* myCamera);
};
#endif // CRAPPYMODULE_H

View File

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

View File

@ -35,6 +35,28 @@ void PhongEntity::draw(const glm::mat4 viewMatrix, const glm::mat4 projectionMat
} }
} }
void PhongEntity::crappyDraw(const glm::mat4 viewMatrix, const glm::mat4 projectionMatrix, Lights::Light* dirLight, Lights* pointLights)
{
glMatrixMode(GL_MODELVIEW);
glm::mat4 modelViewMatrix = viewMatrix * modelMatrix;
glLoadMatrixf(glm::value_ptr(modelViewMatrix));
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(glm::value_ptr(projectionMatrix));
for(int i=0; i<mesh->indiceGroups.size(); ++i)
{
//Material* mat = (PhongMaterial*)(mesh->indiceGroups[i].material);
glBegin(GL_TRIANGLES);
for(int j=0; j<mesh->indiceGroups[i].indices.size(); ++j)
{
int vid = mesh->indiceGroups[i].indices[j];
glNormal3fv(glm::value_ptr(mesh->normals[vid]));
glTexCoord2fv(glm::value_ptr(mesh->texCoords[vid]));
glVertex3fv(glm::value_ptr(mesh->positions[vid]));
}
glEnd();
}
}
void PhongEntity::initGL(bool isDynamic) void PhongEntity::initGL(bool isDynamic)
{ {
GLenum buffer_type = isDynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW; GLenum buffer_type = isDynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW;

View File

@ -29,13 +29,15 @@ 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;
PhongEntity(Mesh* myMesh); PhongEntity(Mesh* myMesh);
~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 initGL(bool isDynamic = false); void initGL(bool isDynamic = false);
void destroyGL(); void destroyGL();

View File

@ -1,6 +1,7 @@
#include "phongmaterial.h" #include "phongmaterial.h"
#include "texture.h" #include "texture.h"
#include "phongmodule.h" #include "phongmodule.h"
#include <glm/ext.hpp>
#define TEX_ID 0 #define TEX_ID 0
@ -11,9 +12,9 @@ void PhongMaterial::updateShader()
void PhongMaterial::bindAttributes() void PhongMaterial::bindAttributes()
{ {
shader->bind(); shader->bind();
shader->bindVec3(shader->getLocation("materialAmbient"), emission); shader->bindVec3(shader->getLocation("materialAmbient"), emission);
shader->bindVec3(shader->getLocation("materialKd"), diffuse); shader->bindVec3(shader->getLocation("materialKd"), diffuse);
shader->bindVec3(shader->getLocation("materialKs"), specular); shader->bindVec3(shader->getLocation("materialKs"), specular);
shader->bindFloat(shader->getLocation("materialNs"), shininess); shader->bindFloat(shader->getLocation("materialNs"), shininess);
if(diffuse_texture != NULL) if(diffuse_texture != NULL)
@ -23,6 +24,16 @@ void PhongMaterial::bindAttributes()
} }
} }
void PhongMaterial::crappyBindAttributes()
{
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, glm::value_ptr(glm::vec4(emission, 1)));
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, glm::value_ptr(glm::vec4(diffuse, 1)));
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, glm::value_ptr(glm::vec4(specular, 1)));
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
if(diffuse_texture != NULL)
diffuse_texture->bind(TEX_ID);
}
void PhongMaterial::setTexture(Texture* myTexture) void PhongMaterial::setTexture(Texture* myTexture)
{ {
diffuse_texture = myTexture; diffuse_texture = myTexture;

View File

@ -37,6 +37,7 @@ public:
updateShader(); updateShader();
} }
virtual void bindAttributes(); virtual void bindAttributes();
void crappyBindAttributes();
void setTexture(Texture* myTexture); void setTexture(Texture* myTexture);

View File

@ -20,7 +20,8 @@ public:
void addEntity(PhongEntity* myEntity); void addEntity(PhongEntity* myEntity);
void clearEntities(); void clearEntities();
void virtual 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,20 +9,23 @@
SkyboxModule::SkyboxModule(Texture* myCubeMap) SkyboxModule::SkyboxModule(Texture* myCubeMap)
{ {
shader = new Shader(vertSource, fragSource); if(isAvailable())
cubeMap = myCubeMap; {
shader = new Shader(vertSource, fragSource);
cubeMap = myCubeMap;
// set up vao // set up vao
glAssert(glGenVertexArrays(1, &vao)); glAssert(glGenVertexArrays(1, &vao));
glAssert(glBindVertexArray(vao)); glAssert(glBindVertexArray(vao));
glAssert(glGenBuffers(1, &vbo)); glAssert(glGenBuffers(1, &vbo));
glAssert(glBindBuffer(GL_ARRAY_BUFFER, vbo)); glAssert(glBindBuffer(GL_ARRAY_BUFFER, vbo));
glAssert(glBufferData(GL_ARRAY_BUFFER, 108 * sizeof(GLfloat), skyboxVertices, GL_STATIC_DRAW)); glAssert(glBufferData(GL_ARRAY_BUFFER, 108 * sizeof(GLfloat), skyboxVertices, GL_STATIC_DRAW));
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"); mvpLocation = shader->getLocation("MVP");
}
} }
SkyboxModule::~SkyboxModule() SkyboxModule::~SkyboxModule()

View File

@ -23,6 +23,7 @@ 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

@ -1,5 +1,5 @@
#include <glew/glew.h> #include <glew/glew.h>
#include <iostream> #include <cstdio>
#include "sparrowrenderer.h" #include "sparrowrenderer.h"
#include "glassert.h" #include "glassert.h"
#include "camera.h" #include "camera.h"
@ -12,16 +12,18 @@ void SparrowRenderer::initGL(int width, int height)
glewExperimental = GL_TRUE; glewExperimental = GL_TRUE;
GLenum err = glewInit(); GLenum err = glewInit();
if (GLEW_OK != err) if (GLEW_OK != err)
{ fprintf(stderr, "Warning: glewInit failed!\n");
std::cerr << "Warning: glewInit failed!" << std::endl;
}
if (!GLEW_ARB_vertex_program || if (!GLEW_ARB_vertex_program ||
!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)
{ {
std::cerr << "Warning: Shaders not supported!" << std::endl; fprintf(stderr, "Warning: Shaders not supported!\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;
@ -59,7 +61,8 @@ void SparrowRenderer::renderGL()
void SparrowRenderer::addModule(Module* myModule, std::string name) void SparrowRenderer::addModule(Module* myModule, std::string name)
{ {
modules.push_back(ModuleNode(myModule, name)); if(myModule->isAvailable())
modules.push_back(ModuleNode(myModule, name));
} }
int SparrowRenderer::getNbModules() int SparrowRenderer::getNbModules()