HW0 – GLM 라이브러리를 사용하여 정점과 색버퍼를 지정한 color triangle 그림을 그려온다~
/// colortriangle.cpp에서 아래와 같이 추가 수정해본다.
#include <glm/glm.hpp>
#include <vector>
std::vector<glm::vec4> vertexColors;
std::vector<glm::vec4> vertexPositions;
void SetData()
{
vertexColors.push_back(glm::vec4(1.0f, 0.0f, 0.0f, 1.0f)); // red
vertexColors.push_back(glm::vec4(0.0f, 1.0f, 0.0f, 1.0f)); // green
vertexColors.push_back(glm::vec4(0.0f, 0.0f, 1.0f, 1.0f)); // blue
vertexPositions.push_back(glm::vec4(-0.75f, -0.75f, 0.0f, 1.0f));
vertexPositions.push_back(glm::vec4(0.75f, -0.75f, 0.0f, 1.0f));
vertexPositions.push_back(glm::vec4(0.75f, 0.75f, 0.0f, 1.0f));
// VAO
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
// VBO
glGenBuffers(2, &vbo[0]);
// vertex position
glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
//glBufferData(GL_ARRAY_BUFFER, 12*sizeof(GLfloat), vertexPosition, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, 3*sizeof(glm::vec4), &vertexPositions[0], GL_STATIC_DRAW);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);
// vertex color
glBindBuffer(GL_ARRAY_BUFFER, vbo[1]);
//glBufferData(GL_ARRAY_BUFFER, 12*sizeof(GLfloat), vertexColor, GL_STATIC_DRAW);
glBufferData(GL_ARRAY_BUFFER, 3*sizeof(glm::vec4), &vertexColors[0], GL_STATIC_DRAW);
glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(1);
glBindVertexArray(0);
}