Created
July 21, 2024 22:45
-
-
Save cchulo/f4110039beeba3779c7aecd9113ef782 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool OpenGL_Mesh::Initialize() | |
{ | |
_vao = 0; | |
_vbo = 0; | |
_nvbo = 0; | |
_uvbo = 0; | |
_ebo = 0; | |
glGenVertexArrays(1, &_vao); | |
glGenBuffers(1, &_vbo); | |
glGenBuffers(1, &_nvbo); | |
glGenBuffers(1, &_uvbo); | |
if (!_indices.empty()) | |
{ | |
glGenBuffers(1, &_ebo); | |
} | |
glBindVertexArray(_vao); | |
// vbo - vertices | |
glBindBuffer(GL_ARRAY_BUFFER, _vbo); | |
glBufferData( | |
GL_ARRAY_BUFFER, | |
static_cast<GLsizeiptr>(_vertices.size() * sizeof(float)), | |
&_vertices[0], | |
GL_STATIC_DRAW); | |
glVertexAttribPointer( | |
0, | |
3, | |
GL_FLOAT, | |
GL_FALSE, | |
3 * sizeof(GLfloat), | |
static_cast<void *>(nullptr)); | |
glEnableVertexAttribArray(0); | |
// nvbo - normals | |
glBindBuffer(GL_ARRAY_BUFFER, _nvbo); | |
glBufferData(GL_ARRAY_BUFFER, | |
static_cast<GLsizeiptr>(_normals.size() * sizeof(float)), | |
&_normals[0], | |
GL_STATIC_DRAW); | |
glVertexAttribPointer( | |
1, | |
3, | |
GL_FLOAT, | |
GL_FALSE, | |
3 * sizeof(GLfloat), | |
static_cast<void *>(nullptr)); | |
glEnableVertexAttribArray(1); | |
// uvbo - texture coordinates | |
glBindBuffer(GL_ARRAY_BUFFER, _uvbo); | |
glBufferData(GL_ARRAY_BUFFER, | |
static_cast<GLsizeiptr>(_uvs.size() * sizeof(float)), | |
&_uvs[0], | |
GL_STATIC_DRAW); | |
glVertexAttribPointer( | |
2, | |
2, | |
GL_FLOAT, | |
GL_FALSE, | |
2 * sizeof(GLfloat), | |
static_cast<void *>(nullptr)); | |
glEnableVertexAttribArray(2); | |
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ebo); | |
glBufferData(GL_ELEMENT_ARRAY_BUFFER, | |
static_cast<GLsizeiptr>(_indices.size() * sizeof(int)), | |
&_indices[0], | |
GL_STATIC_DRAW); | |
glBindBuffer(GL_ARRAY_BUFFER, 0); | |
glBindVertexArray(0); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment