                  /*--.          .-"-. 
                 /   ._.        / ´ ` \
                 \_  (__\       \_°v°_/
                 //   \\        //   \\
                ((     ))      ((     ))
 ¤¤¤¤¤¤¤¤¤¤¤¤¤¤--""---""--¤¤¤¤--""---""--¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
 ¤                 |||            |||                                               ¤
 ¤  Author's note:  |              |                                                ¤
 ¤                                                                                  ¤
 ¤  This file is part of work done by Emil Persson, aka Humus.                      ¤
 ¤  You're free to use the code in any way you like, modified, unmodified           ¤
 ¤  or cut'n'pasted into your own work. But for the good of the whole               ¤
 ¤  programming community I will ask you to as long as possible and to the          ¤
 ¤  extent you find suitable to follow these points:                                ¤
 ¤   * If you use this file and it's contents unmodified, please leave this note.   ¤
 ¤   * If you use a major part of the file in your app, please credit the author(s) ¤
 ¤     in one way or the other as you find suitable, for instance a small notice    ¤
 ¤     in the readme file may do, or perhaps a link to the authors site.            ¤
 ¤   * Share your work and ideas too as much as you can.                            ¤
 ¤    _______                                                                       ¤
 ¤  /` _____ `\;,    Humus                                                          ¤
 ¤ (__(^===^)__)';,  emiper-8@student.luth.se                         ___           ¤
 ¤   /  :::  \   ,;  ICQ #47010716                                  /^   ^\         ¤
 ¤  |   :::   | ,;'                                                ( Ö   Ö )        ¤
 ¤¤¤'._______.'`¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤--°oOo--(_)--oOo°--¤¤*/


#include "FoggedPolygon.h"
#include "../Framework/OpenGL/glExtensions.h"

void FoggedPolygon::draw(Renderer *renderer, const Vertex &pos, const float worldsize){
	renderer->setTextures(material->textures[0], 0);
	renderer->setColorTexEnvs(TEXENV_MODULATE, TEXENV_PASSTHRU);
	renderer->setAlphaTexEnvs(TEXENV_PASSTHRU, TEXENV_REPLACE);
	//renderer->setTexEnvs(TEXENV_MODULATE, TEXENV_MODULATE);
	renderer->apply();
	
	glBegin(GL_TRIANGLE_FAN);
	for (unsigned int i = 0; i < nVertices; i++){
		Vertex v = vertices[i] - origin;

		if (vertices[i].y > 3100){
			float h = 0.01f * (vertices[i].y - 3100);
			glColor3f(h,h,h);
		} else {
			float f = 1.1f - vertices[i].y * 0.001f;
			float g = -0.03f * (2700 + vertices[i].x);
			if (vertices[i].x > -2700) g = 0;
			glColor3f(f + g, g, g);
		}
		glMultiTexCoord2fARB(GL_TEXTURE0_ARB, v * s * scaleS, v * t * scaleT);
		glMultiTexCoord3fvARB(GL_TEXTURE1_ARB, (vertices[i] - pos) / worldsize + Vertex(0.5f, 0.5f, 0.5f));
		glVertex3fv(vertices[i]);
	}
	glEnd();
}

void FoggedPolygon::drawFoggedOnly(Renderer *renderer, const Vertex &pos, const float worldsize){
	renderer->setTextures(0);
	renderer->setTexEnvs(TEXENV_REPLACE);
	renderer->apply();
	
	glBegin(GL_TRIANGLE_FAN);
	for (unsigned int i = 0; i < nVertices; i++){
		glMultiTexCoord3fvARB(GL_TEXTURE0_ARB, (vertices[i] - pos) / worldsize + Vertex(0.5f, 0.5f, 0.5f));
		glVertex3fv(vertices[i]);
	}
	glEnd();
}

class Polygon *FoggedPolygon::create(const int size) const {
	return new FoggedPolygon(size);
}









class Polygon *foggedPolyCreator(const int size){
	return new FoggedPolygon(size);
}
