Commit f824f4eb authored by Anakin's avatar Anakin
Browse files

implement singleton pattern

parent e7d7bec6
......@@ -8,10 +8,13 @@
class OpenGLController
{
public:
OpenGLController();
OpenGLController(int oglMajor, int oglMinor);
static OpenGLController& getInstance(int oglMajor = 4, int oglMinor = 5);
~OpenGLController();
private:
OpenGLController() {};
OpenGLController(int oglMajor, int oglMinor);
private:
int iOglMajorVersion;
int iOglMinorVersion;
......@@ -30,7 +33,7 @@ private:
glm::mat4 m4x4Model;
glm::mat4 m4x4MVP;
Camera camera;
Camera* camera;
Object* object;
struct {
......
......@@ -8,33 +8,33 @@
/////////////////////////////////////////////////////////////////////////
// public constructor/destructor
OpenGLController::OpenGLController() :
iWidth(640),
iHeight(480),
camera(iWidth, iHeight)
OpenGLController& OpenGLController::getInstance(int oglMajor, int oglMinor)
{
initDefault();
processInit();
static OpenGLController instace(oglMajor, oglMinor);
return instace;
}
OpenGLController::~OpenGLController()
{
glDeleteTextures(1, &gluiSamplerID);
glfwTerminate();
}
/////////////////////////////////////////////////////////////////////////
// private constructor
OpenGLController::OpenGLController(int oglMajor, int oglMinor) :
iWidth(640),
iHeight(480),
camera(iWidth, iHeight)
iHeight(480)
{
camera = new Camera(iWidth, iHeight);
initDefault();
iOglMajorVersion = oglMajor;
iOglMinorVersion = oglMinor;
processInit();
}
OpenGLController::~OpenGLController()
{
glDeleteTextures(1, &gluiSamplerID);
glfwTerminate();
}
/////////////////////////////////////////////////////////////////////////
// private functions
......@@ -141,7 +141,7 @@ void OpenGLController::setCallbackFunctions()
glm::mat4 OpenGLController::getMVPMatrix()
{
return camera.getMatrix() * object->getMatrix();
return camera->getMatrix() * object->getMatrix();
}
GLFWwindow * OpenGLController::getWindow() const
......@@ -155,7 +155,7 @@ GLFWwindow * OpenGLController::getWindow() const
void OpenGLController::resize(int width, int height)
{
camera.setSize(width, height);
camera->setSize(width, height);
}
void OpenGLController::addRotX(float value)
......@@ -170,17 +170,17 @@ void OpenGLController::addRotY(float value)
void OpenGLController::addTransX(double value)
{
camera.add2x(value);
camera->add2x(value);
}
void OpenGLController::addTransY(double value)
{
camera.add2y(value);
camera->add2y(value);
}
void OpenGLController::addTransZ(double value)
{
camera.add2z(value);
camera->add2z(value);
}
void OpenGLController::updateScene()
......
......@@ -6,7 +6,7 @@
int main(int argc, char** argv)
{
OpenGLController scene;
OpenGLController scene = OpenGLController::getInstance();
do {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment