代码拉取完成,页面将自动刷新
//
// Created by edward on 23-3-25.
//
#include "Mesh.h"
Mesh::Mesh(std::vector<Vertex> vertices, std::vector<unsigned int> indices, std::vector<Texture> textures)
: vertices_(std::move(vertices))
, indices_(std::move(indices))
, textures_(std::move(textures))
{
setup();
}
void Mesh::setup() {
glGenVertexArrays(1, &VAO_);
glGenBuffers(1, &VBO_);
glGenBuffers(1, &EBO_);
glBindVertexArray(VAO_);
glBindBuffer(GL_ARRAY_BUFFER, VBO_);
glBufferData(GL_ARRAY_BUFFER, vertices_.size() * sizeof(Vertex), vertices_.data(), GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *) offsetof(Vertex, position));
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *) offsetof(Vertex, color));
glEnableVertexAttribArray(1);
glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *) offsetof(Vertex, normal));
glEnableVertexAttribArray(2);
glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void *) offsetof(Vertex, texCoords));
glEnableVertexAttribArray(3);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO_);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices_.size() * sizeof(unsigned int), indices_.data(), GL_STATIC_DRAW);/// copy data to EBO
/// set wireframe mode
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
/// unbind VBO -> is allowed, but not necessary
glBindBuffer(GL_ARRAY_BUFFER, 0);
/// unbind VAO
glBindVertexArray(0);
}
void Mesh::draw(Shader *shader) {
for (unsigned i = 0; i < textures_.size(); ++i) {
textures_[i].use(shader, i);
}
glBindVertexArray(VAO_);
glDrawElements(GL_TRIANGLES, indices_.size(), GL_UNSIGNED_INT, 0);
}
/*
glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO);
*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。