-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
60 lines (52 loc) · 1.69 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "glshift/GLShift.h"
#define numVAOs 1
/**
* Example for a renderer implementation
*/
class MyRenderer : public GLShift::GLRenderer {
public:
void render() override {
glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
// Rather use this function instead of glUseProgram
// Since it checks for availability of the program
this->useProgram("main");
glPointSize(30);
glDrawArrays(GL_POINTS, 0, 1);
}
void init() override {
// Example for fixed shader
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"
"{\n"
"if(gl_FragCoord.x < 300) color = vec4(0.0, 0.0, 1.0, 1.0);\n"
"else color = vec4(0.0, 1.0, 0.0, 1.0);\n"
"}";
// Example for creating and linking a shader pipeline
this->createProgram("main");
this->addShader("main", vShaderSource, GL_VERTEX_SHADER);
this->addShader("main", fShaderSource, GL_FRAGMENT_SHADER);
this->linkProgram("main");
// Just a point
glGenVertexArrays(numVAOs, this->vao);
glBindVertexArray(vao[0]);
}
private:
GLuint vao[numVAOs];
};
int main() {
/*
* Example for a GLManager implementation
*/
GLShift::GLManager glManager = GLShift::GLManager(4, 3);
glManager.openWindow(600, 300, "Yeahh!");
glManager.setRenderer(new MyRenderer());
glManager.run();
return 0;
}