#ifndef GLAD #define GLAD #include #endif #include "Rectangle.hpp" #include "shader.hpp" Rectangle::Rectangle(){} Rectangle::Rectangle(float _x,float _y,float _width,float _height){ x=_x; y=_y; width=_width; height=_height; unsigned int vertexShader = glCreateShader(GL_VERTEX_SHADER); shader = Shader("shaders/2dshader.vs", "shaders/2dshader.fs"); float vertices[] = { x+width,y, x+width,y+height, x,y+height, x,y }; unsigned int indices[] = { 0, 1, 2,3 }; glGenVertexArrays(1, &VAO); glGenBuffers(1, &VBO); glBindVertexArray(VAO); glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)0); glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); } void Rectangle::Draw(Vector3f color){ shader.activate(); shader.setUniformVec3("Color",color); glBindVertexArray(VAO); glDrawArrays(GL_LINE_LOOP, 0, 4); } bool Rectangle::IsIn(float _x,float _y){ return( _xx && _y>y); }