59 lines
1.2 KiB
C++
59 lines
1.2 KiB
C++
|
#include <glad/glad.h>
|
||
|
#include <iostream>
|
||
|
#include "Graphics.h"
|
||
|
|
||
|
Graphics::Graphics() : window(nullptr), VAO(0), VBO(0) {}
|
||
|
|
||
|
Graphics::~Graphics()
|
||
|
{
|
||
|
Shutdown();
|
||
|
}
|
||
|
|
||
|
void Graphics::Initialize(GLFWwindow* window)
|
||
|
{
|
||
|
this->window = window;
|
||
|
|
||
|
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||
|
std::cerr << "Failed to initialize GLAD" << std::endl;
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
SetupBuffers();
|
||
|
}
|
||
|
|
||
|
void Graphics::SetupBuffers()
|
||
|
{
|
||
|
float vertices[] = {
|
||
|
0.0f, 0.5f, 0.0f,
|
||
|
-0.5f, -0.5f, 0.0f,
|
||
|
0.5f, -0.5f, 0.0f
|
||
|
};
|
||
|
|
||
|
glGenVertexArrays(1, &VAO);
|
||
|
glGenBuffers(1, &VBO);
|
||
|
|
||
|
glBindVertexArray(VAO);
|
||
|
|
||
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
|
||
|
|
||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
||
|
glEnableVertexAttribArray(0);
|
||
|
|
||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||
|
glBindVertexArray(0);
|
||
|
}
|
||
|
|
||
|
void Graphics::Render() {
|
||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||
|
|
||
|
glBindVertexArray(VAO);
|
||
|
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||
|
}
|
||
|
|
||
|
void Graphics::Shutdown()
|
||
|
{
|
||
|
glDeleteVertexArrays(1, &VAO);
|
||
|
glDeleteBuffers(1, &VBO);
|
||
|
}
|