4#include <glm/gtc/constants.hpp>
5#include <glm/gtc/quaternion.hpp>
6#include <glm/gtc/matrix_transform.hpp>
7#include <glm/ext/matrix_relational.hpp>
8#include <glm/ext/vector_relational.hpp>
9#include <glm/ext/scalar_relational.hpp>
13Model::Model(std::string n)
19void Model::SetupMeshOnGPU()
21 glGenVertexArrays(1, &vao);
22 glBindVertexArray(vao);
23 glGenBuffers(1, &vbo);
24 glBindBuffer(GL_ARRAY_BUFFER, vbo);
26 glGenBuffers(1, &ebo);
27 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
29 glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE,
sizeof(
Vert), (
void *)offsetof(
Vert, position));
30 glEnableVertexAttribArray(0);
31 glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE,
sizeof(
Vert), (
void *)offsetof(
Vert, normal));
32 glEnableVertexAttribArray(1);
33 glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE,
sizeof(
Vert), (
void *)offsetof(
Vert, texCoord));
34 glEnableVertexAttribArray(2);
35 glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE,
sizeof(
Vert), (
void *)offsetof(
Vert, extras1));
36 glEnableVertexAttribArray(3);
37 std::cout <<
"Setup Model " << name <<
" on GPU.\n";
40void Model::UploadToGPU()
44 std::cout <<
"In Model " << name <<
" mesh not available.\n";
50 std::cout <<
"In Model " << name <<
" mesh not valid.\n";
54 glBindVertexArray(vao);
55 glBindBuffer(GL_ARRAY_BUFFER, vbo);
56 glBufferData(GL_ARRAY_BUFFER,
sizeof(
Vert) * mesh->vertexCount, mesh->vert, GL_DYNAMIC_DRAW);
57 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo);
58 glBufferData(GL_ELEMENT_ARRAY_BUFFER,
sizeof(
int) * mesh->indexCount, mesh->indices, GL_DYNAMIC_DRAW);
59 glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE,
sizeof(
Vert), (
void *)offsetof(
Vert, position));
60 glEnableVertexAttribArray(0);
61 glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE,
sizeof(
Vert), (
void *)offsetof(
Vert, normal));
62 glEnableVertexAttribArray(1);
63 glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE,
sizeof(
Vert), (
void *)offsetof(
Vert, texCoord));
64 glEnableVertexAttribArray(2);
65 glVertexAttribPointer(3, 4, GL_FLOAT, GL_FALSE,
sizeof(
Vert), (
void *)offsetof(
Vert, extras1));
66 glEnableVertexAttribArray(3);
71 modelMatrix = glm::translate(glm::mat4(1.0f), position);
72 modelMatrix = glm::rotate(modelMatrix, rotation.x, glm::vec3(1, 0, 0));
73 modelMatrix = glm::rotate(modelMatrix, rotation.y, glm::vec3(0, 1, 0));
74 modelMatrix = glm::rotate(modelMatrix, rotation.z, glm::vec3(0, 0, 1));
75 modelMatrix = glm::scale(modelMatrix, scale);
85 glBindVertexArray(vao);
86 glDrawElements(GL_TRIANGLES, mesh->indexCount, GL_UNSIGNED_INT, 0);