#define NO_SDL_GLEXT

#include <GL/glew.h>
#include <SDL/SDL_OpenGL.h>
#include <GL/gl.h>
#include <GL/glu.h>

#include <math.h>

#include "demo_script.h"
#include "demo_textures.h"
#include "demo_meshes.h"
#include "demo_shaders.h"
#include "demo_screen.h"
#include "demo_timer.h"

#include "math_vector3D.h"

#include "part_voronoi.h"

bool voronoi_init = false;

int programm_voronoi = PR_VORONOI;

GLint vrn_timer;

void voronoi_precalcs()
{
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_CULL_FACE);

	vrn_timer = MyGetUniformLocation(programm_voronoi, "ptimer");

    voronoi_init = true;
}

void DrawQuadVoronoi(float l)
{
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f); glVertex2f(-l, -l);
		glTexCoord2f(1.0f, 0.0f); glVertex2f( l, -l);
		glTexCoord2f(1.0f, 1.0f); glVertex2f( l, l);
		glTexCoord2f(0.0f, 1.0f); glVertex2f(-l, l);
	glEnd();
}

#define shite -2.41425f

void DrawVoronoi(int ptime)
{
	MyUseProgram(programm_voronoi);
	MyUniform1f(vrn_timer, (float)ptime / 4096.0);

	glLoadIdentity();
	glTranslatef(0.0f, 0.0f, shite * 16.0f);
	DrawQuadVoronoi(16.0f);
}

void voronoi_run(int ptime)
{
	if (!voronoi_init) voronoi_precalcs();

	DrawVoronoi(ptime);
}
