Skip to content

Commit

Permalink
Added documenting comments
Browse files Browse the repository at this point in the history
  • Loading branch information
LessComplexity committed Mar 8, 2020
1 parent 5035e72 commit 041dd34
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 12 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ add_executable(${APP_NAME} main.cpp
glshift/GLManager.h
glshift/GLShift.h
glshift/definitions.h
glshift/GLRenderer.h glshift/GLRenderer.cpp)
glshift/GLRenderer.h
glshift/GLRenderer.cpp)

# Linking libraries for windows/linux
# TODO: add mac support
if(WIN32)
# Neccessary variables
SET(LINK_GL_LIBS ${CMAKE_SOURCE_DIR}/lib/win/${ARCHITECTURE_TO_USE})
Expand Down
1 change: 1 addition & 0 deletions glshift/GLManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void GLShift::GLManager::openWindow(int width, int height, const char* title,boo

void GLShift::GLManager::setRenderer(GLShift::GLRenderer *renderer) {
this->renderer = renderer;
// Call initialization function
this->renderer->init();
}

Expand Down
30 changes: 29 additions & 1 deletion glshift/GLManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,40 @@

class GLShift::GLManager {
public:
/**
* Initializes the GLFW environment
*/
GLManager();
~GLManager();
/**
* Initializes the GLFW environment & sets the specific version
* of OpenGL to use
* @param major
* @param minor
*/
GLManager(signed int major, signed int minor);
/**
* Terminated the GLFW environment
*/
~GLManager();

/**
* Sets the version of OpenGL to use
* @param major
* @param minor
*/
void setVersion(signed int major, signed int minor);
/**
* Sets the renderer object to use for rendering on the window
* @param renderer
*/
void setRenderer(GLRenderer * renderer);
/**
* Opens a window with GLFW context
* @param width
* @param height
* @param title
* @param isFullScreen Set true to make full screen app
*/
void openWindow(signed int width, signed int height, const char* title, bool isFullScreen = false);
void run();
private:
Expand Down
6 changes: 1 addition & 5 deletions glshift/GLRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,4 @@
// Created by lesscomplex on 08/03/2020.
//

#include "GLRenderer.h"

GLShift::GLRenderer::GLRenderer(GLShift::GLManager *context) {
this->context = context;
}
#include "GLRenderer.h"
9 changes: 6 additions & 3 deletions glshift/GLRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@

class GLShift::GLRenderer {
public:
explicit GLRenderer(GLManager* context);
/**
* Override to provide code for the rendering loop
*/
virtual void render() = 0;
/**
* Override to provide code for the initialization loop
*/
virtual void init() = 0;
private:
GLManager * context;
};

#endif //YOURAPPNAME_GLRENDERER_H
6 changes: 6 additions & 0 deletions glshift/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
#include <GLFW/glfw3.h>

namespace GLShift {
/**
* Helps manage a window with GLFW context
*/
class GLManager;
/**
* Defines the functionality for rendering the screen
*/
class GLRenderer;
}

Expand Down
9 changes: 7 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "glshift/GLShift.h"

/**
* Example for a renderer implementation
*/
class MyRenderer : public GLShift::GLRenderer {
using GLShift::GLRenderer::GLRenderer; // Import constructor
public:
void render() override {
glClearColor(1, 0, 0, 1);
Expand All @@ -11,9 +13,12 @@ class MyRenderer : public GLShift::GLRenderer {
};

int main() {
/**
* Example for a GLManager implementation
*/
GLShift::GLManager glManager = GLShift::GLManager();
glManager.openWindow(600, 300, "Yeahh!");
glManager.setRenderer(new MyRenderer(&glManager));
glManager.setRenderer(new MyRenderer());
glManager.run();
return 0;
}

0 comments on commit 041dd34

Please sign in to comment.