Moving application class to it's own file.
This commit is contained in:
parent
765471ca99
commit
ced962f403
85
application.cc
Normal file
85
application.cc
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
#include "application.hh"
|
||||||
|
|
||||||
|
#include <ACGL/OpenGL/Creator/ShaderProgramCreator.hh>
|
||||||
|
|
||||||
|
Application::Application() {
|
||||||
|
graphics = Graphics(glm::uvec2(1024, 786), 0.1f, 150.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::init()
|
||||||
|
{
|
||||||
|
// Don't change this!
|
||||||
|
ignoredMouseUpdates = 0;
|
||||||
|
cameraLock = true;
|
||||||
|
// set Skybox size
|
||||||
|
level.setSkydomeSize((graphics.getFarPlane()/2.0f)-10.0f);
|
||||||
|
|
||||||
|
// define where shaders and textures can be found:
|
||||||
|
ACGL::Base::Settings::the()->setResourcePath("../");
|
||||||
|
ACGL::Base::Settings::the()->setShaderPath("Shader/");
|
||||||
|
ACGL::Base::Settings::the()->setTexturePath("Levels/Textures/");
|
||||||
|
ACGL::Base::Settings::the()->setGeometryPath("Levels/Geometry/");
|
||||||
|
|
||||||
|
// construct VAO to give shader correct Attribute locations
|
||||||
|
ACGL::OpenGL::SharedArrayBuffer ab = std::make_shared<ACGL::OpenGL::ArrayBuffer>();
|
||||||
|
ab->defineAttribute("aPosition", GL_FLOAT, 3);
|
||||||
|
ab->defineAttribute("aTexCoord", GL_FLOAT, 2);
|
||||||
|
ab->defineAttribute("aNormal", GL_FLOAT, 3);
|
||||||
|
ACGL::OpenGL::SharedVertexArrayObject vao = std::make_shared<ACGL::OpenGL::VertexArrayObject>();
|
||||||
|
vao->attachAllAttributes(ab);
|
||||||
|
|
||||||
|
// look up all shader files starting with 'phong' and build a ShaderProgram from it:
|
||||||
|
shader = ACGL::OpenGL::ShaderProgramCreator("phong").attributeLocations(
|
||||||
|
vao->getAttributeLocations()).create();
|
||||||
|
shader->use();
|
||||||
|
|
||||||
|
// load Level
|
||||||
|
level.load();
|
||||||
|
|
||||||
|
// just in case: check for errors
|
||||||
|
openGLCriticalError();
|
||||||
|
}
|
||||||
|
|
||||||
|
Graphics* Application::getGraphics() {
|
||||||
|
return &graphics;
|
||||||
|
}
|
||||||
|
|
||||||
|
Level* Application::getLevel() {
|
||||||
|
return &level;
|
||||||
|
}
|
||||||
|
|
||||||
|
ACGL::OpenGL::SharedShaderProgram Application::getShader() {
|
||||||
|
return shader;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::setFocused(bool focused) {
|
||||||
|
this->focused = focused;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Application::isFocused() {
|
||||||
|
return focused;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::setCameraLock(bool locked) {
|
||||||
|
// Prevent camera jumping huge distances
|
||||||
|
if (!locked) {
|
||||||
|
ignoreNextMouseUpdate();
|
||||||
|
}
|
||||||
|
cameraLock = locked;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::ignoreNextMouseUpdate() {
|
||||||
|
ignoredMouseUpdates++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::ignoredOneMouseUpdate() {
|
||||||
|
ignoredMouseUpdates--;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Application::getIgnoredMouseUpdates() {
|
||||||
|
return ignoredMouseUpdates;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Application::isLocked() {
|
||||||
|
return cameraLock;
|
||||||
|
}
|
31
application.hh
Normal file
31
application.hh
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#ifndef APPLICATION_HH_INCLUDED
|
||||||
|
#define APPLICATION_HH_INCLUDED
|
||||||
|
|
||||||
|
#include "physics.hh"
|
||||||
|
#include "graphics.hh"
|
||||||
|
#include "level.hh"
|
||||||
|
|
||||||
|
class Application {
|
||||||
|
public:
|
||||||
|
Application();
|
||||||
|
Graphics* getGraphics();
|
||||||
|
Level* getLevel();
|
||||||
|
ACGL::OpenGL::SharedShaderProgram getShader();
|
||||||
|
void init();
|
||||||
|
void setFocused(bool focused);
|
||||||
|
bool isFocused();
|
||||||
|
void setCameraLock(bool locked);
|
||||||
|
bool isLocked();
|
||||||
|
void ignoreNextMouseUpdate();
|
||||||
|
int getIgnoredMouseUpdates();
|
||||||
|
void ignoredOneMouseUpdate();
|
||||||
|
private:
|
||||||
|
int ignoredMouseUpdates;
|
||||||
|
bool focused;
|
||||||
|
bool cameraLock;
|
||||||
|
Graphics graphics;
|
||||||
|
Level level;
|
||||||
|
ACGL::OpenGL::SharedShaderProgram shader;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
83
main.cc
83
main.cc
@ -11,60 +11,10 @@
|
|||||||
#include <ACGL/Utils/FileHelpers.hh>
|
#include <ACGL/Utils/FileHelpers.hh>
|
||||||
#include <ACGL/Utils/StringHelpers.hh>
|
#include <ACGL/Utils/StringHelpers.hh>
|
||||||
#include <ACGL/OpenGL/Objects/VertexArrayObject.hh>
|
#include <ACGL/OpenGL/Objects/VertexArrayObject.hh>
|
||||||
#include <ACGL/OpenGL/Creator/ShaderProgramCreator.hh>
|
|
||||||
|
|
||||||
#include <ACGL/OpenGL/glloaders/extensions.hh>
|
#include <ACGL/OpenGL/glloaders/extensions.hh>
|
||||||
#include <ACGL/Base/Settings.hh>
|
#include <ACGL/Base/Settings.hh>
|
||||||
|
|
||||||
Application::Application() {
|
|
||||||
graphics = Graphics(glm::uvec2(1024, 786), 0.1f, 150.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
Graphics* Application::getGraphics() {
|
|
||||||
return &graphics;
|
|
||||||
}
|
|
||||||
|
|
||||||
Level* Application::getLevel() {
|
|
||||||
return &level;
|
|
||||||
}
|
|
||||||
|
|
||||||
ACGL::OpenGL::SharedShaderProgram Application::getShader() {
|
|
||||||
return shader;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::init()
|
|
||||||
{
|
|
||||||
// Don't change this!
|
|
||||||
ignoredMouseUpdates = 0;
|
|
||||||
cameraLock = true;
|
|
||||||
// set Skybox size
|
|
||||||
level.setSkydomeSize((graphics.getFarPlane()/2.0f)-10.0f);
|
|
||||||
|
|
||||||
// define where shaders and textures can be found:
|
|
||||||
ACGL::Base::Settings::the()->setResourcePath("../");
|
|
||||||
ACGL::Base::Settings::the()->setShaderPath("Shader/");
|
|
||||||
ACGL::Base::Settings::the()->setTexturePath("Levels/Textures/");
|
|
||||||
ACGL::Base::Settings::the()->setGeometryPath("Levels/Geometry/");
|
|
||||||
|
|
||||||
// construct VAO to give shader correct Attribute locations
|
|
||||||
ACGL::OpenGL::SharedArrayBuffer ab = std::make_shared<ACGL::OpenGL::ArrayBuffer>();
|
|
||||||
ab->defineAttribute("aPosition", GL_FLOAT, 3);
|
|
||||||
ab->defineAttribute("aTexCoord", GL_FLOAT, 2);
|
|
||||||
ab->defineAttribute("aNormal", GL_FLOAT, 3);
|
|
||||||
ACGL::OpenGL::SharedVertexArrayObject vao = std::make_shared<ACGL::OpenGL::VertexArrayObject>();
|
|
||||||
vao->attachAllAttributes(ab);
|
|
||||||
|
|
||||||
// look up all shader files starting with 'phong' and build a ShaderProgram from it:
|
|
||||||
shader = ACGL::OpenGL::ShaderProgramCreator("phong").attributeLocations(
|
|
||||||
vao->getAttributeLocations()).create();
|
|
||||||
shader->use();
|
|
||||||
|
|
||||||
// load Level
|
|
||||||
level.load();
|
|
||||||
|
|
||||||
// just in case: check for errors
|
|
||||||
openGLCriticalError();
|
|
||||||
}
|
|
||||||
|
|
||||||
void resizeCallback(GLFWwindow* window, int newWidth, int newHeight)
|
void resizeCallback(GLFWwindow* window, int newWidth, int newHeight)
|
||||||
{
|
{
|
||||||
@ -110,39 +60,6 @@ static void focusCallback(GLFWwindow* window, int focused) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::setFocused(bool focused) {
|
|
||||||
this->focused = focused;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Application::isFocused() {
|
|
||||||
return focused;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::setCameraLock(bool locked) {
|
|
||||||
// Prevent camera jumping huge distances
|
|
||||||
if (!locked) {
|
|
||||||
ignoreNextMouseUpdate();
|
|
||||||
}
|
|
||||||
cameraLock = locked;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::ignoreNextMouseUpdate() {
|
|
||||||
ignoredMouseUpdates++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::ignoredOneMouseUpdate() {
|
|
||||||
ignoredMouseUpdates--;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Application::getIgnoredMouseUpdates() {
|
|
||||||
return ignoredMouseUpdates;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Application::isLocked() {
|
|
||||||
return cameraLock;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
//Application app = Application();
|
//Application app = Application();
|
||||||
|
29
main.hh
29
main.hh
@ -5,35 +5,8 @@
|
|||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <ACGL/OpenGL/Objects/ArrayBuffer.hh>
|
#include <ACGL/OpenGL/Objects/ArrayBuffer.hh>
|
||||||
////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#include "physics.hh"
|
#include "application.hh"
|
||||||
#include "graphics.hh"
|
|
||||||
#include "level.hh"
|
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////
|
|
||||||
class Application {
|
|
||||||
public:
|
|
||||||
Application();
|
|
||||||
Graphics* getGraphics();
|
|
||||||
Level* getLevel();
|
|
||||||
ACGL::OpenGL::SharedShaderProgram getShader();
|
|
||||||
void init();
|
|
||||||
void setFocused(bool focused);
|
|
||||||
bool isFocused();
|
|
||||||
void setCameraLock(bool locked);
|
|
||||||
bool isLocked();
|
|
||||||
void ignoreNextMouseUpdate();
|
|
||||||
int getIgnoredMouseUpdates();
|
|
||||||
void ignoredOneMouseUpdate();
|
|
||||||
private:
|
|
||||||
int ignoredMouseUpdates;
|
|
||||||
bool focused;
|
|
||||||
bool cameraLock;
|
|
||||||
Graphics graphics;
|
|
||||||
Level level;
|
|
||||||
ACGL::OpenGL::SharedShaderProgram shader;
|
|
||||||
};
|
|
||||||
|
|
||||||
Application app;
|
Application app;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user