#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 "part_volume0.h"
#include "project_textures.h"
#include "project_shaders.h"
#include "project_volumes.h"
#include "data_volumes.h"
#include "math_vector3D.h"

bool volume0_init = false;

const int vol0dat_num = VOL_PLASMA1;

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

	glActiveTextureARB(GL_TEXTURE0);
	glEnable(GL_TEXTURE_3D);
	glBindTexture(GL_TEXTURE_3D, volumes[vol0dat_num]->GetVolumeID());

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	NotUseProgram();
}

void volume0_precalcs()
{
	volumes[vol0dat_num]->InitVolumeTexture();

    volume0_init = true;
}



void DrawVolume0(int ptime)
{ptime = 0;
	float px = sin((float)ptime / 932.0f) * 8.0f;
	float py = sin((float)ptime / 1124.0f) * 6.0f;
	float pz = -80.0f - (sin((float)ptime / 1324.0f) * 16.0f + 16.0f);

	float vx = 0.25f + sin((float)ptime / 150.0f) * 0.1f + 0.15f;
	float vy = 0.25f + sin((float)ptime / 150.0f) * 0.075f + 0.125f;
	float vz = 2.75f + sin((float)ptime / 200.0f) * 0.05f + 0.1f;

	volumes[vol0dat_num]->RenderVolume(VRND_SLICES, true, Cvector(px, py, pz), Cvector(1,1,vz), Cvector(1, vy, 1), Cvector(vx, 1, 1));
}

void volume0_run(int ptime)
{
	if (!volume0_init) volume0_precalcs();

	volume0_init_frame();
	DrawVolume0(ptime);
}
