temp commit of crappymodule implementation
This commit is contained in:
parent
4d6c9b4a00
commit
a68f7107e1
@ -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
23
crappymodule.cpp
Normal 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
20
crappymodule.h
Normal 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
|
1
module.h
1
module.h
@ -7,6 +7,7 @@ class Module
|
||||
{
|
||||
public:
|
||||
virtual void renderGL(Camera* myCamera) = 0;
|
||||
virtual bool isAvailable() {return true;}
|
||||
};
|
||||
|
||||
#endif // MODULE
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -37,6 +37,7 @@ public:
|
||||
updateShader();
|
||||
}
|
||||
virtual void bindAttributes();
|
||||
void crappyBindAttributes();
|
||||
|
||||
void setTexture(Texture* myTexture);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user