// File: /workspace/github_c_makefile_star2_O0/k0n10pl4tr[P]minimal_crafter/rendering.c
// Function: initRenderingSystem
void
initRenderingSystem()
{
	unsigned int cubeRenderingVertex = loadShader("shaders/cubeRendering.vsh", GL_VERTEX_SHADER);
	unsigned int cubeRenderingFragment = loadShader("shaders/cubeRendering.fsh", GL_FRAGMENT_SHADER);

	unsigned int cubeRenderingShaderShaders[] = { cubeRenderingVertex, cubeRenderingFragment, 0 };
	cubeRenderingShader = createProgram(cubeRenderingShaderShaders);

	glDeleteShader(cubeRenderingVertex);
	glDeleteShader(cubeRenderingFragment);

	glGenBuffers(1, &cubeVertexBuffer);
	glBindBuffer(GL_ARRAY_BUFFER, cubeVertexBuffer);
	glBufferData(GL_ARRAY_BUFFER, sizeof(cubeBufferData), cubeBufferData, GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	glGenVertexArrays(1, &cubeVertexArray);
	glBindVertexArray(cubeVertexArray);
	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);
	glBindBuffer(GL_ARRAY_BUFFER, cubeVertexBuffer);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)(0));
	glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (void*)(36 * 3 * sizeof(float)));
	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindVertexArray(0);

	cubeUniformProjectionLocation = glGetUniformLocation(cubeRenderingShader, "projectionMatrix");
	cubeUniformModelLocation      = glGetUniformLocation(cubeRenderingShader, "modelMatrix");
	cubeUniformViewLocation       = glGetUniformLocation(cubeRenderingShader, "viewMatrix");

	mat4x4_perspective(projectionMatrix, TO_RADIANS(70.0), 4.0/3.0, 0.01, 100.0);
	mat4x4_identity(modelMatrix);
	mat4x4_identity(viewMatrix);

	glUseProgram(cubeRenderingShader);
	glUniformMatrix4fv(cubeUniformProjectionLocation, 1, GL_FALSE, &projectionMatrix[0][0]);
	glUniformMatrix4fv(cubeUniformModelLocation,      1, GL_FALSE, &modelMatrix[0][0]);
	glUniformMatrix4fv(cubeUniformViewLocation,       1, GL_FALSE, &viewMatrix[0][0]);
	glUseProgram(0);
	
	cubeTexture        = loadTextureFarbfeld("textures/test.ff");
	cubeTerrainTexture = loadTextureFarbfeld("textures/terrain.ff");

	for(unsigned int i = 0; i < NUM_CHUNK_CACHED; i++) {
		chunkCached[i].canDraw = 0;
		glGenBuffers(1, &chunkCached[i].vbo);
		glGenVertexArrays(1, &chunkCached[i].vao);
			
		glBindBuffer(GL_ARRAY_BUFFER, chunkCached[i].vbo);
		glBufferData(GL_ARRAY_BUFFER, WORLD_CHUNK_NBLOCKS * 30 * 6 * sizeof(float), NULL, GL_DYNAMIC_DRAW);
		glBindBuffer(GL_ARRAY_BUFFER, 0);

		glBindVertexArray(chunkCached[i].vao);
		glEnableVertexAttribArray(0);
		glEnableVertexAttribArray(1);
		glBindBuffer(GL_ARRAY_BUFFER, chunkCached[i].vbo);
		glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 3, (void*)(0));
		glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, (void*)(WORLD_CHUNK_NBLOCKS * 18 * 6 * sizeof(float)));
		glBindBuffer(GL_ARRAY_BUFFER, 0);
		glBindVertexArray(0);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
