Rewrote graphics to use new classes.
This commit is contained in:
parent
11229430cb
commit
752ee67481
53
graphics.cc
53
graphics.cc
@ -1,38 +1,38 @@
|
|||||||
#include "graphics.hh"
|
#include "graphics.hh"
|
||||||
|
|
||||||
using namespace std;
|
#include "model.hh"
|
||||||
using namespace ACGL::OpenGL;
|
#include "object.hh"
|
||||||
using namespace ACGL::Base;
|
#include "texture.hh"
|
||||||
using namespace ACGL::Utils;
|
#include "shader.hh"
|
||||||
|
|
||||||
SharedVertexArrayObject vaoBunny;
|
using namespace std;
|
||||||
SharedShaderProgram normalsAsColorShader;
|
|
||||||
SharedTexture2D bunnyTexture;
|
Model model;
|
||||||
|
Texture texture;
|
||||||
|
Shader shader;
|
||||||
|
Object object;
|
||||||
|
|
||||||
// gets called after the OpenGL window is prepared:
|
// gets called after the OpenGL window is prepared:
|
||||||
void initCustomResources()
|
void initCustomResources()
|
||||||
{
|
{
|
||||||
// define where shaders and textures can be found:
|
// define where shaders and textures can be found:
|
||||||
Settings::the()->setResourcePath("../");
|
ACGL::Base::Settings::the()->setResourcePath("../");
|
||||||
Settings::the()->setShaderPath("Shader/");
|
ACGL::Base::Settings::the()->setShaderPath("Shader/");
|
||||||
Settings::the()->setTexturePath("Geometry/");
|
ACGL::Base::Settings::the()->setTexturePath("Geometry/");
|
||||||
Settings::the()->setGeometryPath("Geometry/");
|
ACGL::Base::Settings::the()->setGeometryPath("Geometry/");
|
||||||
|
|
||||||
// load the geometry of the stanford bunny and build a VAO:
|
// load the geometry of the stanford bunny and build a VAO:
|
||||||
vaoBunny = VertexArrayObjectCreator("Bunny.obj").create();
|
model = Model("Bunny.obj");
|
||||||
vaoBunny->bind();
|
|
||||||
|
|
||||||
// load a texture:
|
// load a texture:
|
||||||
bunnyTexture = Texture2DFileManager::the()->get( Texture2DCreator("clownfishBunny.png"));
|
texture = Texture("clownfishBunny.png");
|
||||||
// alternatively, without the Managers:
|
|
||||||
//bunnyTexture = loadTexture2D( "../shared/Geometry/clownfishBunny.png" );
|
|
||||||
|
|
||||||
// look up all shader files starting with 'HelloWorld' and build a ShaderProgram from it:
|
// look up all shader files starting with 'HelloWorld' and build a ShaderProgram from it:
|
||||||
normalsAsColorShader = ShaderProgramCreator("HelloWorld").attributeLocations( vaoBunny->getAttributeLocations() ).create();
|
shader = Shader("HelloWorld", model);
|
||||||
normalsAsColorShader->use();
|
|
||||||
|
|
||||||
// set texture uniform and bind texture to the same texture unit:
|
//Create object
|
||||||
normalsAsColorShader->setTexture( "uTexture", bunnyTexture, 0 );
|
object = Object(model, texture, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f),
|
||||||
|
glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 0.0f, 0.0f), shader);
|
||||||
|
|
||||||
// just in case: check for errors
|
// just in case: check for errors
|
||||||
openGLCriticalError();
|
openGLCriticalError();
|
||||||
@ -45,23 +45,16 @@ void deleteCustomResources()
|
|||||||
|
|
||||||
void draw( float runTime )
|
void draw( float runTime )
|
||||||
{
|
{
|
||||||
// reload textures every 100 frames:
|
|
||||||
static int frame = 0;
|
|
||||||
frame++;
|
|
||||||
if (frame % 100 == 0) {
|
|
||||||
Texture2DFileManager::the()->updateAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
// clear the framebuffer:
|
// clear the framebuffer:
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
// set view and projection matrix:
|
// set view and projection matrix:
|
||||||
glm::mat4 viewMatrix = glm::translate(glm::vec3(0.0f, -1.0f, -2.0f)) * glm::rotate<float>(1.0472f * runTime, glm::vec3(0.0f, 1.0f, 0.0f)) * glm::scale<float>(glm::vec3(0.25f));
|
glm::mat4 viewMatrix = glm::translate(glm::vec3(0.0f, -1.0f, -2.0f)) * glm::rotate<float>(1.0472f * runTime, glm::vec3(0.0f, 1.0f, 0.0f)) * glm::scale<float>(glm::vec3(0.25f));
|
||||||
normalsAsColorShader->setUniform( "uViewMatrix", viewMatrix );
|
shader.getReference()->setUniform( "uViewMatrix", viewMatrix );
|
||||||
normalsAsColorShader->setUniform( "uProjectionMatrix", buildFrustum(75.0, 0.1, 100.0, (float)g_windowSize.x/(float)g_windowSize.y) );
|
shader.getReference()->setUniform( "uProjectionMatrix", buildFrustum(75.0, 0.1, 100.0, (float)g_windowSize.x/(float)g_windowSize.y) );
|
||||||
|
|
||||||
// render the bunny:
|
// render the bunny:
|
||||||
vaoBunny->render();
|
object.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
void resizeCallback( GLFWwindow *, int newWidth, int newHeight )
|
void resizeCallback( GLFWwindow *, int newWidth, int newHeight )
|
||||||
|
@ -3,14 +3,8 @@
|
|||||||
|
|
||||||
#include "main.hh"
|
#include "main.hh"
|
||||||
|
|
||||||
#include <ACGL/OpenGL/Creator/ShaderProgramCreator.hh>
|
|
||||||
#include <ACGL/OpenGL/Creator/VertexArrayObjectCreator.hh>
|
|
||||||
#include <ACGL/OpenGL/Creator/Texture2DCreator.hh>
|
|
||||||
#include <ACGL/OpenGL/Objects.hh>
|
|
||||||
#include <ACGL/Base/Settings.hh>
|
#include <ACGL/Base/Settings.hh>
|
||||||
#include <ACGL/Math/Math.hh>
|
#include <ACGL/Math/Math.hh>
|
||||||
#include <ACGL/OpenGL/Data/TextureLoadStore.hh>
|
|
||||||
#include <ACGL/OpenGL/Managers.hh>
|
|
||||||
|
|
||||||
// gets called after the OpenGL window is prepared, init of example specific stuff:
|
// gets called after the OpenGL window is prepared, init of example specific stuff:
|
||||||
void initCustomResources();
|
void initCustomResources();
|
||||||
|
Loading…
Reference in New Issue
Block a user