-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleRender.cpp
More file actions
127 lines (105 loc) · 2.78 KB
/
ModuleRender.cpp
File metadata and controls
127 lines (105 loc) · 2.78 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "Application.h"
#include "ModuleProgram.h"
#include "ModuleCamera.h"
#include "ModuleTexture.h"
#include "ModuleRender.h"
#include "Model.h"
ModuleRender::ModuleRender()
{
}
// Destructor
ModuleRender::~ModuleRender()
{
}
// Called before render is available
bool ModuleRender::Init()
{
//vbo_id = BaboonVbo();
model = new Model;
model->Load("./Models/BakerHouse/BakerHouse.gltf");
model->SetScale(float3::one * 100);
model->ChangeScale(model->GetScale());
return true;
}
update_status ModuleRender::PreUpdate()
{
return UPDATE_CONTINUE;
}
// Called every draw update
update_status ModuleRender::Update()
{
//RenderBaboon(vbo_id, App->GetProgram()->program);
model->Draw();
return UPDATE_CONTINUE;
}
update_status ModuleRender::PostUpdate()
{
return UPDATE_CONTINUE;
}
// Called before quitting
bool ModuleRender::CleanUp()
{
LOG("Destroying program");
glDeleteBuffers(1, &vbo_id);
model->CleanUp();
return true;
}
// BAOBOON: This function must be called one time at creation of vertex buffer
unsigned ModuleRender::BaboonVbo()
{
float vtx_data[] = { //Triangle 1
-1, -1, 0,
1, -1, 0,
-1, 1, 0,
//Triangle 2
1, -1, 0,
1, 1, 0,
-1, 1, 0,
//Coords 1
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
//Coords 2
1.0f, 0.0f,
1.0f, 1.0f,
0.0f, 1.0f
};
unsigned vbo;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo); // set vbo active
glBufferData(GL_ARRAY_BUFFER, sizeof(vtx_data), vtx_data, GL_DYNAMIC_DRAW);
return vbo;
}
void ModuleRender::RenderBaboon(unsigned vbo, unsigned program)
{
glUseProgram(program);
glUniformMatrix4fv(2, 1, GL_TRUE, &App->GetExercise()->GetModel()->GetModelMatrix()[0][0]);
glUniformMatrix4fv(3, 1, GL_TRUE, &App->GetCamera()->GetViewMatrix()[0][0]);
glUniformMatrix4fv(4, 1, GL_TRUE, &App->GetCamera()->GetProjectionMatrix()[0][0]);
// Bind buffer and vertex attributes
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glEnableVertexAttribArray(0);
// size = 3 float per vertex
// stride = 0 is equivalent to stride = sizeof(float)*3
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)(sizeof(float) * 18));
glActiveTexture(GL_TEXTURE5);
glBindTexture(GL_TEXTURE_2D, App->GetTexture()->texture_id);
// 1 triangle to draw = 3 vertices
glDrawArrays(GL_TRIANGLES, 0, 6);
}
void ModuleRender::ChangeModel(std::string fileName)
{
int last = fileName.find_last_of('\\');
std::string name = "";
int len = fileName.length();
for (int i = last + 1; i < fileName.length() -5; i++)
{
name += fileName[i];
}
model->CleanUp();
std::string path = "./Models/" + name + "/" + name + ".gltf";
const char* filePath = path.c_str();
model->Load(filePath);
}