/* 
 * This file is automaticaly generated, Please dont edit this file! 
 */
#include <engine/renderPasses/renderPassFont.h> 

























char * font_textFromNumber( font * this, int i ) {

		char * fileName = malloc( sizeof( char ) * 100 );

		sprintf( fileName, "%d", i );

		return fileName;

	}

void font_prepare( font * this ) {

		printf("\n\n\n		Prepare renderPass Font\n\n\n\n\n");

		


		shader * vertexShader = shader_newPointer( GL_VERTEX_SHADER );

		shader_loadFromFile( vertexShader,  "assets/shaders/quad.vertex" );


		shader * fragmentShader = shader_newPointer( GL_FRAGMENT_SHADER );

		shader_loadFromFile( fragmentShader,  "assets/shaders/quad.fragment" );



		this->program 	= program_newPointer();

		program_addShader( this->program,  vertexShader );

		program_addShader( this->program,  fragmentShader );

		program_create( this->program );


		sampler2D * samplerArray		= sampler2D_newPointer();

		samplerArray->target			= GL_TEXTURE_2D_ARRAY;

		samplerArray->format  			= GL_RED;

		samplerArray->internalFormat  	= GL_RED;

		samplerArray->WRAP_S  			= GL_CLAMP_TO_EDGE;

		samplerArray->WRAP_S  			= GL_CLAMP_TO_EDGE;

		samplerArray->cubeSize			= vector3_newPointer( 128, 128, 170 );

		samplerArray->UNPACK_ALIGNMENT	= true;


		this->samplerArray = samplerArray;

		block * fontBlock				= program_getBlock( this->program,  "fontData" );


		this->mesh = mesh_newPointer();

		mesh_setProgram( this->mesh,  this->program );

		mesh_createBuffers( this->mesh );


		glUseProgram( this->program->glProgram );

		for ( int i = 1; i < 170; ++i )
		{
			texture2D * characterTexture 	= fontRenderer_loadFont( this->font,  34 + i );

			vector2 * offset 				= characterTexture->offset;

			printf("%c  offset left:	%f,  offset top:	%f  bitmap->rows:	%i\n", (char) 34 +  i, offset->x, offset->y, characterTexture->height );

			vector2 * size					= vector2_newPointer( characterTexture->width, characterTexture->height );

			block_setMemberItem( fontBlock,  "fontOffsets[0]", i - 35, offset );

			

				block_setMemberItem( fontBlock,  "fontSizes[0]", i - 35, size );
			
			

			sampler2D_addTexture( samplerArray,  characterTexture );

		}

		block_upload( fontBlock );

		program_setUniform( this->program,  "samplerArray", samplerArray );



		vector_int * textArray = vector_int_newPointer();

		char * someText			= "Wauw this is myp first text.";

		for (int i = 0; i < strlen(someText); ++i)
		{

			int charNumber = ( char ) someText[i] - 35;

			printf("	%i\n", charNumber   );

			vector_int_add( textArray,  charNumber );

		}

		block * inputBlock				= program_getBlock( this->program,  "inputBlock" );

		block_setMemberArray( inputBlock,  "characters[0]", ( float * ) textArray->items );

		block_upload( inputBlock );

	}

void font_render( font * this ) {

		int numItems	= 12;


		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

		
		program_use( this->program );

		program_bindBlock( this->program,  "inputBlock");

		program_bindBlock( this->program,  "fontData");


		program_setUniform( this->program,  "samplerArray", this->samplerArray );



		glBindVertexArray( this->mesh->vertexArrayObject );

		glDrawElements( GL_TRIANGLES, numItems, GL_UNSIGNED_INT, ( void * ) 0 ); 

	}

font font_new() {

	font instance;

	instance.font = fontRenderer_newPointer();

	return instance;

}

font * font_newPointer() {

	struct font * pointer = malloc( sizeof ( struct font ) );

	pointer->font = fontRenderer_newPointer();

	return pointer;

}

