#include "GameObject.h"

#include <GL/glew.h>
#include <iostream>

GameObject::GameObject() {
	//Create VBO
	glGenBuffers(1, &VBO);
	float vertices[] = {
		-0.5f, -0.5f, 0.0f,
		0.5f, -0.5f, 0.0f,
		0.0f,  0.5f, 0.0f
	};
	glBindBuffer(GL_ARRAY_BUFFER,VBO);
	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices),vertices, GL_STATIC_DRAW);
	//Create VAO
	glGenBuffers(1, &VAO);
	glBindVertexArray(VAO);
	//Set attriPointer and enable
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void *) 0);
	glEnableVertexAttribArray(0);

	//Cleanup
	glBindBuffer(GL_ARRAY_BUFFER,0);
	glBindVertexArray(0);
}

GameObject::~GameObject() {
	std::cout << "Deleting GameObject" << std::endl;
	glDeleteBuffers(1,&VBO);
	glDeleteBuffers(1,&VAO);
}

void GameObject::draw() {
	glBindVertexArray(this->VAO);
	glDrawArrays(GL_TRIANGLES, 0, 3);
}
