
/*
 * sandbox to create a decent fire effect
 * particle engine on the GPU
 * from Nopper ogl 3.2 tutorial 08
*/
#pragma once

#include <memory>
#include <vector>

#include "demo_base.h"
#include "common.hpp"
#include "shader.hpp"
#include "tga.h"
#include "transformation_node.h"
#include "geometry_node.h"

class demo_fire : public demo_base {
public:
	demo_fire(void);
	virtual ~demo_fire(void);
	virtual bool init();

protected:
	const int particle_lookup_width;
	//members
	int max_particles;
	std::vector<GLfloat> points;		//points for referencing each texel
	std::vector<GLfloat> particles;	//initial particle data
	//available shaders
	std::auto_ptr<Shader> render;
	std::auto_ptr<Shader> update;
	//object handles
	GLuint vertex_vbo_id, vao_id;
	GLuint texture_particle, texture_particle2, texture_particle3;  //texture handles
	GLuint texture_lookup[2];
	GLuint framebuffer_lookup[2]; //framebuffer for both textures
	GLint size_location, //locations for shader variables
		time_location,
		vertex_location,
		vertex_update_location,
		texture_location, texture_location2, texture_location3,
		lookup_texture_location,
		lookup_texture_update_location;
	GLint flip;
	//fire parameters
	float burn_speed;


	//functions
	virtual void process_keys();
	virtual void draw();	//main drawing method
	virtual void cleanup(); //do some cleanup if necessary
	void init_particles();
	void update_particles();
	bool loadGLTextures();
	float rand_float();


};