Skip to content

Commit

Permalink
Just a test
Browse files Browse the repository at this point in the history
  • Loading branch information
LessComplexity committed Mar 8, 2020
1 parent 041dd34 commit de0f066
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion 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;
this->renderer->setWindow(this->window);
// Call initialization function
this->renderer->init();
}
Expand All @@ -57,7 +58,6 @@ void GLShift::GLManager::run() {
while(!glfwWindowShouldClose(this->window)) {
this->renderer->render();

glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(this->window);
glfwPollEvents();
}
Expand Down
6 changes: 5 additions & 1 deletion glshift/GLRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
// Created by lesscomplex on 08/03/2020.
//

#include "GLRenderer.h"
#include "GLRenderer.h"

void GLShift::GLRenderer::setWindow(GLFWwindow * context) {
this->window = context;
}
3 changes: 3 additions & 0 deletions glshift/GLRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class GLShift::GLRenderer {
* Override to provide code for the initialization loop
*/
virtual void init() = 0;
void setWindow(GLFWwindow * context);
private:
GLFWwindow * window;
};

#endif //YOURAPPNAME_GLRENDERER_H
43 changes: 40 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,59 @@
#include "glshift/GLShift.h"
#include <vector>

#define numVAOs 1

GLuint createShaderProgram() {
const char* vShaderSource =
"#version 430 \n"
"void main(void) \n"
"{ gl_Position = vec4(0.0, 0.0, 0.0, 1.0); }";
const char* fShaderSource =
"#version 430 \n"
"out vec4 color; \n"
"void main(void) \n"
"{ color = vec4(0.0, 1.0, 1.0, 1.0); }";

GLuint vShader = glCreateShader(GL_VERTEX_SHADER);
GLuint fShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(vShader, 1, &vShaderSource, NULL); glCompileShader(vShader);
glShaderSource(fShader, 1, &fShaderSource, NULL); glCompileShader(fShader);

GLuint vfProgram = glCreateProgram();
glAttachShader(vfProgram, vShader); glAttachShader(vfProgram, fShader);
glLinkProgram(vfProgram);
return vfProgram;
}

/**
* Example for a renderer implementation
*/
class MyRenderer : public GLShift::GLRenderer {
public:
void render() override {
glClearColor(1, 0, 0, 1);
glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);

glUseProgram(this->renderingProgram);
glDrawArrays(GL_POINTS, 0, 1);
}

void init() override {
this->renderingProgram = createShaderProgram();
glGenVertexArrays(numVAOs, this->vao);
glBindVertexArray(vao[0]);
}

void init() override {}
private:
GLuint renderingProgram;
GLuint vao[numVAOs];
};

int main() {
/**
* Example for a GLManager implementation
*/
GLShift::GLManager glManager = GLShift::GLManager();
GLShift::GLManager glManager = GLShift::GLManager(4, 3);
glManager.openWindow(600, 300, "Yeahh!");
glManager.setRenderer(new MyRenderer());
glManager.run();
Expand Down

0 comments on commit de0f066

Please sign in to comment.