Skip to content

Commit de0f066

Browse files
Just a test
1 parent 041dd34 commit de0f066

File tree

4 files changed

+49
-5
lines changed

4 files changed

+49
-5
lines changed

glshift/GLManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ void GLShift::GLManager::openWindow(int width, int height, const char* title,boo
4040

4141
void GLShift::GLManager::setRenderer(GLShift::GLRenderer *renderer) {
4242
this->renderer = renderer;
43+
this->renderer->setWindow(this->window);
4344
// Call initialization function
4445
this->renderer->init();
4546
}
@@ -57,7 +58,6 @@ void GLShift::GLManager::run() {
5758
while(!glfwWindowShouldClose(this->window)) {
5859
this->renderer->render();
5960

60-
glClear(GL_COLOR_BUFFER_BIT);
6161
glfwSwapBuffers(this->window);
6262
glfwPollEvents();
6363
}

glshift/GLRenderer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
// Created by lesscomplex on 08/03/2020.
33
//
44

5-
#include "GLRenderer.h"
5+
#include "GLRenderer.h"
6+
7+
void GLShift::GLRenderer::setWindow(GLFWwindow * context) {
8+
this->window = context;
9+
}

glshift/GLRenderer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class GLShift::GLRenderer {
1717
* Override to provide code for the initialization loop
1818
*/
1919
virtual void init() = 0;
20+
void setWindow(GLFWwindow * context);
21+
private:
22+
GLFWwindow * window;
2023
};
2124

2225
#endif //YOURAPPNAME_GLRENDERER_H

main.cpp

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,59 @@
11
#include "glshift/GLShift.h"
2+
#include <vector>
3+
4+
#define numVAOs 1
5+
6+
GLuint createShaderProgram() {
7+
const char* vShaderSource =
8+
"#version 430 \n"
9+
"void main(void) \n"
10+
"{ gl_Position = vec4(0.0, 0.0, 0.0, 1.0); }";
11+
const char* fShaderSource =
12+
"#version 430 \n"
13+
"out vec4 color; \n"
14+
"void main(void) \n"
15+
"{ color = vec4(0.0, 1.0, 1.0, 1.0); }";
16+
17+
GLuint vShader = glCreateShader(GL_VERTEX_SHADER);
18+
GLuint fShader = glCreateShader(GL_FRAGMENT_SHADER);
19+
glShaderSource(vShader, 1, &vShaderSource, NULL); glCompileShader(vShader);
20+
glShaderSource(fShader, 1, &fShaderSource, NULL); glCompileShader(fShader);
21+
22+
GLuint vfProgram = glCreateProgram();
23+
glAttachShader(vfProgram, vShader); glAttachShader(vfProgram, fShader);
24+
glLinkProgram(vfProgram);
25+
return vfProgram;
26+
}
227

328
/**
429
* Example for a renderer implementation
530
*/
631
class MyRenderer : public GLShift::GLRenderer {
732
public:
833
void render() override {
9-
glClearColor(1, 0, 0, 1);
34+
glClearColor(1.0, 0.0, 0.0, 1.0);
35+
glClear(GL_COLOR_BUFFER_BIT);
36+
37+
glUseProgram(this->renderingProgram);
38+
glDrawArrays(GL_POINTS, 0, 1);
39+
}
40+
41+
void init() override {
42+
this->renderingProgram = createShaderProgram();
43+
glGenVertexArrays(numVAOs, this->vao);
44+
glBindVertexArray(vao[0]);
1045
}
1146

12-
void init() override {}
47+
private:
48+
GLuint renderingProgram;
49+
GLuint vao[numVAOs];
1350
};
1451

1552
int main() {
1653
/**
1754
* Example for a GLManager implementation
1855
*/
19-
GLShift::GLManager glManager = GLShift::GLManager();
56+
GLShift::GLManager glManager = GLShift::GLManager(4, 3);
2057
glManager.openWindow(600, 300, "Yeahh!");
2158
glManager.setRenderer(new MyRenderer());
2259
glManager.run();

0 commit comments

Comments
 (0)