added support for crappy renderer in skybox, added entityloader class
This commit is contained in:
parent
de4936399e
commit
04cc620797
@ -15,7 +15,7 @@ set(LIB_SRC_LIST
|
|||||||
asciientity.cpp
|
asciientity.cpp
|
||||||
asciimodule.cpp
|
asciimodule.cpp
|
||||||
framebuffer.cpp
|
framebuffer.cpp
|
||||||
gbuffermodule.cpp
|
gbuffermodule.cpp
|
||||||
lights.cpp
|
lights.cpp
|
||||||
meshbuilder.cpp
|
meshbuilder.cpp
|
||||||
phongentity.cpp
|
phongentity.cpp
|
||||||
@ -24,8 +24,9 @@ set(LIB_SRC_LIST
|
|||||||
shader.cpp
|
shader.cpp
|
||||||
skyboxmodule.cpp
|
skyboxmodule.cpp
|
||||||
sparrowrenderer.cpp
|
sparrowrenderer.cpp
|
||||||
parametricmesh.cpp
|
parametricmesh.cpp
|
||||||
texture.cpp
|
texture.cpp
|
||||||
|
entityloader.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(LIBRARY_NAME ${PROJECT_NAME})
|
set(LIBRARY_NAME ${PROJECT_NAME})
|
||||||
|
7
entityloader.cpp
Normal file
7
entityloader.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "entityloader.h"
|
||||||
|
|
||||||
|
EntityLoader::EntityLoader()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
10
entityloader.h
Normal file
10
entityloader.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#ifndef ENTITYLOADER_H
|
||||||
|
#define ENTITYLOADER_H
|
||||||
|
|
||||||
|
class EntityLoader
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EntityLoader();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ENTITYLOADER_H
|
@ -16,7 +16,7 @@
|
|||||||
{\
|
{\
|
||||||
GLuint err = glGetError(); \
|
GLuint err = glGetError(); \
|
||||||
if (err != GL_NO_ERROR) { \
|
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; \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ void PhongModule::renderGL(Camera* myCamera)
|
|||||||
{
|
{
|
||||||
if(!SparrowRenderer::isModernOpenGLAvailable())
|
if(!SparrowRenderer::isModernOpenGLAvailable())
|
||||||
{
|
{
|
||||||
|
glLoadIdentity();
|
||||||
glAssert(glLightfv(GL_LIGHT0, GL_DIFFUSE, glm::value_ptr(glm::vec4(dirLight->color, 1))));
|
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))));
|
glAssert(glLightfv(GL_LIGHT0, GL_SPECULAR, glm::value_ptr(glm::vec4(dirLight->color, 1))));
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,20 @@
|
|||||||
#include <glm/mat4x4.hpp>
|
#include <glm/mat4x4.hpp>
|
||||||
#include <glm/mat3x3.hpp>
|
#include <glm/mat3x3.hpp>
|
||||||
|
#include <glm/ext.hpp>
|
||||||
#include "skyboxmodule.h"
|
#include "skyboxmodule.h"
|
||||||
#include "phongentity.h"
|
#include "phongentity.h"
|
||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
#include "glassert.h"
|
#include "glassert.h"
|
||||||
|
#include "sparrowrenderer.h"
|
||||||
|
|
||||||
SkyboxModule::SkyboxModule(Texture* myCubeMap)
|
SkyboxModule::SkyboxModule(Texture* myCubeMap)
|
||||||
{
|
{
|
||||||
if(requiresModernOpenGL())
|
if(SparrowRenderer::isModernOpenGLAvailable())
|
||||||
{
|
{
|
||||||
shader = new Shader(vertSource, fragSource);
|
shader = new Shader(vertSource, fragSource);
|
||||||
|
mvpLocation = shader->getLocation("MVP");
|
||||||
cubeMap = myCubeMap;
|
cubeMap = myCubeMap;
|
||||||
|
|
||||||
// set up vao
|
// set up vao
|
||||||
@ -23,29 +26,90 @@ SkyboxModule::SkyboxModule(Texture* myCubeMap)
|
|||||||
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");
|
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()
|
SkyboxModule::~SkyboxModule()
|
||||||
{
|
{
|
||||||
glAssert(glDeleteVertexArrays(1, &vao));
|
if(SparrowRenderer::isModernOpenGLAvailable())
|
||||||
glAssert(glDeleteBuffers(1, &vbo));
|
{
|
||||||
|
glAssert(glDeleteVertexArrays(1, &vao));
|
||||||
|
glAssert(glDeleteBuffers(1, &vbo));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkyboxModule::renderGL(Camera* myCamera)
|
void SkyboxModule::renderGL(Camera* myCamera)
|
||||||
{
|
{
|
||||||
shader->bind();
|
glm::mat4 viewMatrix = glm::mat4(glm::mat3(myCamera->getViewMatrix()));
|
||||||
glm::mat4 mvp = myCamera->getProjectionMatrix() * glm::mat4(glm::mat3(myCamera->getViewMatrix()));
|
glm::mat4 projectionMatrix = myCamera->getProjectionMatrix();
|
||||||
glAssert(glDepthMask(GL_FALSE));
|
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);
|
cubeMap->bind(0);
|
||||||
shader->bindMatrix(mvpLocation, mvp);
|
|
||||||
glAssert(glBindVertexArray(vao));
|
glAssert(glBindVertexArray(vao));
|
||||||
glAssert(glDrawArrays(GL_TRIANGLES, 0, 36));
|
glAssert(glDrawArrays(GL_TRIANGLES, 0, 36));
|
||||||
glAssert(glDepthMask(GL_TRUE));
|
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[] = {
|
const GLfloat SkyboxModule::skyboxVertices[] = {
|
||||||
-1.0f, 1.0f, -1.0f,
|
-1.0f, 1.0f, -1.0f,
|
||||||
-1.0f, -1.0f, -1.0f,
|
-1.0f, -1.0f, -1.0f,
|
||||||
|
@ -14,15 +14,22 @@ class SkyboxModule : public Module
|
|||||||
static const std::string vertSource;
|
static const std::string vertSource;
|
||||||
static const std::string fragSource;
|
static const std::string fragSource;
|
||||||
|
|
||||||
|
// modern opengl variables
|
||||||
GLuint vao;
|
GLuint vao;
|
||||||
GLuint vbo;
|
GLuint vbo;
|
||||||
GLuint mvpLocation;
|
GLuint mvpLocation;
|
||||||
Shader* shader;
|
Shader* shader;
|
||||||
Texture* cubeMap;
|
Texture* cubeMap;
|
||||||
|
//crappy opengl variables
|
||||||
|
GLuint displayList;
|
||||||
|
|
||||||
|
void drawCube();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SkyboxModule(Texture* myCubeMap);
|
SkyboxModule(Texture* myCubeMap);
|
||||||
~SkyboxModule();
|
~SkyboxModule();
|
||||||
virtual void renderGL(Camera* myCamera);
|
virtual void renderGL(Camera* myCamera);
|
||||||
|
virtual bool requiresModernOpenGL() {return false;}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SKYBOXMODULE_H
|
#endif // SKYBOXMODULE_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user