Triangle Geometry

사용자 삽입 이미지
void Triangle::init()
{
 glm::vec3 t1 = p + v1;
 glm::vec3 t2 = p + v2;
 glm::vec3 t3 = p + v3;

 // face 1
 vbo.addData(&t1[0], sizeof(glm::vec3)); // vertex position
 vbo.addData(&color[0], sizeof(glm::vec3)); // vertex color
 vbo.addData(&t2[0], sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3));
 vbo.addData(&t3[0], sizeof(glm::vec3));
 vbo.addData(&color[0], sizeof(glm::vec3));

 numVertices = 3;

 // VAO & VBOs
 vbo.createVBO();
 vbo.bindVBO();
 vbo.uploadDataToGPU(GL_STATIC_DRAW);

 glGenVertexArrays(1, &vao);
 glBindVertexArray(vao);

 int iDataStride = 2 * sizeof(glm::vec3); // vertex & color only
 int iDataOffset = 0;
 glEnableVertexAttribArray(0);
 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, iDataStride, (void*)iDataOffset);
 iDataOffset += sizeof(glm::vec3);
 glEnableVertexAttribArray(1);
 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, iDataStride, (void*)iDataOffset);

 isLoaded = true;
}

Leave a Reply

Your email address will not be published. Required fields are marked *