fix some shapes generation and draw a grid of shapes for an overview

This commit is contained in:
Omar Mohamed Ali Mudhir
2017-01-16 00:22:44 +00:00
parent de17029e0d
commit baaaf213cc
4 changed files with 89 additions and 45 deletions

View File

@@ -29,6 +29,14 @@ void App::init()
"void main(){"
" frag = texture(tex, uv, 0.0);"
"}";
static const char* shader_uv_f =
"#version 150\n"
"uniform sampler2D tex;"
"in vec2 uv;"
"out vec4 frag;"
"void main(){"
" frag = vec4(uv,0,1);"
"}";
static const char* shader_color_v =
"#version 150\n"
"uniform mat4 mvp;"
@@ -45,9 +53,12 @@ void App::init()
"}";
shader.create(shader_v, shader_f);
shader_color.create(shader_color_v, shader_color_f);
plane.create<15>(.5f, .5f);
longPlane.create<1>(.3, .05f);
circle.create<6>(.5f, .25f);
shader_uv.create(shader_v, shader_uv_f);
plane.create<5>(50, 50);
longPlane.create<1>(50, 25);
circle.create<6>(25, 12);
circle1.create<4>(25, 12);
circle2.create<15>(25, 12);
if (!tex.load("data/image.png"))
printf("error loading image\n");
@@ -79,24 +90,55 @@ void App::update(float dt)
theta += M_PI * 0.5f * dt;
float red = fabsf(sinf(theta));
glm::mat4 proj = glm::perspective(glm::radians(85.f), 1.f, .1f, 100.f);
glm::mat4 model = glm::translate(glm::vec3(0, 0, 0));
glm::mat4 view = glm::lookAt(glm::vec3(sinf(theta), 0, 1), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
auto mvp = proj * view * model;
// glm::mat4 proj = glm::perspective(glm::radians(85.f), 1.f, .1f, 100.f);
// glm::mat4 model = glm::translate(glm::vec3(0, 0, 0));
// glm::mat4 view = glm::lookAt(glm::vec3(sinf(theta), 0, 1), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0));
float ar = width / height;
glm::mat4 proj = glm::ortho<float>(0, width, height, 0, -1, 1);
Shape* shapes[] = { &circle, &circle1, &circle2, &plane, &longPlane };
//glClearColor(red, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
shader.use();
shader.u_mat4("mvp", glm::mat4());
shader.u_int("tex", 0);
glActiveTexture(GL_TEXTURE0);
tex.bind();
circle.draw_fill();
tex.unbind();
shader_color.use();
shader_color.u_mat4("mvp", glm::mat4());
shader_color.u_vec4("col", {1, 1, 1, 1});
circle.draw_stroke();
auto s = glm::scale(glm::vec3(2));
for (int i = 0; i < 5; i++)
{
shader.use();
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glActiveTexture(GL_TEXTURE0);
tex.bind();
shader.u_int("tex", 0);
shader.u_mat4("mvp", proj * glm::translate(glm::vec3{75 + 120 * 1, 75 + 120 * i, 0.f}) * s);
shapes[i]->draw_fill();
tex.unbind();
shader_color.use();
shader.u_mat4("mvp", proj * glm::translate(glm::vec3{75 + 120 * 2, 75 + 120 * i, 0.f}) * s);
shader_color.u_vec4("col", {1, 1, 1, 1});
shapes[i]->draw_stroke();
shader.u_mat4("mvp", proj * glm::translate(glm::vec3{75 + 120 * 0, 75 + 120 * i, 0.f}) * s);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
shapes[i]->draw_fill();
shader_uv.use();
shader_uv.u_mat4("mvp", proj * glm::translate(glm::vec3{75 + 120 * 3, 75 + 120 * i, 0.f}) * s);
shader_uv.u_int("tex", 0);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
shapes[i]->draw_fill();
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
shader_uv.u_mat4("mvp", proj * glm::translate(glm::vec3{75 + 120 * 4, 75 + 120 * i, 0.f}) * s);
shapes[i]->draw_fill();
tex.unbind();
}
// shader.use();
// shader.u_mat4("mvp", proj * glm::translate(glm::vec3{width/2, height/2, 0.f}) * glm::scale(glm::vec3(10)));
// shader.u_int("tex", 0);
// glActiveTexture(GL_TEXTURE0);
// tex.bind();
// circle.draw_fill();
// tex.unbind();
}