#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_shaders.h"
#include "demo_screen.h"

#include "math_vector3D.h"

#include "part_implicit_plasma.h"

bool implicit_plasma_init = false;

GLint ip_timer;

int programm5 = PR_IMPLICIT_PLASMA;

void implicit_plasma_precalcs()
{
	glClearColor(0.0f, 0.0f, 0.5f, 0.0f);

	ip_timer = MyGetUniformLocation(programm5, "ptimer");

    implicit_plasma_init = true;
}

void DrawQuad5(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.415f

void DrawImplicitPlasma(int ptime)
{
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_CULL_FACE);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	MyUseProgram(programm5);
	MyUniform1f(ip_timer, (float)ptime);

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

	DrawQuad5(16.0f);

	NotUseProgram();
}

void implicit_plasma_run(int ptime)
{
	if (!implicit_plasma_init) implicit_plasma_precalcs();

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	DrawImplicitPlasma(ptime);
}