leaq 0x5791(%rip), %rdi      # 0xafb0
movl $0x8b31, %esi           # imm = 0x8B31
callq 0x2fb0
movl %eax, -0x4(%rbp)
leaq 0x5797(%rip), %rdi      # 0xafca
movl $0x8b30, %esi           # imm = 0x8B30
callq 0x2fb0
movl %eax, -0x8(%rbp)
movl -0x4(%rbp), %eax
movl %eax, -0x14(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0x10(%rbp)
movl $0x0, -0xc(%rbp)
leaq -0x14(%rbp), %rdi
callq 0x3130
movl %eax, 0x8eee(%rip)      # 0xe750
leaq 0x84f7(%rip), %rax      # 0xdd60
movq (%rax), %rax
movl -0x4(%rbp), %edi
callq *%rax
leaq 0x84e8(%rip), %rax      # 0xdd60
movq (%rax), %rax
movl -0x8(%rbp), %edi
callq *%rax
movl $0x1, %edi
leaq 0x8ec8(%rip), %rsi      # 0xe754
leaq 0x85fd(%rip), %rax      # 0xde90
callq *(%rax)
leaq 0x82fc(%rip), %rax      # 0xdb98
movq (%rax), %rax
movl 0x8eaf(%rip), %esi      # 0xe754
movl $0x8892, %edi           # imm = 0x8892
callq *%rax
movl $0x8892, %edi           # imm = 0x8892
movl $0x2d0, %esi            # imm = 0x2D0
leaq 0x5423(%rip), %rdx      # 0xace0
movl $0x88e4, %ecx           # imm = 0x88E4
leaq 0x834f(%rip), %rax      # 0xdc18
callq *(%rax)
movl $0x8892, %edi           # imm = 0x8892
xorl %esi, %esi
leaq 0x82bf(%rip), %rax      # 0xdb98
callq *(%rax)
movl $0x1, %edi
leaq 0x8e71(%rip), %rsi      # 0xe758
leaq 0x85d2(%rip), %rax      # 0xdec0
callq *(%rax)
leaq 0x82e9(%rip), %rax      # 0xdbe0
movq (%rax), %rax
movl 0x8e58(%rip), %edi      # 0xe758
callq *%rax
xorl %edi, %edi
leaq 0x8505(%rip), %rax      # 0xde10
callq *(%rax)
movl $0x1, %edi
leaq 0x84f7(%rip), %rax      # 0xde10
callq *(%rax)
leaq 0x8276(%rip), %rax      # 0xdb98
movq (%rax), %rax
movl 0x8e29(%rip), %esi      # 0xe754
movl $0x8892, %edi           # imm = 0x8892
callq *%rax
xorl %ecx, %ecx
movl $0x3, %esi
movl $0x1406, %edx           # imm = 0x1406
movl $0xc, %r8d
xorl %eax, %eax
movl %eax, %r9d
leaq 0x8d80(%rip), %rax      # 0xe6d0
movl %ecx, %edi
callq *(%rax)
movl $0x1, %edi
movl $0x2, %esi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
movl $0x8, %r8d
movl $0x1b0, %r9d            # imm = 0x1B0
leaq 0x8d58(%rip), %rax      # 0xe6d0
callq *(%rax)
movl $0x8892, %edi           # imm = 0x8892
xorl %esi, %esi
leaq 0x8210(%rip), %rax      # 0xdb98
callq *(%rax)
xorl %edi, %edi
leaq 0x824d(%rip), %rax      # 0xdbe0
callq *(%rax)
leaq 0x86e4(%rip), %rax      # 0xe080
movq (%rax), %rax
movl 0x8dab(%rip), %edi      # 0xe750
leaq 0x5638(%rip), %rsi      # 0xafe4
callq *%rax
movl %eax, 0x8da8(%rip)      # 0xe75c
leaq 0x86c5(%rip), %rax      # 0xe080
movq (%rax), %rax
movl 0x8d8c(%rip), %edi      # 0xe750
leaq 0x562a(%rip), %rsi      # 0xaff5
callq *%rax
movl %eax, 0x8d8d(%rip)      # 0xe760
leaq 0x86a6(%rip), %rax      # 0xe080
movq (%rax), %rax
movl 0x8d6d(%rip), %edi      # 0xe750
leaq 0x5617(%rip), %rsi      # 0xb001
callq *%rax
movl %eax, 0x8d72(%rip)      # 0xe764
leaq 0x8d77(%rip), %rdi      # 0xe770
movss 0x528b(%rip), %xmm0     # 0xac8c
movss 0x5287(%rip), %xmm1     # 0xac90
movss 0x5283(%rip), %xmm2     # 0xac94
movss 0x527f(%rip), %xmm3     # 0xac98
callq 0x5c80
leaq 0x8d8b(%rip), %rdi      # 0xe7b0
callq 0x5e00
leaq 0x8dbf(%rip), %rdi      # 0xe7f0
callq 0x5e00
leaq 0x8a73(%rip), %rax      # 0xe4b0
movq (%rax), %rax
movl 0x8d0a(%rip), %edi      # 0xe750
callq *%rax
leaq 0x8a41(%rip), %rax      # 0xe490
movq (%rax), %rax
movl 0x8d04(%rip), %edi      # 0xe75c
movl $0x1, %esi
xorl %edx, %edx
leaq 0x8d0a(%rip), %rcx      # 0xe770
callq *%rax
leaq 0x8a21(%rip), %rax      # 0xe490
movq (%rax), %rax
movl 0x8ce8(%rip), %edi      # 0xe760
movl $0x1, %esi
xorl %edx, %edx
leaq 0x8d2a(%rip), %rcx      # 0xe7b0
callq *%rax
leaq 0x8a01(%rip), %rax      # 0xe490
movq (%rax), %rax
movl 0x8ccc(%rip), %edi      # 0xe764
movl $0x1, %esi
xorl %edx, %edx
leaq 0x8d4a(%rip), %rcx      # 0xe7f0
callq *%rax
xorl %edi, %edi
leaq 0x89ff(%rip), %rax      # 0xe4b0
callq *(%rax)
leaq 0x5552(%rip), %rdi      # 0xb00c
callq 0x31d0
movl %eax, 0x8d6b(%rip)      # 0xe830
leaq 0x5551(%rip), %rdi      # 0xb01d
callq 0x31d0
movl %eax, 0x8d5d(%rip)      # 0xe834
movl $0x0, -0x18(%rbp)
cmpl $0x100, -0x18(%rbp)     # imm = 0x100
jae 0x5c6f
movl -0x18(%rbp), %eax
movl %eax, %ecx
leaq 0x8d49(%rip), %rax      # 0xe840
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x18(%rax)
leaq 0x8387(%rip), %rax      # 0xde90
movq (%rax), %rax
movl -0x18(%rbp), %ecx
leaq 0x8d2a(%rip), %rsi      # 0xe840
imulq $0x1c, %rcx, %rcx
addq %rcx, %rsi
addq $0x4, %rsi
movl $0x1, %edi
callq *%rax
leaq 0x8391(%rip), %rax      # 0xdec0
movq (%rax), %rax
movl -0x18(%rbp), %ecx
leaq 0x8d04(%rip), %rsi      # 0xe840
imulq $0x1c, %rcx, %rcx
addq %rcx, %rsi
movl $0x1, %edi
callq *%rax
leaq 0x8047(%rip), %rax      # 0xdb98
movq (%rax), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %edx
leaq 0x8ce0(%rip), %rcx      # 0xe840
imulq $0x1c, %rdx, %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %esi
movl $0x8892, %edi           # imm = 0x8892
callq *%rax
movl $0x8892, %edi           # imm = 0x8892
movl $0x2d0000, %esi         # imm = 0x2D0000
xorl %eax, %eax
movl %eax, %edx
movl $0x88e8, %ecx           # imm = 0x88E8
leaq 0x808d(%rip), %rax      # 0xdc18
callq *(%rax)
movl $0x8892, %edi           # imm = 0x8892
xorl %esi, %esi
leaq 0x7ffd(%rip), %rax      # 0xdb98
callq *(%rax)
leaq 0x803c(%rip), %rax      # 0xdbe0
movq (%rax), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %edx
leaq 0x8c8d(%rip), %rcx      # 0xe840
imulq $0x1c, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %edi
callq *%rax
xorl %edi, %edi
leaq 0x8249(%rip), %rax      # 0xde10
callq *(%rax)
movl $0x1, %edi
leaq 0x823b(%rip), %rax      # 0xde10
callq *(%rax)
leaq 0x7fba(%rip), %rax      # 0xdb98
movq (%rax), %rax
movl -0x18(%rbp), %ecx
movl %ecx, %edx
leaq 0x8c53(%rip), %rcx      # 0xe840
imulq $0x1c, %rdx, %rdx
addq %rdx, %rcx
movl 0x4(%rcx), %esi
movl $0x8892, %edi           # imm = 0x8892
callq *%rax
xorl %ecx, %ecx
movl $0x3, %esi
movl $0x1406, %edx           # imm = 0x1406
movl $0xc, %r8d
xorl %eax, %eax
movl %eax, %r9d
leaq 0x8ab4(%rip), %rax      # 0xe6d0
movl %ecx, %edi
callq *(%rax)
movl $0x1, %edi
movl $0x2, %esi
movl $0x1406, %edx           # imm = 0x1406
xorl %ecx, %ecx
movl $0x8, %r8d
movl $0x1b0000, %r9d         # imm = 0x1B0000
leaq 0x8a8c(%rip), %rax      # 0xe6d0
callq *(%rax)
movl $0x8892, %edi           # imm = 0x8892
xorl %esi, %esi
leaq 0x7f44(%rip), %rax      # 0xdb98
callq *(%rax)
xorl %edi, %edi
leaq 0x7f81(%rip), %rax      # 0xdbe0
callq *(%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x5ade
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)