<commit_before>
#include <base/cmd_line.h>
#include <base/unit_test.h>
#include <platform/platform.h>
#include <gl/framebuffer.h>
#include <gl/texture.h>
#include <gl/check.h>
#include <gl/context.h>
#include <gl/png_image.h>

namespace
{

int safemain( int argc, char *argv[] )
{
	base::cmd_line options( argv[0] );

	base::unit_test test( "info" );
	test.setup( options );

	options.add_help();
	options.parse( argc, argv );

	if ( options["help"] )
	{
		std::cerr << options << std::endl;
		return -1;
	}

	// Create a window
	auto sys = platform::platform::common().create();
	auto win = sys->new_window();

	win->set_title( "Triangle" );
	win->acquire();

	// OpenGL initialization
	gl::context ogl;
//	ogl.enable( gl::capability::DEPTH_TEST );
//	ogl.depth_func( gl::depth_test::LESS );

	// Create the geometry for the triangle
	auto vbo_points = ogl.new_array_buffer<float>( {
		0.0F,  0.5F,   0.0F,
		0.5F, -0.5F,   0.0F,
		-0.5F, -0.5F,   0.0F
	} );

	auto vbo_colors = ogl.new_array_buffer<float>( {
		1.0F, 0.0F,  0.0F,
		0.0F, 1.0F,  0.0F,
		0.0F, 0.0F,  1.0F
	} );

	auto vao = ogl.new_vertex_array();
	{
		auto tmp = vao->bind();	
		tmp.attrib_pointer( 0, vbo_points, 3 );
		tmp.attrib_pointer( 1, vbo_colors, 3 );
	}

	// The shaders and program for the triangle
	auto vshader = ogl.new_shader( gl::shader::type::VERTEX, R"SHADER(
		#version 410

		layout(location = 0) in vec3 vertex_position;
		layout(location = 1) in vec3 vertex_colour;

		out vec3 colour;

		void main()
		{
			colour = vertex_colour;
			gl_Position = vec4( vertex_position, 1.0 );
		}
	)SHADER" );

	auto fshader = ogl.new_shader( gl::shader::type::FRAGMENT, R"SHADER(
		#version 410

		in vec3 colour;
		out vec4 frag_colour;

		void main()
		{
			frag_colour = vec4( colour, 1.0 );
		}
	)SHADER" );

	auto prog = ogl.new_program( vshader, fshader );

	checkgl();

	gl::texture txt;
	gl::framebuffer fb;
	{
		auto bound = txt.bind( gl::texture::target::TEXTURE_RECTANGLE );
		bound.image_2d_rgb( gl::format::RGB, 200, 200, gl::image_type::UNSIGNED_BYTE, nullptr );
		checkgl();

		fb.bind().attach( txt );
		checkgl();
	}

	test["png_write"] = [&]( void )
	{
		checkgl();

		ogl.clear();

		checkgl();

		ogl.viewport( 0, 0, static_cast<size_t>( win->width() ), static_cast<size_t>( win->height() ) );

		checkgl();

		prog->use();

		checkgl();

		auto triangle = vao->bind();
		triangle.draw( gl::primitive::TRIANGLES, 0, 3 );

		checkgl();

		gl::png_write( "/tmp/test.png", static_cast<size_t>( win->width() ), static_cast<size_t>( win->height() ), 3 );

		checkgl();
<commit_msg>Ignore window size when not using it for display.<commit_after>
#include <base/cmd_line.h>
#include <base/unit_test.h>
#include <platform/platform.h>
#include <gl/framebuffer.h>
#include <gl/texture.h>
#include <gl/check.h>
#include <gl/context.h>
#include <gl/png_image.h>

namespace
{

int safemain( int argc, char *argv[] )
{
	base::cmd_line options( argv[0] );

	base::unit_test test( "info" );
	test.setup( options );

	options.add_help();
	options.parse( argc, argv );

	if ( options["help"] )
	{
		std::cerr << options << std::endl;
		return -1;
	}

	// Create a window
	auto sys = platform::platform::common().create();
	auto win = sys->new_window();

	win->set_title( "Triangle" );
	win->acquire();

	// OpenGL initialization
	gl::context ogl;
//	ogl.enable( gl::capability::DEPTH_TEST );
//	ogl.depth_func( gl::depth_test::LESS );

	// Create the geometry for the triangle
	auto vbo_points = ogl.new_array_buffer<float>( {
		0.0F,  0.5F,   0.0F,
		0.5F, -0.5F,   0.0F,
		-0.5F, -0.5F,   0.0F
	} );

	auto vbo_colors = ogl.new_array_buffer<float>( {
		1.0F, 0.0F,  0.0F,
		0.0F, 1.0F,  0.0F,
		0.0F, 0.0F,  1.0F
	} );

	auto vao = ogl.new_vertex_array();
	{
		auto tmp = vao->bind();
		tmp.attrib_pointer( 0, vbo_points, 3 );
		tmp.attrib_pointer( 1, vbo_colors, 3 );
	}

	// The shaders and program for the triangle
	auto vshader = ogl.new_shader( gl::shader::type::VERTEX, R"SHADER(
		#version 410

		layout(location = 0) in vec3 vertex_position;
		layout(location = 1) in vec3 vertex_colour;

		out vec3 colour;

		void main()
		{
			colour = vertex_colour;
			gl_Position = vec4( vertex_position, 1.0 );
		}
	)SHADER" );

	auto fshader = ogl.new_shader( gl::shader::type::FRAGMENT, R"SHADER(
		#version 410

		in vec3 colour;
		out vec4 frag_colour;

		void main()
		{
			frag_colour = vec4( colour, 1.0 );
		}
	)SHADER" );

	auto prog = ogl.new_program( vshader, fshader );

	checkgl();

	gl::texture txt;
	gl::framebuffer fb;
	{
		auto bound = txt.bind( gl::texture::target::TEXTURE_RECTANGLE );
		bound.image_2d_rgb( gl::format::RGB, 200, 200, gl::image_type::UNSIGNED_BYTE, nullptr );
		checkgl();

		fb.bind().attach( txt );
		checkgl();
	}

	test["png_write"] = [&]( void )
	{
		checkgl();

		ogl.clear();

		checkgl();

		ogl.viewport( 0, 0, static_cast<size_t>( 200 ), static_cast<size_t>( 200 ) );

		checkgl();

		prog->use();

		checkgl();

		auto triangle = vao->bind();
		triangle.draw( gl::primitive::TRIANGLES, 0, 3 );

		checkgl();

		gl::png_write( "/tmp/test.png", 200, 200, 3 );

		checkgl();

{'fraction_non_alphanumeric': 0.1786624828397725, 'fraction_numerical': 0.030986467934889194, 'mean_word_length': 3.649042844120328, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 45, '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': '3920471', 'n_tokens_mistral': 2302, 'n_tokens_neox': 2071, 'n_words': 442}