1. VBO.h
#ifndef VBO_CLASS_H
#define VBO_CLASS_H
#include<glad/glad.h>
class VBO
{
public:
// Reference ID of the Vertex Buffer Object
GLuint ID;
// Constructor that generates a Vertex Buffer Object and links it to vertices
VBO(GLfloat* vertices, GLsizeiptr size);
// Binds the VBO
void Bind();
// Unbinds the VBO
void Unbind();
// Deletes the VBO
void Delete();
};
#endif
2. VBO.cpp
#include"VBO.h"
// Constructor that generates a Vertex Buffer Object and links it to vertices
VBO::VBO(GLfloat* vertices, GLsizeiptr size)
{
glGenBuffers(1, &ID);
glBindBuffer(GL_ARRAY_BUFFER, ID);
glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW);
}
// Binds the VBO
void VBO::Bind()
{
glBindBuffer(GL_ARRAY_BUFFER, ID);
}
// Unbinds the VBO
void VBO::Unbind()
{
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
// Deletes the VBO
void VBO::Delete()
{
glDeleteBuffers(1, &ID);
}
3. VAO.h
#ifndef VAO_CLASS_H
#define VAO_CLASS_H
#include<glad/glad.h>
#include"VBO.h"
class VAO
{
public:
// ID reference for the Vertex Array Object
GLuint ID;
// Constructor that generates a VAO ID
VAO();
// Links a VBO to the VAO using a certain layout
void LinkVBO(VBO& VBO, GLuint layout);
// Binds the VAO
void Bind();
// Unbinds the VAO
void Unbind();
// Deletes the VAO
void Delete();
};
#endif
4. VAO.cpp
#include"VAO.h"
// Constructor that generates a VAO ID
VAO::VAO()
{
glGenVertexArrays(1, &ID);
}
// Links a VBO to the VAO using a certain layout
void VAO::LinkVBO(VBO& VBO, GLuint layout)
{
VBO.Bind();
glVertexAttribPointer(layout, 3, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnableVertexAttribArray(layout);
VBO.Unbind();
}
// Binds the VAO
void VAO::Bind()
{
glBindVertexArray(ID);
}
// Unbinds the VAO
void VAO::Unbind()
{
glBindVertexArray(0);
}
// Deletes the VAO
void VAO::Delete()
{
glDeleteVertexArrays(1, &ID);
}
'OpenGL' 카테고리의 다른 글
[OpenGL] Types of Light (0) | 2022.11.04 |
---|---|
[OpenGL] 2. Shader (셰이더) (0) | 2022.10.07 |
[OpenGL] 1. 윈도우 창 생성 및 배경색 조절 (0) | 2022.10.07 |
[OpenGL] 설치 (0) | 2022.10.07 |