<commit_before>#include "..\include\Triangle.h"

using namespace pv;
using namespace pv::Primitive;

Triangle::Triangle(float size, float x, float y, Window &window):
_win(window)
{
	_size = size;
	_x = x;
	_y = y;
	_offX = 0.0f;
	_offY = 0.0f;
	_vertices = {

	_x, _y, 1.0f, 1.0f, 1.0f,
	_x, _y + _size, 1.0f, 1.0f, 1.0f,
	_x + _size, _y + _size, 1.0f, 1.0f, 1.0f

	};

	_elements = {
		0, 1, 2
	};

	glGenBuffers(1, &_vbo);
	glBindBuffer(GL_ARRAY_BUFFER, _vbo);
	glBufferData(GL_ARRAY_BUFFER, _vertices.size()* sizeof(float), &_vertices.front(), GL_DYNAMIC_DRAW);

	glGenBuffers(1, &_ebo);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ebo);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, _elements.size() * sizeof(unsigned int), &_elements.front(), GL_STATIC_DRAW);

	_posAttrib = glGetAttribLocation(_win.getShader(), "position");
	glEnableVertexAttribArray(_posAttrib);
	glVertexAttribPointer(_posAttrib, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0);

	_colAttrib = glGetAttribLocation(_win.getShader(), "color");
	glEnableVertexAttribArray(_colAttrib);
	glVertexAttribPointer(_colAttrib, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (void*)(2 * sizeof(GLfloat)));

	_offsetUnif = glGetUniformLocation(_win.getShader(), "offset");
	assert(_offsetUnif >= 0);
	glUniform2f(_offsetUnif, 0.0f, 0.0f);

}

void Triangle::move(float x, float y)
{
	_offX += x;
	_offY += y;
}

void Triangle::setPosition(float x, float y)
{
	_offX = x - _x;
	_offY = y - _y;
}

void Triangle::setColor(float r, float g, float b)
{
	_r = r;
	_g = g;
	_b = b;
}


void Triangle::draw()
{
	glBindBuffer(GL_ARRAY_BUFFER, _vbo);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ebo);

	glEnableVertexAttribArray(_posAttrib);
	glVertexAttribPointer(_posAttrib, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0);

	glEnableVertexAttribArray(_colAttrib);
	glVertexAttribPointer(_colAttrib, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (void*)(2 * sizeof(GLfloat)));

	glUniform2f(_offsetUnif, _offX, _offY);
	glUniform3f(_colUnif, _r, _g, _b);
	glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0);
}



Triangle::~Triangle()
{
	glDeleteBuffers(1, &_ebo);
	glDeleteBuffers(1, &_vbo);

}<commit_msg>Update Triangle.cpp<commit_after>#include "..\include\Triangle.h"

using namespace pv;
using namespace pv::Primitive;

Triangle::Triangle(float size, float x, float y, Window &window):
_win(window)
{
	_size = size;
	_x = x;
	_y = y;
	_offX = 0.0f;
	_offY = 0.0f;
	_a = 1.0f;
	_r = 1.0f;
	_g = 1.0f;
	_b = 1.0f;
	_vertices = {

	_x, _y, 1.0f, 1.0f, 1.0f,
	_x, _y + _size, 1.0f, 1.0f, 1.0f,
	_x + _size, _y + _size, 1.0f, 1.0f, 1.0f

	};

	_elements = {
		0, 1, 2
	};

	glGenBuffers(1, &_vbo);
	glBindBuffer(GL_ARRAY_BUFFER, _vbo);
	glBufferData(GL_ARRAY_BUFFER, _vertices.size()* sizeof(float), &_vertices.front(), GL_DYNAMIC_DRAW);

	glGenBuffers(1, &_ebo);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ebo);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, _elements.size() * sizeof(unsigned int), &_elements.front(), GL_STATIC_DRAW);

	_posAttrib = glGetAttribLocation(_win.getShader("colorshader"), "position");
	glEnableVertexAttribArray(_posAttrib);
	glVertexAttribPointer(_posAttrib, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0);

	_colAttrib = glGetAttribLocation(_win.getShader("colorshader"), "color");
	glEnableVertexAttribArray(_colAttrib);
	glVertexAttribPointer(_colAttrib, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (void*)(2 * sizeof(GLfloat)));

	_alphaUnif = glGetUniformLocation(_win.getShader("colorshader"), "unifalpha");
	assert(_alphaUnif >= 0);
	glUniform1f(_alphaUnif, 1.0f);

	_offsetUnif = glGetUniformLocation(_win.getShader("colorshader"), "offset");
	assert(_offsetUnif >= 0);
	glUniform2f(_offsetUnif, 0.0f, 0.0f);

}

void Triangle::move(float x, float y)
{
	_offX += x;
	_offY += y;
}

void Triangle::setPosition(float x, float y)
{
	_offX = x - _x;
	_offY = y - _y;
}

void Triangle::setColor(float r, float g, float b)
{
	_r = r;
	_g = g;
	_b = b;
}

void Triangle::setAlpha(float a)
{
	_a = a;
}


void Triangle::draw()
{
	glBindBuffer(GL_ARRAY_BUFFER, _vbo);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _ebo);

	glEnableVertexAttribArray(_posAttrib);
	glVertexAttribPointer(_posAttrib, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), 0);

	glEnableVertexAttribArray(_colAttrib);
	glVertexAttribPointer(_colAttrib, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (void*)(2 * sizeof(GLfloat)));

	glUniform2f(_offsetUnif, _offX, _offY);
	glUniform3f(_colUnif, _r, _g, _b);
	glUniform1f(_alphaUnif, _a);
	glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0);
}



Triangle::~Triangle()
{
	glDeleteBuffers(1, &_ebo);
	glDeleteBuffers(1, &_vbo);

}
{'fraction_non_alphanumeric': 0.15423102023058516, 'fraction_numerical': 0.025016314988035675, 'mean_word_length': 5.771723122238586, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6933090', 'n_tokens_mistral': 2025, 'n_tokens_neox': 1968, 'n_words': 367}