2018-07-14 21:42:23 +00:00
|
|
|
//
|
|
|
|
// Rectangle.cpp
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 11/07/2018.
|
|
|
|
// Copyright © 2018 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Rectangle.hpp"
|
|
|
|
|
2018-11-11 20:11:32 +00:00
|
|
|
using namespace Outputs::Display::OpenGL;
|
2018-07-14 21:42:23 +00:00
|
|
|
|
|
|
|
Rectangle::Rectangle(float x, float y, float width, float height):
|
2018-11-24 03:32:32 +00:00
|
|
|
pixel_shader_(
|
2018-07-14 21:42:23 +00:00
|
|
|
"#version 150\n"
|
|
|
|
|
|
|
|
"in vec2 position;"
|
|
|
|
|
|
|
|
"void main(void)"
|
|
|
|
"{"
|
|
|
|
"gl_Position = vec4(position, 0.0, 1.0);"
|
|
|
|
"}",
|
|
|
|
|
|
|
|
"#version 150\n"
|
|
|
|
|
|
|
|
"uniform vec4 colour;"
|
|
|
|
"out vec4 fragColour;"
|
|
|
|
|
|
|
|
"void main(void)"
|
|
|
|
"{"
|
|
|
|
"fragColour = colour;"
|
|
|
|
"}"
|
|
|
|
){
|
|
|
|
pixel_shader_.bind();
|
|
|
|
|
2019-02-18 15:29:40 +00:00
|
|
|
test_gl(glGenVertexArrays, 1, &drawing_vertex_array_);
|
|
|
|
test_gl(glGenBuffers, 1, &drawing_array_buffer_);
|
2018-07-14 21:42:23 +00:00
|
|
|
|
2019-02-18 15:29:40 +00:00
|
|
|
test_gl(glBindVertexArray, drawing_vertex_array_);
|
|
|
|
test_gl(glBindBuffer, GL_ARRAY_BUFFER, drawing_array_buffer_);
|
2018-07-14 21:42:23 +00:00
|
|
|
|
|
|
|
GLint position_attribute = pixel_shader_.get_attrib_location("position");
|
2019-02-18 15:29:40 +00:00
|
|
|
test_gl(glEnableVertexAttribArray, GLuint(position_attribute));
|
2018-07-14 21:42:23 +00:00
|
|
|
|
2019-02-18 15:29:40 +00:00
|
|
|
test_gl(glVertexAttribPointer,
|
2018-07-14 21:42:23 +00:00
|
|
|
(GLuint)position_attribute,
|
|
|
|
2,
|
|
|
|
GL_FLOAT,
|
|
|
|
GL_FALSE,
|
|
|
|
2 * sizeof(GLfloat),
|
|
|
|
(void *)0);
|
|
|
|
|
|
|
|
colour_uniform_ = pixel_shader_.get_uniform_location("colour");
|
|
|
|
|
|
|
|
float buffer[4*2];
|
|
|
|
|
|
|
|
// Store positions.
|
|
|
|
buffer[0] = x; buffer[1] = y;
|
|
|
|
buffer[2] = x; buffer[3] = y + height;
|
|
|
|
buffer[4] = x + width; buffer[5] = y;
|
|
|
|
buffer[6] = x + width; buffer[7] = y + height;
|
|
|
|
|
|
|
|
// Upload buffer.
|
2019-02-18 15:29:40 +00:00
|
|
|
test_gl(glBindBuffer, GL_ARRAY_BUFFER, drawing_array_buffer_);
|
|
|
|
test_gl(glBufferData, GL_ARRAY_BUFFER, sizeof(buffer), buffer, GL_STATIC_DRAW);
|
2018-07-14 21:42:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Rectangle::draw(float red, float green, float blue) {
|
|
|
|
pixel_shader_.bind();
|
2019-02-18 15:29:40 +00:00
|
|
|
test_gl(glUniform4f, colour_uniform_, red, green, blue, 1.0);
|
2018-07-14 21:42:23 +00:00
|
|
|
|
2019-02-18 15:29:40 +00:00
|
|
|
test_gl(glBindVertexArray, drawing_vertex_array_);
|
|
|
|
test_gl(glDrawArrays, GL_TRIANGLE_STRIP, 0, 4);
|
2018-07-14 21:42:23 +00:00
|
|
|
}
|