<commit_before>#include "render_utility.h"
#include "Snapshoot.h"
#include "BoundingBox.h"
#include "Image.h"
#include "ImageSprite.h"

#include <gl/glew.h>

namespace ee
{

Sprite* draw_all_to_one_spr(const std::vector<Sprite*>& sprites, Sprite* except)
{
	std::vector<Sprite*> _sprites;
	for (int i = 0, n = sprites.size(); i < n; ++i) {
		if (sprites[i] != except) {
			_sprites.push_back(sprites[i]);
		}
	}
	return draw_all_to_one_spr(_sprites);
}

float cal_texture_size(float w, float h)
{
	const float MAX_SIZE = 4096;

	float max = std::max(w, h);
	if (max <= MAX_SIZE) {
		return 1;
	} else {
		return MAX_SIZE / max;
	}
}

Sprite* draw_all_to_one_spr(const std::vector<Sprite*>& sprites)
{
	if (sprites.empty()) {
		return NULL;
	}

	sm::rect r;
	for (int i = 0, n = sprites.size(); i < n; ++i) {
		std::vector<sm::vec2> bound;
		sprites[i]->GetBounding()->GetBoundPos(bound);
		for (int j = 0, m = bound.size(); j < m; ++j) {
			r.Combine(bound[j]);
		}
	}

	sm::vec2 sz = r.Size();
	float scale = cal_texture_size(sz.x, sz.y);
	sz *= scale;
	sm::vec2 center = r.Center() * scale;

	Snapshoot ss(static_cast<int>(sz.x), static_cast<int>(sz.y));
	for (int i = 0, n = sprites.size(); i < n; ++i) {
		ee::Sprite* spr = sprites[i];
		ss.DrawSprite(spr, false, static_cast<int>(sz.x), static_cast<int>(sz.y), center.x, center.y, scale);
	}

	Image* img = new Image(ss.GetFBO());
	ImageSymbol* symbol = new ImageSymbol(img, "ss");
	ImageSprite* spr = new ImageSprite(symbol);

	spr->SetMirror(false, true);
	spr->SetTransform(sm::vec2(center.x, center.y), 0);
	spr->SetScale(sm::vec2(1.0f / scale, 1.0f / scale));

	return spr;
}

void gl_debug()
{
	GLenum err;
	while ( ( err = glGetError() ) != GL_NO_ERROR) {
		int zz = err;
		std::cerr << err;<commit_msg>[FIXED] draw to sprite<commit_after>#include "render_utility.h"
#include "Snapshoot.h"
#include "BoundingBox.h"
#include "Image.h"
#include "ImageSprite.h"

#include <gl/glew.h>

namespace ee
{

Sprite* draw_all_to_one_spr(const std::vector<Sprite*>& sprites, Sprite* except)
{
	std::vector<Sprite*> _sprites;
	for (int i = 0, n = sprites.size(); i < n; ++i) {
		if (sprites[i] != except) {
			_sprites.push_back(sprites[i]);
		}
	}
	return draw_all_to_one_spr(_sprites);
}

float cal_texture_size(float w, float h)
{
	const float MAX_SIZE = 4096;

	float max = std::max(w, h);
	if (max <= MAX_SIZE) {
		return 1;
	} else {
		return MAX_SIZE / max;
	}
}

Sprite* draw_all_to_one_spr(const std::vector<Sprite*>& sprites)
{
	if (sprites.empty()) {
		return NULL;
	}

	sm::rect r;
	for (int i = 0, n = sprites.size(); i < n; ++i) {
		std::vector<sm::vec2> bound;
		sprites[i]->GetBounding()->GetBoundPos(bound);
		for (int j = 0, m = bound.size(); j < m; ++j) {
			r.Combine(bound[j]);
		}
	}

	sm::vec2 sz = r.Size();
	float scale = cal_texture_size(sz.x, sz.y);
	sz *= scale;
	sm::vec2 center = r.Center() * scale;

	Snapshoot ss(static_cast<int>(sz.x), static_cast<int>(sz.y));
	for (int i = 0, n = sprites.size(); i < n; ++i) {
		ee::Sprite* spr = sprites[i];
		ss.DrawSprite(spr, false, static_cast<int>(sz.x + 0.5f), static_cast<int>(sz.y + 0.5f), center.x, center.y, scale);
	}

	Image* img = new Image(ss.GetFBO());
	ImageSymbol* symbol = new ImageSymbol(img, "ss");
	ImageSprite* spr = new ImageSprite(symbol);

	spr->SetMirror(false, true);
	spr->SetTransform(r.Center(), 0);
	spr->SetScale(sm::vec2(1.0f / scale, 1.0f / scale));

	return spr;
}

void gl_debug()
{
	GLenum err;
	while ( ( err = glGetError() ) != GL_NO_ERROR) {
		int zz = err;
		std::cerr << err;
{'fraction_non_alphanumeric': 0.19292786421499292, 'fraction_numerical': 0.011598302687411598, 'mean_word_length': 4.215339233038348, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 31, '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': '4218712', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1501, 'n_words': 329}