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
skyboxmodule.cpp
sparrowrenderer.cpp
crappymodule.cpp
sphere.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:
virtual void renderGL(Camera* myCamera) = 0;
virtual bool isAvailable() {return true;}
};
#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)
{
GLenum buffer_type = isDynamic ? GL_DYNAMIC_DRAW : GL_STATIC_DRAW;

View File

@ -29,13 +29,15 @@ 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;
PhongEntity(Mesh* myMesh);
~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 destroyGL();

View File

@ -1,6 +1,7 @@
#include "phongmaterial.h"
#include "texture.h"
#include "phongmodule.h"
#include <glm/ext.hpp>
#define TEX_ID 0
@ -11,9 +12,9 @@ void PhongMaterial::updateShader()
void PhongMaterial::bindAttributes()
{
shader->bind();
shader->bindVec3(shader->getLocation("materialAmbient"), emission);
shader->bindVec3(shader->getLocation("materialKd"), diffuse);
shader->bind();
shader->bindVec3(shader->getLocation("materialAmbient"), emission);
shader->bindVec3(shader->getLocation("materialKd"), diffuse);
shader->bindVec3(shader->getLocation("materialKs"), specular);
shader->bindFloat(shader->getLocation("materialNs"), shininess);
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)
{
diffuse_texture = myTexture;

View File

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

View File

@ -20,7 +20,8 @@ public:
void addEntity(PhongEntity* myEntity);
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 Shader* getShader(ShaderType slot);

View File

@ -9,20 +9,23 @@
SkyboxModule::SkyboxModule(Texture* myCubeMap)
{
shader = new Shader(vertSource, fragSource);
cubeMap = myCubeMap;
if(isAvailable())
{
shader = new Shader(vertSource, fragSource);
cubeMap = myCubeMap;
// set up vao
glAssert(glGenVertexArrays(1, &vao));
glAssert(glBindVertexArray(vao));
glAssert(glGenBuffers(1, &vbo));
glAssert(glBindBuffer(GL_ARRAY_BUFFER, vbo));
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(glEnableVertexAttribArray(0));
glAssert(glBindVertexArray(0));
// set up vao
glAssert(glGenVertexArrays(1, &vao));
glAssert(glBindVertexArray(vao));
glAssert(glGenBuffers(1, &vbo));
glAssert(glBindBuffer(GL_ARRAY_BUFFER, vbo));
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(glEnableVertexAttribArray(0));
glAssert(glBindVertexArray(0));
mvpLocation = shader->getLocation("MVP");
mvpLocation = shader->getLocation("MVP");
}
}
SkyboxModule::~SkyboxModule()

View File

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

View File

@ -1,5 +1,5 @@
#include <glew/glew.h>
#include <iostream>
#include <cstdio>
#include "sparrowrenderer.h"
#include "glassert.h"
#include "camera.h"
@ -12,16 +12,18 @@ void SparrowRenderer::initGL(int width, int height)
glewExperimental = GL_TRUE;
GLenum err = glewInit();
if (GLEW_OK != err)
{
std::cerr << "Warning: glewInit failed!" << std::endl;
}
fprintf(stderr, "Warning: glewInit failed!\n");
if (!GLEW_ARB_vertex_program ||
!GLEW_ARB_fragment_program ||
!GLEW_ARB_texture_float ||
!GLEW_ARB_draw_buffers ||
!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;
@ -59,7 +61,8 @@ void SparrowRenderer::renderGL()
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()