-
Notifications
You must be signed in to change notification settings - Fork 0
/
view2_triangle.cpp
84 lines (64 loc) · 1.6 KB
/
view2_triangle.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <vector>
using namespace std;
#include "view2_triangle.h"
#include "util.h"
#include "engine/Mesh.h"
#include "engine/Program.h"
#include "engine/Render.h"
static Program *program = NULL;
static Mesh *mesh = NULL;
static Render *render = NULL;
int view2_triangle_initResources()
{
mesh = new Mesh();
glm::vec4 triangle_vertices[3] = {
glm::vec4(0.0, 0.8, 0.0, 1.0),
glm::vec4(-0.8, -0.8, 0.0, 1.0),
glm::vec4(0.8, -0.8, 0.0, 1.0)
};
for(int i = 0; i < sizeof(triangle_vertices); ++i){
mesh->vertices.push_back(triangle_vertices[i]);
}
mesh->set_attr_v_name("coord2d");
mesh->upload();
program = new Program("glsl/triangle.2.v.glsl",
"glsl/triangle.2.f.glsl");
render = new Render(mesh, program);
return 0;
}
void view2TriangleDisplay()
{
glClearColor(1.0, 1.0, 1.0, 0);
glClear(GL_COLOR_BUFFER_BIT);
render->begin();
render->draw();
render->end();
glutSwapBuffers();
}
void view2_triangle_freeResources()
{
delete program;
delete mesh;
delete render;
}
// TODO: add boost as feature, auto free?
void view2_entry(Window *window)
{
window->display = view2TriangleDisplay;
window->entry = viewEntry;
window->init = view2_triangle_initResources;
window->free = view2_triangle_freeResources;
}
#ifdef TEST_ALONE
int main(int argc, char *argv[])
{
Window window;
resetWindow(&window);
view2_entry(&window);
if (mini_initWindow(argc, argv, &window) == 0){
glutMainLoop();
}
return 0;
}
#endif /* TEST_ALONE */