added support for crappy renderer in skybox, added entityloader class

This commit is contained in:
Anselme 2015-11-09 21:05:16 +01:00
parent de4936399e
commit 04cc620797
7 changed files with 101 additions and 11 deletions

View File

@ -15,7 +15,7 @@ set(LIB_SRC_LIST
asciientity.cpp
asciimodule.cpp
framebuffer.cpp
gbuffermodule.cpp
gbuffermodule.cpp
lights.cpp
meshbuilder.cpp
phongentity.cpp
@ -24,8 +24,9 @@ set(LIB_SRC_LIST
shader.cpp
skyboxmodule.cpp
sparrowrenderer.cpp
parametricmesh.cpp
parametricmesh.cpp
texture.cpp
entityloader.cpp
)
set(LIBRARY_NAME ${PROJECT_NAME})

7
entityloader.cpp Normal file
View File

@ -0,0 +1,7 @@
#include "entityloader.h"
EntityLoader::EntityLoader()
{
}

10
entityloader.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef ENTITYLOADER_H
#define ENTITYLOADER_H
class EntityLoader
{
public:
EntityLoader();
};
#endif // ENTITYLOADER_H

View File

@ -16,7 +16,7 @@
{\
GLuint err = glGetError(); \
if (err != GL_NO_ERROR) { \
std::cerr<<"erreur OpenGL ("<<__FILE__<<":"<<__LINE__<<", "<<STR(code)<<") : "<<(const char*)gluErrorString (err)<<"("<<err<<")"<<std::endl; \
std::cerr<<"Erreur OpenGL ("<<__FILE__<<":"<<__LINE__<<", "<<STR(code)<<") : "<<(const char*)gluErrorString (err)<<"("<<err<<")"<<std::endl; \
} \
}

View File

@ -38,6 +38,7 @@ void PhongModule::renderGL(Camera* myCamera)
{
if(!SparrowRenderer::isModernOpenGLAvailable())
{
glLoadIdentity();
glAssert(glLightfv(GL_LIGHT0, GL_DIFFUSE, glm::value_ptr(glm::vec4(dirLight->color, 1))));
glAssert(glLightfv(GL_LIGHT0, GL_SPECULAR, glm::value_ptr(glm::vec4(dirLight->color, 1))));
}

View File

@ -1,17 +1,20 @@
#include <glm/mat4x4.hpp>
#include <glm/mat3x3.hpp>
#include <glm/ext.hpp>
#include "skyboxmodule.h"
#include "phongentity.h"
#include "shader.h"
#include "texture.h"
#include "camera.h"
#include "glassert.h"
#include "sparrowrenderer.h"
SkyboxModule::SkyboxModule(Texture* myCubeMap)
{
if(requiresModernOpenGL())
if(SparrowRenderer::isModernOpenGLAvailable())
{
shader = new Shader(vertSource, fragSource);
mvpLocation = shader->getLocation("MVP");
cubeMap = myCubeMap;
// set up vao
@ -23,29 +26,90 @@ SkyboxModule::SkyboxModule(Texture* myCubeMap)
glAssert(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float)*3, NULL));
glAssert(glEnableVertexAttribArray(0));
glAssert(glBindVertexArray(0));
mvpLocation = shader->getLocation("MVP");
}
else
{
displayList = glAssert(glGenLists(1));
glAssert(glNewList(displayList, GL_COMPILE));
glAssert(glDisable(GL_LIGHTING));
glAssert(glEnable(GL_TEXTURE_CUBE_MAP));
myCubeMap->bind(0);
drawCube();
glAssert(glDisable(GL_TEXTURE_CUBE_MAP));
glAssert(glEnable(GL_LIGHTING));
glAssert(glEndList());
}
}
SkyboxModule::~SkyboxModule()
{
glAssert(glDeleteVertexArrays(1, &vao));
glAssert(glDeleteBuffers(1, &vbo));
if(SparrowRenderer::isModernOpenGLAvailable())
{
glAssert(glDeleteVertexArrays(1, &vao));
glAssert(glDeleteBuffers(1, &vbo));
}
}
void SkyboxModule::renderGL(Camera* myCamera)
{
shader->bind();
glm::mat4 mvp = myCamera->getProjectionMatrix() * glm::mat4(glm::mat3(myCamera->getViewMatrix()));
glm::mat4 viewMatrix = glm::mat4(glm::mat3(myCamera->getViewMatrix()));
glm::mat4 projectionMatrix = myCamera->getProjectionMatrix();
glAssert(glDepthMask(GL_FALSE));
if(!SparrowRenderer::isModernOpenGLAvailable())
{
glAssert(glMatrixMode(GL_MODELVIEW));
glAssert(glLoadMatrixf(glm::value_ptr(viewMatrix)));
glAssert(glMatrixMode(GL_PROJECTION));
glAssert(glLoadMatrixf(glm::value_ptr(projectionMatrix)));
glAssert(glCallList(displayList));
}
else
{
shader->bind();
shader->bindMatrix(mvpLocation, projectionMatrix * viewMatrix);
}
cubeMap->bind(0);
shader->bindMatrix(mvpLocation, mvp);
glAssert(glBindVertexArray(vao));
glAssert(glDrawArrays(GL_TRIANGLES, 0, 36));
glAssert(glDepthMask(GL_TRUE));
}
void SkyboxModule::drawCube()
{
const float t = 1;
glAssert(glBegin(GL_QUADS));
glTexCoord3f(-t,-t,-t); glVertex3f(-t,-t,-t);
glTexCoord3f(-t,t,-t); glVertex3f(-t,t,-t);
glTexCoord3f(-t,t,t); glVertex3f(-t,t,t);
glTexCoord3f(-t,-t,t); glVertex3f(-t,-t,t);
glTexCoord3f(t, -t,-t); glVertex3f(t,-t,-t);
glTexCoord3f(t,-t,t); glVertex3f(t,-t,t);
glTexCoord3f(t,t,t); glVertex3f(t,t,t);
glTexCoord3f(t,t,-t); glVertex3f(t,t,-t);
glTexCoord3f(-t,-t,-t); glVertex3f(-t,-t,-t);
glTexCoord3f(-t,-t,t); glVertex3f(-t,-t,t);
glTexCoord3f(t,-t,t); glVertex3f(t,-t,t);
glTexCoord3f(t, -t,-t); glVertex3f(t,-t,-t);
glTexCoord3f(-t,t,-t); glVertex3f(-t,t,-t);
glTexCoord3f(t,t,-t); glVertex3f(t,t,-t);
glTexCoord3f(t,t,t); glVertex3f(t,t,t);
glTexCoord3f(-t,t,t); glVertex3f(-t,t,t);
glTexCoord3f(-t,-t,-t); glVertex3f(-t,-t,-t);
glTexCoord3f(t, -t,-t); glVertex3f(t,-t,-t);
glTexCoord3f(t,t,-t); glVertex3f(t,t,-t);
glTexCoord3f(-t,t,-t); glVertex3f(-t,t,-t);
glTexCoord3f(-t,-t,t); glVertex3f(-t,-t,t);
glTexCoord3f(-t,t,t); glVertex3f(-t,t,t);
glTexCoord3f(t,t,t); glVertex3f(t,t,t);
glTexCoord3f(t,-t,t); glVertex3f(t,-t,t);
glAssert(glEnd());
}
const GLfloat SkyboxModule::skyboxVertices[] = {
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f,

View File

@ -14,15 +14,22 @@ class SkyboxModule : public Module
static const std::string vertSource;
static const std::string fragSource;
// modern opengl variables
GLuint vao;
GLuint vbo;
GLuint mvpLocation;
Shader* shader;
Texture* cubeMap;
//crappy opengl variables
GLuint displayList;
void drawCube();
public:
SkyboxModule(Texture* myCubeMap);
~SkyboxModule();
virtual void renderGL(Camera* myCamera);
virtual bool requiresModernOpenGL() {return false;}
};
#endif // SKYBOXMODULE_H