# data[].attributes.headline
(성만규)지스타 참석 때문에 늦게 제출하시는 분들

# data[].attributes.subject
(성만규)지스타 참석 때문에 늦게 제출하시는 분들

# data[].attributes.body
1. 삼각형 두개 이어서 사각형 그리기 (버텍트 6)
2. GL_TRIANGLE_STRIP을 사용해서 버텍스 줄이기 (버텍스 4)
4. 큐브 그리기(glDrawElement 이용)

# data[].attributes.body
지스타 참석때문에 늦게 제출합니다.

# data[].attributes.body
#pragma once
#include "MyGlWindow.h"

ShaderProgram* shaderProgram;
GLuint vaoHandle;
GLuint vboPosition;
GLuint vboColor;
GLuint vbo;
GLuint ibo_cube_elements;

MyGlWindow::MyGlWindow(int w, int h)
{
m_width = w;
m_height = h;

setupBuffer();
}

void MyGlWindow::setupBuffer()
{
shaderProgram = new ShaderProgram();
shaderProgram->initFromFiles("simple.vert", "simple.frag");

const float vertex[] = {
0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f,
0.8f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.8f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,

0.8f, 0.8f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f,
0.8f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
0.0f, 0.8f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,

};

//VAO 생성
glCreateVertexArrays(1, &vaoHandle);
glBindVertexArray(vaoHandle);

glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex), vertex, GL_STATIC_DRAW);
glVertexAttribPointer(
0, //attr의 번호
4, //# of data for each vertex
GL_FLOAT, //데이터 타입
GL_FALSE, //normalize 되어 있는지
sizeof(float) * 7, //다음 데이터 까지의 거리
0
);
glEnableVertexAttribArray(0);

glVertexAttribPointer(
1, //attr의 번호
3, //# of data for each vertex
GL_FLOAT, //데이터 타입
GL_FALSE, //normalize 되어 있는지
sizeof(float) * 7,
(void*)(sizeof(float) * 4)
);
glEnableVertexAttribArray(1);

glBindVertexArray(0);

}

void MyGlWindow::draw()
{
glClearColor(0.5f, 0.5f, 0.5f, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glViewport(0, 0, m_width, m_height);

//그려줌
shaderProgram->use();

glBindVertexArray(vaoHandle);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

shaderProgram->disable();
}

void MyGlWindow::setSize(int width, int height)
{
m_width  = width;
m_height = height;
}

# data[].attributes.body
#pragma once
#include "MyGlWindow.h"

ShaderProgram* shaderProgram;
GLuint vaoHandle;
GLuint vboPosition;
GLuint vboColor;
GLuint vbo;
GLuint ibo_cube_elements;

MyGlWindow::MyGlWindow(int w, int h)
{
m_width = w;
m_height = h;

setupBuffer();
}

void MyGlWindow::setupBuffer()
{
shaderProgram = new ShaderProgram();
shaderProgram->initFromFiles("simple.vert", "simple.frag");

const float vertex[] = {
-0.8f, 0.8f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
0.8f, 0.8f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f,
-0.8f, -0.8f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,
0.8f, -0.8f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f

};

//VAO 생성
glCreateVertexArrays(1, &vaoHandle);
glBindVertexArray(vaoHandle);

glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertex), vertex, GL_STATIC_DRAW);
glVertexAttribPointer(
0, //attr의 번호
4, //# of data for each vertex
GL_FLOAT, //데이터 타입
GL_FALSE, //normalize 되어 있는지
sizeof(float) * 7, //다음 데이터 까지의 거리
0
);
glEnableVertexAttribArray(0);

glVertexAttribPointer(
1, //attr의 번호
3, //# of data for each vertex
GL_FLOAT, //데이터 타입
GL_FALSE, //normalize 되어 있는지
sizeof(float) * 7,
(void*)(sizeof(float) * 4)
);
glEnableVertexAttribArray(1);

glBindVertexArray(0);

}

void MyGlWindow::draw()
{
glClearColor(0.2f, 0.2f, 0.2f, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glViewport(0, 0, m_width, m_height);

//그려줌
shaderProgram->use(); //vertex shader 호출

glBindVertexArray(vaoHandle);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

shaderProgram->disable();
}

void MyGlWindow::setSize(int width, int height)
{
m_width  = width;
m_height = height;
}

# data[].attributes.body
#pragma once
#include "MyGlWindow.h"

ShaderProgram* shaderProgram;
GLuint vaoHandle;
GLuint vboPosition;
GLuint vboColor;
GLuint vbo;
GLuint ibo_cube_elements;

MyGlWindow::MyGlWindow(int w, int h)
{
m_width = w;
m_height = h;

setupBuffer();
}

void MyGlWindow::setupBuffer()
{
shaderProgram = new ShaderProgram();
shaderProgram->initFromFiles("simple.vert", "simple.frag");

GLfloat cube_vertices[] = {
// front
-1.0, -1.0, 1.0,
1.0, -1.0, 1.0,
1.0, 1.0, 1.0,
-1.0, 1.0, 1.0,
// back
-1.0, -1.0, -1.0,
1.0, -1.0, -1.0,
1.0, 1.0, -1.0,
-1.0, 1.0, -1.0,
};

GLfloat cube_colors[] = {
// front colors
1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0,
1.0, 1.0, 1.0,
// back colors
1.0, 0.0, 0.0,
0.0, 1.0, 0.0,
0.0, 0.0, 1.0,
1.0, 1.0, 1.0,
};

GLushort cube_elements[] = {
0, 1, 2, 2, 3, 0, 1, 5, 6,
6, 2, 1, 7, 6, 5, 5, 4, 7,
4, 0, 3, 3, 7, 4, 4, 5, 1,
1, 0, 4, 3, 2, 6, 6, 7, 3,
};

//VAO 생성
glCreateVertexArrays(1, &vaoHandle);
glBindVertexArray(vaoHandle);

glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(cube_vertices), cube_vertices, GL_STATIC_DRAW);
glVertexAttribPointer(
0, //attr의 번호
3, //# of data for each vertex
GL_FLOAT, //데이터 타입
GL_FALSE, //normalize 되어 있는지
0, //다음 데이터 까지의 거리
0 //시작 위치
);
glEnableVertexAttribArray(0);

glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(cube_colors), cube_colors, GL_STATIC_DRAW);
glVertexAttribPointer(
1, //attr의 번호
3, //# of data for each vertex
GL_FLOAT, //데이터 타입
GL_FALSE, //normalize 되어 있는지
0,
0
);
glEnableVertexAttribArray(1);

glGenBuffers(1, &ibo_cube_elements);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo_cube_elements);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(cube_elements), cube_elements, GL_STATIC_DRAW);

glBindVertexArray(0);
}

void MyGlWindow::draw()
{
glClearColor(0.5f, 0.5f, 0.5f, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glViewport(0, 0, m_width, m_height);

shaderProgram->use();

glBindVertexArray(vaoHandle);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 8);

int size;
glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);
glDrawElements(GL_TRIANGLES, size / sizeof(GLushort), GL_UNSIGNED_SHORT, 0);

shaderProgram->disable();
}

void MyGlWindow::setSize(int width, int height)
{
m_width  = width;
m_height = height;
}