Index: P/trunk/Lib/Illum/GPUObscurancesGT/src/vcObscuranceMap1.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/GPUObscurancesGT/src/vcObscuranceMap1.cpp	(revision 930)
+++ 	(revision )
@@ -1,1071 +1,0 @@
-//========================================
-//	Class to interface the VisualCAD specifications.
-//	Nicolau Sunyer & Sergi Funtané (10/13/2005).
-//	Universitat de Girona.
-//========================================
-
-#pragma warning(disable:4244)
-// Includes
-#define GLEW_STATIC 1
-#include "glew.h"
-#include <iostream>
-#include "textfile.h"
-
-// Includes
-#include "CMesh.h"
-#include "vcObscuranceMap.h"
-#include <imdebug.h>
-#include <imdebuggl.h>
-
-#ifndef M_PI
-	#define M_PI        3.14159265358979323846
-#endif
-
-// DepthPeeling Layers.
-#define MAX_LAYERS	12
-
-// To use Offsets in the PBOs.
-#define BUFFER_OFFSET(i) ((char *)NULL + (i))
-
-//GLSL
-// Handlers
-GLuint vProjection,fProjection,pProjection;
-GLuint vReflect, fReflect, pReflect;
-GLuint vCopy, fCopy, pCopy;
-GLuint vTransfer, fTransfer, pTransfer;
-
-//Uniform Parameters
-//Projection Step
-GLint TexturaDepthProjection;
-GLint SizeProjection;
-GLint FirstProjection;
-
-//Reflectivity texture generation Step.
-
-//Texture Copy Step.
-GLint TextureCopy;
-GLint Texture2Copy;
-
-//Energy Transfer Step.
-GLint TexturaReflectTransfer;
-GLint DirectionTransfer;
-GLint DmaxTransfer;
-
-// Global variables
-CVert Vertex, Direccio, Increment, Primer, Ultim, Origin;	
-
-static GLuint texName[3];
-
-static int ResX;		//Resolution
-static int ResY;
-static int Res2X;		//Resolution
-static int Res2Y;		//Resolution
-
-//RenderTexture *ob=NULL;								// RenderTexture for the Obscurances.
-
-static GLuint texProjeccions[2]; //Texture name
-static GLuint texTransfer[1];
-static GLuint texReflect[1];
-static GLuint texCopy[1];
-static GLuint fb1; // Framebuffer Reflectivity
-static GLuint fb2; // Framebuffer Projeccions
-static GLuint fb3; // Framebuffer Transfer
-static GLuint fb4; // Framebuffer Copy
-
-
-
-GLenum glerror;
-
-GLfloat *m_pTextureImage;// Texture of diferent colors.
-GLfloat *m_pTextureReflect; //Texture of reflectivitat.
-GLfloat *m_pBlau;
-GLfloat *m_pNegre;
-int obs_global_cancelar;
-
-CMesh	g_pMesh;						// Mesh Data
-static CSphere Esfera;
-
-static GLuint	ProjectionsPBO[MAX_LAYERS+2];	// PBOs to store the projections.
-static GLuint	ObscurancesPBO;					// PBOs to store the projections.
-static GLuint	ztex;								//Texture with the depth.
-
-
-// Function to use when the window is resized
-void changeSize(int w, int h) 
-{
-
-	if(h == 0)
-		h = 1;
-
-	float ratio = 1.0 * (float)w / (float)h;
-
-	//Camera Set up
-	glMatrixMode(GL_PROJECTION);
-	glLoadIdentity();
-	gluOrtho2D(-w,w,-h,h);
-
-	glMatrixMode(GL_MODELVIEW);
-	glLoadIdentity();
-
-	glViewport(0, 0, w, h);
-
-}
-
-
-// Returns a random point in the surface of the sphere
-CVert ranpoint(float r, CVert c)
-{
-	double ale1, ale2;
-	CVert p;
-	float alfa,beta;
-
-	ale1= (float)rand()/(float)RAND_MAX; 
-	ale2= (float)rand()/(float)RAND_MAX;
- 
-    alfa=1.0-2.0*ale1;	/* real between -1 and 1 */
-    alfa=acos(alfa);	/* angle between 0 and PI */
-
-    beta=2*M_PI*ale2;	/* angle between 0 and 2*PI */
-   
-    p.x=c.x+r*sin(alfa)*cos(beta);
-    p.y=c.y+r*sin(alfa)*sin(beta);
-    p.z=c.z+r*cos(alfa);
-   
-    return p;
-}
-
-// Function to find a point in the sphere in the direction that goes from the point in the surface of the sphere
-// to the center of the sphere. First it gets the random point in the surface.
-void BuscarDireccio()
-{
-	Esfera.center.x = 0.0;
-	Esfera.center.y = 0.0;
-	Esfera.center.z = 0.0;
-	Esfera.radius = sqrt(12.0)/2.0;
-
-	Primer = ranpoint(Esfera.radius,Esfera.center);
-	Vertex.x = Primer.x + (Esfera.center.x-Primer.x) * ((float)rand()/(float)RAND_MAX)*2.0;
-	Vertex.y = Primer.y + (Esfera.center.y-Primer.y) * ((float)rand()/(float)RAND_MAX)*2.0;
-	Vertex.z = Primer.z + (Esfera.center.z-Primer.z) * ((float)rand()/(float)RAND_MAX)*2.0;
-}
-
-// Function that renders the depth peeling geometry planes and stores them in PBOs.
-void RenderProjeccions(int buffer, int first)
-{
-	int i, j, e;
-
-		glUseProgram(pProjection);
-		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb2);
-
-		changeSize(ResX, ResY);
-		glEnable (GL_DEPTH_TEST);									// Enable Depth Testing
-		glDepthFunc(GL_LESS);
-
-		glDisable(GL_CULL_FACE);
-
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		glOrtho(-Esfera.radius,Esfera.radius,-Esfera.radius,Esfera.radius,0,Esfera.radius * 2.0);	
-
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-		gluLookAt(Primer.x,Primer.y,Primer.z, 
-			      Esfera.center.x,Esfera.center.y,Esfera.center.z,
-				  0.0f,1.0f,0.0f);
-
-		glViewport(0,0,ResX,ResY);
-
-		glUniform1f(SizeProjection, (float)ResX);
-		glUniform1f(FirstProjection, (float)first);
-
-		int other = ((buffer == 1)? 0:1);
-		if(first == 0)
-		{
-			glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[other] );			// Bind The Buffer
-			glBindTexture(GL_TEXTURE_2D,texName[0]);
-			glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, ResX, ResY);
-			glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 );			// Bind The Buffer
-			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
-			glActiveTexture(GL_TEXTURE0);
-			glBindTexture(GL_TEXTURE_2D, texName[0]);
-			glUniform1i(TexturaDepthProjection, 0);
-		}
-
-		// Enable Pointers
-		glEnableClientState( GL_VERTEX_ARRAY );						// Enable Vertex Arrays
-		glEnableClientState( GL_TEXTURE_COORD_ARRAY );				// Enable Texture Coord Arrays
-		glEnableClientState( GL_NORMAL_ARRAY );				// Enable Texture Coord Arrays
-
-		for(i=0; i<g_pMesh.m_pObject._numGeos;i++)
-		{
-			for(j=0; j<g_pMesh.m_pObject._geo[i]._numTriSets;j++)
-			{
-				// Set Pointers To Our Data
-				glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOVertices );
-				glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL );		// Set The Vertex Pointer To The Vertex Buffer
-				glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOTexCoords );
-				glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL );		// Set The TexCoord Pointer To The TexCoord Buffer
-				glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBONormals );
-				glNormalPointer( GL_FLOAT, 0, (char *) NULL );		// Set The TexCoord Pointer To The TexCoord Buffer
-				glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOIndexs );
-
-				// Render
-				glDrawElements( GL_TRIANGLES, g_pMesh.m_pObject._geo[i]._triSet[j]._numTris*3,GL_UNSIGNED_INT,BUFFER_OFFSET(0) );	// Draw All Of The Quads At Once
-
-			}
-		}
-
-		glDisableClientState( GL_VERTEX_ARRAY );					// Disable Vertex Arrays
-		glDisableClientState( GL_TEXTURE_COORD_ARRAY );				// Disable Texture Coord Arrays
-		glDisableClientState( GL_NORMAL_ARRAY );				// Disable Texture Coord Arrays
-
-		//Copy the color buffer to PBO.
-		glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[buffer] );			// Bind The Buffer
-		glReadPixels(0, 0, ResX, ResY, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
-		glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0);
-
-		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-		glUseProgram(0);
-}
-
-// Function that calculates the lightmap using the neighbouring projections.
-void RenderTransfer(int buffer, int first)
-{
-	glUseProgram(pTransfer);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb3);
-
-		int other = ((buffer == 1)? 0:1);
-
-		glBlendFunc(GL_ONE, GL_ONE);
-
-		glEnable(GL_BLEND);
-
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		gluOrtho2D(-1,1,-1,1);
-
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-		glPointSize(1.0);
-
-		glViewport(0, 0, Res2X, Res2Y);
-
-		glUniform1f(DmaxTransfer, (GLfloat)0.3);
-//		glUniform1f(DirectionTransfer, 0.0);
-		glActiveTexture(GL_TEXTURE0);
-		glBindTexture(GL_TEXTURE_2D, texReflect[0]);
-		glUniform1i(TexturaReflectTransfer, 0);
-		
-		if(first == 1)
-		{
-//			printf("\nEntrem al first");
-//			printf("\nFirst: %d", first);
-//			printf("\nBuffer: %d", buffer);
-			//First Render
-			glUniform1f(DirectionTransfer, (float)buffer);
-			glEnableClientState( GL_VERTEX_ARRAY );						// Enable Vertex Arrays
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[buffer] );
-			glVertexPointer( 4, GL_FLOAT, 0, (char *) NULL );		// Set The Vertex Pointer To The Vertex Buffer
-
-			glEnableClientState( GL_TEXTURE_COORD_ARRAY );				// Enable Texture Coord Arrays
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[other] );
-			glTexCoordPointer( 4, GL_FLOAT, 0, (char *) NULL );		// Set The TexCoord Pointer To The TexCoord Buffer
-
-			glDrawArrays(GL_POINTS, 0, ResX*ResY );
-		}
-		else
-		{
-//			printf("\nNo entrem al first");
-//			printf("\nFirst: %d", first);
-//			printf("\nBuffer: %d", buffer);
-			glUniform1f(DirectionTransfer, 0.0);
-
-			glEnableClientState( GL_VERTEX_ARRAY );						// Enable Vertex Arrays
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[buffer] );
-			glVertexPointer( 4, GL_FLOAT, 0, (char *) NULL );		// Set The Vertex Pointer To The Vertex Buffer
-
-			glEnableClientState( GL_TEXTURE_COORD_ARRAY );				// Enable Texture Coord Arrays
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[other] );
-			glTexCoordPointer( 4, GL_FLOAT, 0, (char *) NULL );		// Set The TexCoord Pointer To The TexCoord Buffer
-
-			glDrawArrays(GL_POINTS, 0, ResX*ResY );
-
-			glUniform1f(DirectionTransfer, 1.0);
-
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[other] );
-			glVertexPointer( 4, GL_FLOAT, 0, (char *) NULL );		// Set The Vertex Pointer To The Vertex Buffer
-
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[buffer] );
-			glTexCoordPointer( 4, GL_FLOAT, 0, (char *) NULL );		// Set The TexCoord Pointer To The TexCoord Buffer
-
-			glDrawArrays(GL_POINTS, 0, ResX*ResY );
-		}
-
-		glDisableClientState( GL_VERTEX_ARRAY );					// Disable Vertex Arrays
-		glDisableClientState( GL_TEXTURE_COORD_ARRAY );				// Disable Texture Coord Arrays
-
-		glDisable(GL_BLEND);
-	glUseProgram(0);
-
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-
-}
-
-// Function that copies the 16-bit fp RGBA buffer of the lightmap to a 32-bit RGBA fb buffer.
-void CopyTexture(void)
-{
-	glUseProgram(pCopy);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb4);
-	void *texturePBO;
-	
-		glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ObscurancesPBO );			// Bind The Buffer
-		texturePBO = glMapBuffer(GL_PIXEL_PACK_BUFFER_EXT, GL_READ_ONLY);
-		glBindTexture(GL_TEXTURE_2D,texName[1]);
-		glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, Res2X, Res2Y, GL_RGBA, GL_FLOAT, texturePBO);
-		glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB);
-		glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 );			// Bind The Buffer
-
-		glEnable(GL_CULL_FACE);
-
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		gluOrtho2D(-Res2X,Res2Y,-Res2X,Res2Y);
-
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-
-		glViewport(0, 0, Res2X, Res2Y);
-
-		glActiveTexture(GL_TEXTURE0);
-		glBindTexture(GL_TEXTURE_2D, texTransfer[0]);
-		glUniform1i(TextureCopy, 0);
-		glActiveTexture(GL_TEXTURE1);
-		glBindTexture(GL_TEXTURE_2D, texName[1]);
-		glUniform1i(Texture2Copy, 1);
-		glActiveTexture(GL_TEXTURE0);
-
-
-		//Draw the geometry. 
-		glBegin(GL_QUADS);
-		{
-			glTexCoord2f(0,      0);       glVertex3f(-Res2X, -Res2Y, -0.5f);
-			glTexCoord2f(1,0);       glVertex3f(Res2X, -Res2Y, -0.5f);
-			glTexCoord2f(1,1); glVertex3f(Res2X, Res2Y, -0.5f);
-			glTexCoord2f(0,      1); glVertex3f(-Res2X, Res2Y, -0.5f);
-		}
-		glEnd();
-
-		//Copy Buffer to PBO.
-		glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT,ObscurancesPBO );			// Bind The Buffer
-		glReadPixels(0, 0, Res2X, Res2Y, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
-		glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0);
-
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb3);
-	glClearColor(0.0,0.0,0.0,0.0);
-	glClear(GL_COLOR_BUFFER_BIT);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-	glUseProgram(0);
-}
-
-// Function that calculates the reflectivity map from the scene data.
-void RenderReflect(void)
-{
-	int i, j;
-	glUseProgram(pReflect);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb1);
-
-		glClearColor(0.0,0.0,0.0,0.0);
-		glClear(GL_COLOR_BUFFER_BIT);
-
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		gluOrtho2D(0,1,0,1);
-
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-
-		glViewport(0, 0, Res2X, Res2Y);
-
-		// Enable Pointers
-		glEnableClientState( GL_VERTEX_ARRAY );						// Enable Vertex Arrays
-		glEnableClientState( GL_COLOR_ARRAY );				// Enable Texture Coord Arrays
-
-		for(i=0; i<g_pMesh.m_pObject._numGeos;i++)
-		{
-			for(j=0; j<g_pMesh.m_pObject._geo[i]._numTriSets;j++)
-			{
-				// Set Pointers To Our Data
-				glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOTexCoords );
-				glVertexPointer( 2, GL_FLOAT, 0, (char *) NULL );		// Set The Vertex Pointer To The Vertex Buffer
-				glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOColors );
-				glColorPointer( 3, GL_FLOAT, 0, (char *) NULL );		// Set The TexCoord Pointer To The TexCoord Buffer
-				glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOIndexs );
-
-				// Render
-				glDrawElements( GL_TRIANGLES, g_pMesh.m_pObject._geo[i]._triSet[j]._numTris*3,GL_UNSIGNED_INT,BUFFER_OFFSET(0) );	// Draw All Of The Quads At Once
-
-			}
-		}
-
-		glDisableClientState( GL_VERTEX_ARRAY );			// Enable Vertex Arrays
-		glDisableClientState( GL_COLOR_ARRAY );				// Enable Texture Coord Arrays
-
-	glUseProgram(0);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-}
-
-// Function that updates the lightmap. 
-// The number of directions used to calculate the lightmap is iterations * steps
-void UpdateTexture(int iterations, int steps)
-{
-	printf("\nIteracions: %d => Steps: %d\n", iterations, steps);
-	for(int i = 0; i < steps; i++)
-	{
-		for(int j = 0; j < iterations; j++)
-		{
-			printf("\rProgress: %d%%",i*100/steps + j*100/(steps*iterations));
-			BuscarDireccio();				// Find a random direction
-				glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb2);
-					glClearColor(0.0,0.0,1.0,1.0);
-					glClearDepth(1.0);
-					glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-				glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-//				printf("\nRender Blau: 0");
-//				printf("\nRender Projeccions: 1, 1");
-				RenderProjeccions(1,1);
-/*//Debug
-		glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_EXT, ProjectionsPBO[0] );			// Bind The Buffer
-		glBindTexture(GL_TEXTURE_2D, texName[0]);
-		glTexSubImage2D(GL_TEXTURE_2D, 0,0,0, ResX, ResY, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
-		imdebugTexImagef(GL_TEXTURE_2D,texName[0],GL_RGBA,0,NULL);
-		glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_EXT, ProjectionsPBO[1] );			// Bind The Buffer
-		glBindTexture(GL_TEXTURE_2D, texName[0]);
-		glTexSubImage2D(GL_TEXTURE_2D, 0,0,0, ResX, ResY, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
-		imdebugTexImagef(GL_TEXTURE_2D,texName[0],GL_RGBA,0,NULL);
-//End Debug*/
-//				printf("\nRender Transfer:  0, 1");
-				RenderTransfer(1,1);
-//		imdebugTexImagef(GL_TEXTURE_2D,texTransfer[0],GL_RGBA,0,NULL);
-				int l = 0;
-				for(int k=1; k < MAX_LAYERS; k++)
-				{
-//					printf("\nProjeccions: %d", l);
-//					printf("\nRender Projeccions: %d, 0",l);
-					RenderProjeccions(l,0);
-/*//Debug
-		glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_EXT, ProjectionsPBO[l] );			// Bind The Buffer
-		glBindTexture(GL_TEXTURE_2D, texName[0]);
-		glTexSubImage2D(GL_TEXTURE_2D, 0,0,0, ResX, ResY, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
-		imdebugTexImagef(GL_TEXTURE_2D,texName[0],GL_RGBA,0,NULL);
-//End Debug*/
-/*//Debug
-		glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_EXT, ProjectionsPBO[0] );			// Bind The Buffer
-		glBindTexture(GL_TEXTURE_2D, texName[0]);
-		glTexSubImage2D(GL_TEXTURE_2D, 0,0,0, ResX, ResY, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
-		imdebugTexImagef(GL_TEXTURE_2D,texName[0],GL_RGBA,0,NULL);
-		glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_EXT, ProjectionsPBO[1] );			// Bind The Buffer
-		glBindTexture(GL_TEXTURE_2D, texName[0]);
-		glTexSubImage2D(GL_TEXTURE_2D, 0,0,0, ResX, ResY, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
-		imdebugTexImagef(GL_TEXTURE_2D,texName[0],GL_RGBA,0,NULL);
-//End Debug*/
-					l = (l == 0)? 1:0;
-//					printf("\nRender Transfer:  %d, 0",l);
-					RenderTransfer(l,0);
-//		imdebugTexImagef(GL_TEXTURE_2D,texTransfer[0],GL_RGBA,0,NULL);
-				}
-				glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[l] );			// Bind The Buffer
-				glBufferDataARB( GL_PIXEL_PACK_BUFFER_EXT, ResX*ResY*4*sizeof(float), m_pBlau, GL_STREAM_COPY );
-				glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 );			// Bind The Buffer
-//				printf("\nRender Blau: %d",l);
-/*//Debug
-		glBindBufferARB( GL_PIXEL_UNPACK_BUFFER_EXT, ProjectionsPBO[l] );			// Bind The Buffer
-		glBindTexture(GL_TEXTURE_2D, texName[0]);
-		glTexSubImage2D(GL_TEXTURE_2D, 0,0,0, ResX, ResY, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
-		imdebugTexImagef(GL_TEXTURE_2D,texName[0],GL_RGBA,0,NULL);
-//End Debug*/
-				l = (l = 0)? 1:0;
-//				printf("\nRender Transfer:  %d, 1",l);
-				RenderTransfer(l,1);
-		}
-//		imdebugTexImagef(GL_TEXTURE_2D,texTransfer[0],GL_RGBA,0,NULL);
-		CopyTexture();
-//		imdebugTexImagef(GL_TEXTURE_2D,texCopy[0],GL_RGBA,0,NULL);
-	}
-//	printf("\n");
-	printf("\r100%% Done!!!!");
-
-}
-
-// Function that generates the VBOs with the geometric data of the scene.
-// It also initializes the constant textures used.
-void InitGeometry(void)
-{
-	int i, j;
-	m_pBlau = new float[ResX * ResY * 4];
-	//Initialize a blue buffer.
-	for(i = 0; i<ResX; i++)
-	{
-		for(j = 0; j<ResY; j++)
-		{
-			m_pBlau[4 * (i * ResY + j)] = 0.0;
-			m_pBlau[4 * (i * ResY + j) + 1] = 0.0;
-			m_pBlau[4 * (i * ResY + j) + 2] = 1.0;
-			m_pBlau[4 * (i * ResY + j) + 3] = 1.0;
-		}
-	}
-
-	//Initialize a black buffer
-	for(i = 0; i<Res2X; i++)
-	{
-		for(j = 0; j<Res2Y; j++)
-		{
-			m_pNegre[4*(i*Res2Y+j)] = 0.0;
-			m_pNegre[4*(i*Res2Y+j)+1] = 0.0;
-			m_pNegre[4*(i*Res2Y+j)+2] = 0.0;
-			m_pNegre[4*(i*Res2Y+j)+3] = 0.0;
-		}
-	}
-
-
-	for(i = 0; i<g_pMesh.m_pObject._numGeos;i++)
-	{
-		for(j = 0; j<g_pMesh.m_pObject._geo[i]._numTriSets;j++)
-		{
-			//Aqui creeem els VBOs.
-
-			// Generate And Bind The Index Buffer
-			glGenBuffersARB( 1, (unsigned int *)&g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOIndexs );					// Get A Valid Name
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOIndexs );			// Bind The Buffer
-			// Load The Data
-			glBufferDataARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j]._numTris*3*sizeof(int), g_pMesh.m_pObject._geo[i]._triSet[j]._index, GL_STATIC_DRAW_ARB );
-
-			// Generate And Bind The Vertex Buffer
-			glGenBuffersARB( 1, &g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOVertices );			// Get A Valid Name
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOVertices );			// Bind The Buffer
-			// Load The Data
-			glBufferDataARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j]._numVer * 3 * sizeof(float), g_pMesh.m_pObject._geo[i]._triSet[j]._ver, GL_STATIC_DRAW_ARB );
-
-
-			// Generate And Bind The Normal Buffer
-			glGenBuffersARB( 1, &g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBONormals );			// Get A Valid Name
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBONormals );			// Bind The Buffer
-			// Load The Data
-			glBufferDataARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j]._numVer * 3 * sizeof(float), g_pMesh.m_pObject._geo[i]._triSet[j]._nor, GL_STATIC_DRAW_ARB );
-
-			// Generate And Bind The TexCoord Buffer
-			glGenBuffersARB( 1, &g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOTexCoords );			// Get A Valid Name
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOTexCoords );			// Bind The Buffer
-			// Load The Data
-			glBufferDataARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j]._numVer * 2 * sizeof(float), g_pMesh.m_pObject._geo[i]._triSet[j]._tex, GL_STATIC_DRAW_ARB );
-
-			// Generate And Bind The Color Buffer
-			glGenBuffersARB( 1, &g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOColors );			// Get A Valid Name
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOColors );			// Bind The Buffer
-			// Load The Data
-																										//*12
-			glBufferDataARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j]._numVer * 3 * sizeof(float), g_pMesh.m_pObject._geo[i]._triSet[j]._refl, GL_STATIC_DRAW_ARB );
-		}
-	}
-
-	cout<<"\nPeta aqui\n";
-
-	glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );			// Bind The Buffer
-}
-
-// Functions that initializes the RenderTextures, the shaders and so on...
-void init2(int numargs, char ** argv)
-{	
-
-	g_pMesh.LoadMesh(numargs, argv);
-
-	m_pTextureImage = new float[Res2X*Res2Y*4];// Texture of diferent colors.
-	m_pTextureReflect = new float[Res2X*Res2Y*4]; //Texture of reflectivitat.
-	m_pNegre = new float[Res2X*Res2Y*4];
-
-	//Create Textures.
-	glGenTextures(3, &texName[0]);					// Create The Textures
-
-	InitGeometry();
-
-	//Texture
-	// Binding
-	glBindTexture( GL_TEXTURE_2D, texName[0] );
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, ResX, ResY, 0, GL_RGBA, GL_FLOAT, NULL);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
-	//Texture
-	// Binding
-	glBindTexture( GL_TEXTURE_2D, texName[1] );
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, Res2X, Res2Y, 0, GL_RGBA, GL_FLOAT, NULL);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
-
-	//Texture
-	// Binding
-	glBindTexture( GL_TEXTURE_2D, texName[2] );
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, Res2X, Res2Y, 0, GL_RGBA, GL_FLOAT, m_pTextureReflect);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
-	// Setup GL States
-	glEnable (GL_DEPTH_TEST);									// Enable Depth Testing
-
-	// Setup GL States
-	glEnable (GL_DEPTH_TEST);									// Enable Depth Testing
-
-	//FBOs
-	glGenFramebuffersEXT(1, &fb1);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb1);
-
-	glGenTextures(1,&texReflect[0]);
-
-	glBindTexture( GL_TEXTURE_2D, texReflect[0] );
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, Res2X, Res2Y, 0, GL_RGBA, GL_FLOAT, 0);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texReflect[0],0);
-	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0);
-
-	glGenFramebuffersEXT(1, &fb2);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb2);
-
-	glGenTextures(1,&texProjeccions[0]);
-
-	glBindTexture( GL_TEXTURE_2D, texProjeccions[0] );
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, ResX, ResY, 0, GL_RGBA, GL_FLOAT, 0);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texProjeccions[0],0);
-
-	glGenRenderbuffersEXT(1, &texProjeccions[1]);
-	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, texProjeccions[1]);
-	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, ResX, ResY );
-	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, texProjeccions[1]);
-
-	glGenFramebuffersEXT(1, &fb3);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb3);
-
-	glGenTextures(1,&texTransfer[0]);
-
-	glBindTexture( GL_TEXTURE_2D, texTransfer[0] );
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT16_ATI, Res2X, Res2Y, 0, GL_RGBA, GL_FLOAT, 0);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texTransfer[0],0);
-	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0);
-
-	glClearColor(0.0,0.0,0.0,0.0);
-	glClear(GL_COLOR_BUFFER_BIT);
-
-	glGenFramebuffersEXT(1, &fb4);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb4);
-
-	glGenTextures(1,&texCopy[0]);
-
-	glBindTexture( GL_TEXTURE_2D, texCopy[0] );
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, Res2X, Res2Y, 0, GL_RGBA, GL_FLOAT, 0);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texCopy[0],0);
-	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0);
-
-	//Create PBO
-	glGenBuffersARB( 3, &ProjectionsPBO[0] );
-		glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[0] );			// Bind The Buffer
-		glBufferDataARB( GL_PIXEL_PACK_BUFFER_EXT, ResX*ResY*4*sizeof(float), m_pBlau, GL_STREAM_COPY );
-		glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[1] );			// Bind The Buffer
-		glBufferDataARB( GL_PIXEL_PACK_BUFFER_EXT, ResX*ResY*4*sizeof(float), NULL, GL_STREAM_COPY );
-		//Possible optimitzacio: Treure aquest tercer buffer i copiar el blau al buffer que toqui.!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-//		glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[2] );			// Bind The Buffer
-//		glBufferDataARB( GL_PIXEL_PACK_BUFFER_EXT, ResX*ResY*4*sizeof(float), m_pBlau, GL_STREAM_COPY );
-
-
-
-	glGenBuffersARB( 1, &ObscurancesPBO );
-		glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ObscurancesPBO );			// Bind The Buffer
-		glBufferDataARB( GL_PIXEL_PACK_BUFFER_EXT, Res2X*Res2Y*4*sizeof(float), m_pNegre, GL_STREAM_COPY );
-	glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 );			// Bind The Buffer
-
-
-	//GLSL
-	//Projection Shaders
-	char *vsProjection = NULL, *fsProjection = NULL;
-	
-	vProjection = glCreateShader(GL_VERTEX_SHADER);
-	fProjection = glCreateShader(GL_FRAGMENT_SHADER);
-
-	vsProjection = textFileRead("projection.vert");
-	fsProjection = textFileRead("projection.frag");
-
-	if (!vsProjection) cout<<"\nNo es pot trobar el shader\n";
-	else cout<<"\nOK!\n";
-	
-	const char *vvProjection = vsProjection;
-	const char *ffProjection = fsProjection;
-
-	glShaderSource(vProjection, 1, &vvProjection, NULL);
-	glShaderSource(fProjection, 1, &ffProjection, NULL);
-
-	free(vsProjection); free(fsProjection);	
-
-	glCompileShader(vProjection);
-	glCompileShader(fProjection);	
-
-	pProjection = glCreateProgram();
-	glAttachShader(pProjection, vProjection);
-	glAttachShader(pProjection, fProjection);	
-
-	glLinkProgram(pProjection);
-
-	glUseProgram(pProjection);
-	TexturaDepthProjection = glGetUniformLocation(pProjection, "ztex");
-	SizeProjection = glGetUniformLocation(pProjection, "res");
-	FirstProjection = glGetUniformLocation(pProjection, "first");	
-
-	glUseProgram(0);	
-
-	//Reflect Shaders
-	char *vsReflect = NULL, *fsReflect = NULL;
-	
-	vReflect = glCreateShader(GL_VERTEX_SHADER);
-	fReflect = glCreateShader(GL_FRAGMENT_SHADER);
-
-	vsReflect = textFileRead("reflect.vert");
-	fsReflect = textFileRead("reflect.frag");
-	
-	const char *vvReflect = vsReflect;
-	const char *ffReflect = fsReflect;
-
-	glShaderSource(vReflect, 1, &vvReflect, NULL);
-	glShaderSource(fReflect, 1, &ffReflect, NULL);
-
-	free(vsReflect); free(fsReflect);
-
-	glCompileShader(vReflect);
-	glCompileShader(fReflect);
-
-	pReflect = glCreateProgram();
-	glAttachShader(pReflect, vReflect);
-	glAttachShader(pReflect, fReflect);
-
-	glLinkProgram(pReflect);
-
-//	glUseProgram(pReflect);
-	glUseProgram(0);
-
-	//Texture Copy Shaders
-	char *vsCopy = NULL, *fsCopy = NULL;
-	
-	vCopy = glCreateShader(GL_VERTEX_SHADER);
-	fCopy = glCreateShader(GL_FRAGMENT_SHADER);
-
-	vsCopy = textFileRead("copy.vert");
-	fsCopy = textFileRead("copy.frag");
-	
-	const char *vvCopy = vsCopy;
-	const char *ffCopy = fsCopy;
-
-	glShaderSource(vCopy, 1, &vvCopy, NULL);
-	glShaderSource(fCopy, 1, &ffCopy, NULL);
-
-	free(vsCopy); free(fsCopy);
-
-	glCompileShader(vCopy);
-	glCompileShader(fCopy);
-
-	pCopy = glCreateProgram();
-	glAttachShader(pCopy, vCopy);
-	glAttachShader(pCopy, fCopy);
-
-	glLinkProgram(pCopy);
-
-	glUseProgram(pCopy);
-	TextureCopy = glGetUniformLocation(pCopy, "texture");
-	Texture2Copy = glGetUniformLocation(pCopy, "texture2");
-	glUseProgram(0);
-
-	//Energy Transfer Shaders
-	char *vsTransfer = NULL, *fsTransfer = NULL;
-	
-	vTransfer = glCreateShader(GL_VERTEX_SHADER);
-	fTransfer = glCreateShader(GL_FRAGMENT_SHADER);
-
-	vsTransfer = textFileRead("transfer.vert");
-	fsTransfer = textFileRead("transfer.frag");
-	
-	const char *vvTransfer = vsTransfer;
-	const char *ffTransfer = fsTransfer;
-
-	glShaderSource(vTransfer, 1, &vvTransfer, NULL);
-	glShaderSource(fTransfer, 1, &ffTransfer, NULL);
-
-	free(vsTransfer); free(fsTransfer);
-
-	glCompileShader(vTransfer);
-	glCompileShader(fTransfer);
-
-	pTransfer = glCreateProgram();
-	glAttachShader(pTransfer, vTransfer);
-	glAttachShader(pTransfer, fTransfer);
-
-	glLinkProgram(pTransfer);
-
-	glUseProgram(pTransfer);
-	TexturaReflectTransfer = glGetUniformLocation(pTransfer, "reflectivity");
-	DirectionTransfer = glGetUniformLocation(pTransfer, "direction");
-	DmaxTransfer = glGetUniformLocation(pTransfer, "dmax");
-
-	glUseProgram(0);
-	//Generate the reflectivity texture.
-
-	RenderReflect();
-
-	UpdateTexture(60,2);	
-//	UpdateTexture(1,1);	
-
-}
-
-// Function that interfaces with the VisualCAD.
-int vcObscurerGenerateImage(CMesh &geom, int numargs, char **argv, int quality, int *imgUsize, int *imgVsize, float **imgRgbBuffer)
-{
-	float divisor;
-	int *DadesTemp = new int[4];
-	float	*dadesf=NULL;
-	float aux[4];
-	int		*dadesi=NULL;
-	float a;
-	int qual;
-
-	memset(&aux, 0.0, 4);
-
-	qual = quality;
-
-	if (qual < 1) qual = 1;
-
-	switch (qual)
-	{
-		case 1: *imgVsize = *imgUsize = 256;
-			break;
-		case 2: *imgVsize = *imgUsize = 512;
-			break;
-		case 3: *imgVsize = *imgUsize = 1024;
-			break;
-		case 4: *imgVsize = *imgUsize = 2048;
-			break;
-		default: printf("\nResolution not supported");
-	};
-
-	Res2X = *imgUsize;
-	Res2Y = *imgVsize;
-
-	ResX = Res2X * 2.0; 
-	ResY = Res2Y * 2.0;
-
-	if(ResX == 4096) ResX = 2048;
-	if(ResY == 4096) ResY = 2048;
-
-	printf("\nRes(Plans de projeccio): ResolucioX = %d , ResolucioY = %d", ResX, ResY);
-	printf("\nRes2(Lightmap): ResolucioX = %d , ResolucioY = %d", Res2X, Res2Y);
-	dadesf = new float[Res2X*Res2Y*4];
-	dadesi = new int[Res2X*Res2Y*4];
-
-	init2(numargs, argv);	
- 
-	//->g_pMesh.FreeMem();
-
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb4);
-	glReadPixels(0,0,Res2X,Res2Y,GL_RGBA,GL_FLOAT,dadesf);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-
-	for(int i=0; i<Res2X*Res2Y; i++)
-	{
-		divisor = dadesf[4*i+3];
-		if(divisor>15)
-		{
-			dadesf[4*i] = (dadesf[4*i]/divisor);
-			dadesf[4*i+1] = (dadesf[4*i+1]/divisor);
-			dadesf[4*i+2] = (dadesf[4*i+2]/divisor);
-			dadesf[4*i+3] = 1.0;
-		}
-		else
-		{
-			a=0;
-			aux[0] = 0.0;
-			aux[1] = 0.0;
-			aux[2] = 0.0;
-			aux[3] = 0.0;
-			if(i/Res2X > 0)
-			{
-				if(i/Res2X < Res2Y-1)
-				{
-					if(i%Res2X !=0)
-					{
-						if(dadesf[4*(i-Res2X)-1]>15)	//ul();
-						{
-							aux[0] += (dadesf[4*(i-Res2X)-4]/dadesf[4*(i-Res2X)-1]);
-							aux[1] += (dadesf[4*(i-Res2X)-3]/dadesf[4*(i-Res2X)-1]);
-							aux[2] += (dadesf[4*(i-Res2X)-2]/dadesf[4*(i-Res2X)-1]);
-							aux[3] += 1.0;
-							a =+ 1.0;;
-						}
-						if(dadesf[4*i-1]>15)	//l();
-						{
-							aux[0] += (dadesf[4*i-4]/dadesf[4*i-1]);
-							aux[1] += (dadesf[4*i-3]/dadesf[4*i-1]);
-							aux[2] += (dadesf[4*i-2]/dadesf[4*i-1]);
-							aux[3] += 1.0;
-							a =+ 1.0;;
-						}
-						if(dadesf[4*(i+Res2X)-1]>15)	//dl();
-						{
-							aux[0] += (dadesf[4*(i+Res2X)-4]/dadesf[4*(i+Res2X)-1]);
-							aux[1] += (dadesf[4*(i+Res2X)-3]/dadesf[4*(i+Res2X)-1]);
-							aux[2] += (dadesf[4*(i+Res2X)-2]/dadesf[4*(i+Res2X)-1]);
-							aux[3] += 1.0;
-							a =+ 1.0;;
-						}
-					}
-					if(dadesf[4*(i+Res2X)+3]>15)	//d();
-					{
-						aux[0] += (dadesf[4*(i+Res2X)]/dadesf[4*(i+Res2X)+3]);
-						aux[1] += (dadesf[4*(i+Res2X)+1]/dadesf[4*(i+Res2X)+3]);
-						aux[2] += (dadesf[4*(i+Res2X)+2]/dadesf[4*(i+Res2X)+3]);
-						aux[3] += 1.0;
-						a =+ 1.0;;
-					}
-					if(i%Res2X!=Res2X-1)
-					{
-						if(dadesf[4*(i-Res2X)+7]>15)	//ur();
-						{
-							aux[0] += (dadesf[4*(i-Res2X)+4]/dadesf[4*(i-Res2X)+7]);
-							aux[1] += (dadesf[4*(i-Res2X)+5]/dadesf[4*(i-Res2X)+7]);
-							aux[2] += (dadesf[4*(i-Res2X)+6]/dadesf[4*(i-Res2X)+7]);
-							aux[3] += 1.0;
-							a =+ 1.0;;
-						}
-						if(dadesf[4*i+7]>15)	//r();
-						{
-							aux[0] += (dadesf[4*i+4]/dadesf[4*i+7]);
-							aux[1] += (dadesf[4*i+5]/dadesf[4*i+7]);
-							aux[2] += (dadesf[4*i+6]/dadesf[4*i+7]);
-							aux[3] += 1.0;
-							a =+ 1.0;;
-						}
-						if(dadesf[4*(i+Res2X)+7]>15)	//dr();
-						{
-							aux[0] += (dadesf[4*(i+Res2X)+4]/dadesf[4*(i+Res2X)+7]);
-							aux[1] += (dadesf[4*(i+Res2X)+5]/dadesf[4*(i+Res2X)+7]);
-							aux[2] += (dadesf[4*(i+Res2X)+6]/dadesf[4*(i+Res2X)+7]);
-							aux[3] += 1.0;
-							a =+ 1.0;;
-						}
-					}
-					if(dadesf[4*(i-Res2X)+3]>15)	//u();
-					{
-						aux[0] += (dadesf[4*(i-Res2X)]/dadesf[4*(i-Res2X)+3]);
-						aux[1] += (dadesf[4*(i-Res2X)+1]/dadesf[4*(i-Res2X)+3]);
-						aux[2] += (dadesf[4*(i-Res2X)+2]/dadesf[4*(i-Res2X)+3]);
-						aux[3] += 1.0;
-						a =+ 1.0;;
-					}
-				}
-			}
-			else
-			{
-				if(i%Res2X !=0)
-				{
-					if(dadesf[4*i-1]>15)	//l();
-					{
-						aux[0] += (dadesf[4*i-4]/dadesf[4*i-1]);
-						aux[1] += (dadesf[4*i-3]/dadesf[4*i-1]);
-						aux[2] += (dadesf[4*i-2]/dadesf[4*i-1]);
-						aux[3] += 1.0;
-						a =+ 1.0;;
-					}
-					if(dadesf[4*(i+Res2X)-1]>15)	//dl();
-					{
-						aux[0] += (dadesf[4*(i+Res2X)-4]/dadesf[4*(i+Res2X)-1]);
-						aux[1] += (dadesf[4*(i+Res2X)-3]/dadesf[4*(i+Res2X)-1]);
-						aux[2] += (dadesf[4*(i+Res2X)-2]/dadesf[4*(i+Res2X)-1]);
-						aux[3] = 1.0;
-						a =+ 1.0;;
-					}
-				}
-				if(i%Res2X!=Res2X-1)
-				{
-					if(dadesf[4*i+7]>15)	//r();
-					{
-						aux[0] += (dadesf[4*i+4]/dadesf[4*i+7]);
-						aux[1] += (dadesf[4*i+5]/dadesf[4*i+7]);
-						aux[2] += (dadesf[4*i+6]/dadesf[4*i+7]);
-						aux[3] += 1.0;
-						a =+ 1.0;;
-					}
-					if(dadesf[4*(i+Res2X)+7]>15)	//dr();
-					{
-						aux[0] += (dadesf[4*(i+Res2X)+4]/dadesf[4*(i+Res2X)+7]);
-						aux[1] += (dadesf[4*(i+Res2X)+5]/dadesf[4*(i+Res2X)+7]);
-						aux[2] += (dadesf[4*(i+Res2X)+6]/dadesf[4*(i+Res2X)+7]);
-						aux[3] += 1.0;
-						a =+ 1.0;;
-					}
-				}
-				if(dadesf[4*(i+Res2X)+3]>15)	//d();
-				{
-						aux[0] += (dadesf[4*(i+Res2X)]/dadesf[4*(i+Res2X)+3]);
-						aux[1] += (dadesf[4*(i+Res2X)+1]/dadesf[4*(i+Res2X)+3]);
-						aux[2] += (dadesf[4*(i+Res2X)+2]/dadesf[4*(i+Res2X)+3]);
-						aux[3] += 1.0;
-						a =+ 1.0;;
-				}
-			}
-			if(a > 0.0)
-			{
-				dadesf[4*i] = aux[0]/aux[3];
-				dadesf[4*i+1] = aux[1]/aux[3];
-				dadesf[4*i+2] = aux[2]/aux[3];
-				dadesf[4*i+3] = 1.0;
-			}
-			else
-			{
-				dadesf[4*i] = 0.0;
-				dadesf[4*i+1] = 0.0;
-				dadesf[4*i+2] = 0.0;
-				dadesf[4*i+3] = 0.0;
-			}
-		}
-		dadesi[4*i] = (int)(255.0*dadesf[4*i]);
-		dadesi[4*i+1] = (int)(255.0*dadesf[4*i+1]);
-		dadesi[4*i+2] = (int)(255.0*dadesf[4*i+2]);
-		dadesi[4*i+3] = (int)(255.0*dadesf[4*i+3]);
-
-	}	
-
-	geom = g_pMesh;
-
-	imdebug("rgba b=32f w=%d h=%d %p", Res2X, Res2Y, dadesf);
-
-	*imgRgbBuffer = dadesf;
-
-	return 0;
-
-}
Index: P/trunk/Lib/Illum/GPUObscurancesGT/src/vcObscuranceMap2.cpp
===================================================================
--- /GTP/trunk/Lib/Illum/GPUObscurancesGT/src/vcObscuranceMap2.cpp	(revision 930)
+++ 	(revision )
@@ -1,1016 +1,0 @@
-//========================================
-//	Class to interface the VisualCAD specifications.
-//	Nicolau Sunyer & Sergi Funtané (10/13/2005).
-//	Universitat de Girona.
-//========================================
-
-#pragma warning(disable:4244)
-// Includes
-//->#define GLEW_STATIC 1
-#include "glew.h"
-#include <glut.h>
-#include <iostream>
-#include "textfile.h"
-
-// Includes
-#include "CMesh.h"
-#include "vcObscuranceMap.h"
-#include <imdebug.h>
-#include <imdebuggl.h>
-
-#ifndef M_PI
-	#define M_PI        3.14159265358979323846
-#endif
-
-// DepthPeeling Layers.
-#define MAX_LAYERS	12
-
-// To use Offsets in the PBOs.
-#define BUFFER_OFFSET(i) ((char *)NULL + (i))
-
-//GLSL
-// Handlers
-GLuint vProjection,fProjection,pProjection;
-GLuint vReflect, fReflect, pReflect;
-GLuint vCopy, fCopy, pCopy;
-GLuint vTransfer, fTransfer, pTransfer;
-
-//Uniform Parameters
-//Projection Step
-GLint TexturaDepthProjection;
-GLint SizeProjection;
-GLint FirstProjection;
-
-//Reflectivity texture generation Step.
-
-//Texture Copy Step.
-GLint TextureCopy;
-GLint Texture2Copy;
-
-//Energy Transfer Step.
-GLint TexturaReflectTransfer;
-GLint DirectionTransfer;
-GLint DmaxTransfer;
-
-// Global variables
-CVert Vertex, Direccio, Increment, Primer, Ultim, Origin;	
-
-static GLuint texName[2];
-
-static int ResX;		//Resolution
-static int ResY;
-static int Res2X;		//Resolution
-static int Res2Y;		//Resolution
-
-static GLuint texProjeccions[2]; //Texture name
-static GLuint texTransfer[1];
-static GLuint texReflect[1];
-static GLuint texCopy[1];
-static GLuint fb1; // Framebuffer Reflectivity
-static GLuint fb2; // Framebuffer Projeccions
-static GLuint fb3; // Framebuffer Transfer
-static GLuint fb4; // Framebuffer Copy
-
-GLenum glerror;
-
-GLfloat *m_pTextureImage;// Texture of diferent colors.
-GLfloat *m_pTextureReflect; //Texture of reflectivitat.
-GLfloat *m_pBlau;
-GLfloat *m_pNegre;
-int obs_global_cancelar;
-
-CMesh	g_pMesh;						// Mesh Data
-static CSphere Esfera;
-
-static GLuint	ProjectionsPBO[MAX_LAYERS+2];	// PBOs to store the projections.
-static GLuint	ObscurancesPBO;					// PBOs to store the projections.
-static GLuint	ztex;								//Texture with the depth.
-
-// Function to use when the window is resized
-void changeSize(int w, int h) 
-{
-
-	if(h == 0)
-		h = 1;
-
-	float ratio = 1.0 * (float)w / (float)h;
-
-	//Camera Set up
-	glMatrixMode(GL_PROJECTION);
-	glLoadIdentity();
-	gluOrtho2D(-w,w,-h,h);
-
-	glMatrixMode(GL_MODELVIEW);
-	glLoadIdentity();
-
-	glViewport(0, 0, w, h);
-
-}
-
-
-// Returns a random point in the surface of the sphere
-CVert ranpoint(float r, CVert c)
-{
-	double ale1, ale2;
-	CVert p;
-	float alfa,beta;
-
-	ale1= (float)rand()/(float)RAND_MAX; 
-	ale2= (float)rand()/(float)RAND_MAX;
- 
-    alfa=1.0-2.0*ale1;	/* real between -1 and 1 */
-    alfa=acos(alfa);	/* angle between 0 and PI */
-
-    beta=2*M_PI*ale2;	/* angle between 0 and 2*PI */
-   
-    p.x=c.x+r*sin(alfa)*cos(beta);
-    p.y=c.y+r*sin(alfa)*sin(beta);
-    p.z=c.z+r*cos(alfa);
-   
-    return p;
-}
-
-// Function to find a point in the sphere in the direction that goes from the point in the surface of the sphere
-// to the center of the sphere. First it gets the random point in the surface.
-void BuscarDireccio()
-{
-	Esfera.center.x = 0.0;
-	Esfera.center.y = 0.0;
-	Esfera.center.z = 0.0;
-	Esfera.radius = sqrt(12.0)/2.0;
-
-	Primer = ranpoint(Esfera.radius,Esfera.center);
-	Vertex.x = Primer.x + (Esfera.center.x-Primer.x) * ((float)rand()/(float)RAND_MAX)*2.0;
-	Vertex.y = Primer.y + (Esfera.center.y-Primer.y) * ((float)rand()/(float)RAND_MAX)*2.0;
-	Vertex.z = Primer.z + (Esfera.center.z-Primer.z) * ((float)rand()/(float)RAND_MAX)*2.0;
-}
-
-// Function that renders the depth peeling geometry planes and stores them in PBOs.
-void RenderProjeccions(int buffer, int first)
-{
-	int i, j, e;
-
-		glUseProgram(pProjection);
-		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb2);
-
-		changeSize(ResX, ResY);
-		glEnable (GL_DEPTH_TEST);									// Enable Depth Testing
-		glDepthFunc(GL_LESS);
-
-		glDisable(GL_CULL_FACE);
-
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		glOrtho(-Esfera.radius,Esfera.radius,-Esfera.radius,Esfera.radius,0,Esfera.radius * 2.0);	
-
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-		gluLookAt(Primer.x,Primer.y,Primer.z, 
-			      Esfera.center.x,Esfera.center.y,Esfera.center.z,
-				  0.0f,1.0f,0.0f);
-
-		glViewport(0,0,ResX,ResY);
-
-		glUniform1f(SizeProjection, (float)ResX);
-		glUniform1f(FirstProjection, (float)first);
-
-		int other = ((buffer == 1)? 0:1);
-		if(first == 0)
-		{
-			glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[other] );			// Bind The Buffer
-			glBindTexture(GL_TEXTURE_2D,texName[0]);
-			glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, ResX, ResY);
-			glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 );			// Bind The Buffer
-			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
-			glActiveTexture(GL_TEXTURE0);
-			glBindTexture(GL_TEXTURE_2D, texName[0]);
-			glUniform1i(TexturaDepthProjection, 0);
-		}
-
-		// Enable Pointers
-		glEnableClientState( GL_VERTEX_ARRAY );						// Enable Vertex Arrays
-		glEnableClientState( GL_TEXTURE_COORD_ARRAY );				// Enable Texture Coord Arrays
-		glEnableClientState( GL_NORMAL_ARRAY );				// Enable Texture Coord Arrays
-
-		for(i=0; i<g_pMesh.m_pObject._numGeos;i++)
-		{
-			for(j=0; j<g_pMesh.m_pObject._geo[i]._numTriSets;j++)
-			{
-				// Set Pointers To Our Data
-				glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOVertices );
-				glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL );		// Set The Vertex Pointer To The Vertex Buffer
-				glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOTexCoords );
-				glTexCoordPointer( 2, GL_FLOAT, 0, (char *) NULL );		// Set The TexCoord Pointer To The TexCoord Buffer
-				glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBONormals );
-				glNormalPointer( GL_FLOAT, 0, (char *) NULL );		// Set The TexCoord Pointer To The TexCoord Buffer
-				glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOIndexs );
-
-				// Render
-				glDrawElements( GL_TRIANGLES, g_pMesh.m_pObject._geo[i]._triSet[j]._numTris*3,GL_UNSIGNED_INT,BUFFER_OFFSET(0) );	// Draw All Of The Quads At Once
-
-			}
-		}
-
-		glDisableClientState( GL_VERTEX_ARRAY );					// Disable Vertex Arrays
-		glDisableClientState( GL_TEXTURE_COORD_ARRAY );				// Disable Texture Coord Arrays
-		glDisableClientState( GL_NORMAL_ARRAY );				// Disable Texture Coord Arrays
-
-		//Copy the color buffer to PBO.
-		glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[buffer] );			// Bind The Buffer
-		glReadPixels(0, 0, ResX, ResY, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
-		glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0);
-
-		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-		glUseProgram(0);
-}
-
-// Function that calculates the lightmap using the neighbouring projections.
-void RenderTransfer(int buffer, int first)
-{
-	glUseProgram(pTransfer);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb3);
-
-		int other = ((buffer == 1)? 0:1);
-
-		glBlendFunc(GL_ONE, GL_ONE);
-
-		glEnable(GL_BLEND);
-
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		gluOrtho2D(-1,1,-1,1);
-
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-		glPointSize(1.0);
-
-		glViewport(0, 0, Res2X, Res2Y);
-
-		glUniform1f(DmaxTransfer, (GLfloat)0.3);
-		glActiveTexture(GL_TEXTURE0);
-		glBindTexture(GL_TEXTURE_2D, texReflect[0]);
-		glUniform1i(TexturaReflectTransfer, 0);
-		
-		if(first == 1)
-		{
-			//First Render
-			glUniform1f(DirectionTransfer, (float)buffer);
-			glEnableClientState( GL_VERTEX_ARRAY );						// Enable Vertex Arrays
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[buffer] );
-			glVertexPointer( 4, GL_FLOAT, 0, (char *) NULL );		// Set The Vertex Pointer To The Vertex Buffer
-
-			glEnableClientState( GL_TEXTURE_COORD_ARRAY );				// Enable Texture Coord Arrays
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[other] );
-			glTexCoordPointer( 4, GL_FLOAT, 0, (char *) NULL );		// Set The TexCoord Pointer To The TexCoord Buffer
-
-			glDrawArrays(GL_POINTS, 0, ResX*ResY );
-		}
-		else
-		{
-			glUniform1f(DirectionTransfer, 0.0);
-
-			glEnableClientState( GL_VERTEX_ARRAY );						// Enable Vertex Arrays
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[buffer] );
-			glVertexPointer( 4, GL_FLOAT, 0, (char *) NULL );		// Set The Vertex Pointer To The Vertex Buffer
-
-			glEnableClientState( GL_TEXTURE_COORD_ARRAY );				// Enable Texture Coord Arrays
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[other] );
-			glTexCoordPointer( 4, GL_FLOAT, 0, (char *) NULL );		// Set The TexCoord Pointer To The TexCoord Buffer
-
-			glDrawArrays(GL_POINTS, 0, ResX*ResY );
-
-			glUniform1f(DirectionTransfer, 1.0);
-
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[other] );
-			glVertexPointer( 4, GL_FLOAT, 0, (char *) NULL );		// Set The Vertex Pointer To The Vertex Buffer
-
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, ProjectionsPBO[buffer] );
-			glTexCoordPointer( 4, GL_FLOAT, 0, (char *) NULL );		// Set The TexCoord Pointer To The TexCoord Buffer
-
-			glDrawArrays(GL_POINTS, 0, ResX*ResY );
-		}
-
-		glDisableClientState( GL_VERTEX_ARRAY );					// Disable Vertex Arrays
-		glDisableClientState( GL_TEXTURE_COORD_ARRAY );				// Disable Texture Coord Arrays
-
-		glDisable(GL_BLEND);
-	glUseProgram(0);
-
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-
-}
-
-// Function that copies the 16-bit fp RGBA buffer of the lightmap to a 32-bit RGBA fb buffer.
-void CopyTexture(void)
-{
-	glUseProgram(pCopy);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb4);
-	void *texturePBO;
-	
-		glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ObscurancesPBO );			// Bind The Buffer
-		texturePBO = glMapBuffer(GL_PIXEL_PACK_BUFFER_EXT, GL_READ_ONLY);
-		glBindTexture(GL_TEXTURE_2D,texName[1]);
-		glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, Res2X, Res2Y, GL_RGBA, GL_FLOAT, texturePBO);
-		glUnmapBuffer(GL_PIXEL_PACK_BUFFER_ARB);
-		glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 );			// Bind The Buffer
-
-		glEnable(GL_CULL_FACE);
-
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		gluOrtho2D(-Res2X,Res2Y,-Res2X,Res2Y);
-
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-
-		glViewport(0, 0, Res2X, Res2Y);
-
-		glActiveTexture(GL_TEXTURE0);
-		glBindTexture(GL_TEXTURE_2D, texTransfer[0]);
-		glUniform1i(TextureCopy, 0);
-		glActiveTexture(GL_TEXTURE1);
-		glBindTexture(GL_TEXTURE_2D, texName[1]);
-		glUniform1i(Texture2Copy, 1);
-		glActiveTexture(GL_TEXTURE0);
-
-
-		//Draw the geometry. 
-		glBegin(GL_QUADS);
-		{
-			glTexCoord2f(0,      0);       glVertex3f(-Res2X, -Res2Y, -0.5f);
-			glTexCoord2f(1,0);       glVertex3f(Res2X, -Res2Y, -0.5f);
-			glTexCoord2f(1,1); glVertex3f(Res2X, Res2Y, -0.5f);
-			glTexCoord2f(0,      1); glVertex3f(-Res2X, Res2Y, -0.5f);
-		}
-		glEnd();
-
-		//Copy Buffer to PBO.
-		glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT,ObscurancesPBO );			// Bind The Buffer
-		glReadPixels(0, 0, Res2X, Res2Y, GL_RGBA, GL_FLOAT, BUFFER_OFFSET(0));
-		glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, 0);
-
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb3);
-	glClearColor(0.0,0.0,0.0,0.0);
-	glClear(GL_COLOR_BUFFER_BIT);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-	glUseProgram(0);
-}
-
-// Function that calculates the reflectivity map from the scene data.
-void RenderReflect(void)
-{
-	int i, j;
-	glUseProgram(pReflect);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb1);
-
-		glClearColor(0.0,0.0,0.0,0.0);
-		glClear(GL_COLOR_BUFFER_BIT);
-
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		gluOrtho2D(0,1,0,1);
-
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-
-		glViewport(0, 0, Res2X, Res2Y);
-
-		// Enable Pointers
-		glEnableClientState( GL_VERTEX_ARRAY );						// Enable Vertex Arrays
-		glEnableClientState( GL_COLOR_ARRAY );				// Enable Texture Coord Arrays
-
-		for(i=0; i<g_pMesh.m_pObject._numGeos;i++)
-		{
-			for(j=0; j<g_pMesh.m_pObject._geo[i]._numTriSets;j++)
-			{
-				// Set Pointers To Our Data
-				glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOTexCoords );
-				glVertexPointer( 2, GL_FLOAT, 0, (char *) NULL );		// Set The Vertex Pointer To The Vertex Buffer
-				glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOColors );
-				glColorPointer( 3, GL_FLOAT, 0, (char *) NULL );		// Set The TexCoord Pointer To The TexCoord Buffer
-				glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOIndexs );
-
-				// Render
-				glDrawElements( GL_TRIANGLES, g_pMesh.m_pObject._geo[i]._triSet[j]._numTris*3,GL_UNSIGNED_INT,BUFFER_OFFSET(0) );	// Draw All Of The Quads At Once
-
-			}
-		}
-
-		glDisableClientState( GL_VERTEX_ARRAY );			// Enable Vertex Arrays
-		glDisableClientState( GL_COLOR_ARRAY );				// Enable Texture Coord Arrays
-
-	glUseProgram(0);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-}
-
-// Function that updates the lightmap. 
-// The number of directions used to calculate the lightmap is iterations * steps
-void UpdateTexture(int iterations, int steps)
-{
-	printf("\nIteracions: %d => Steps: %d\n", iterations, steps);
-	for(int i = 0; i < steps; i++)
-	{
-		for(int j = 0; j < iterations; j++)
-		{
-			printf("\rProgress: %d%%",i*100/steps + j*100/(steps*iterations));
-			BuscarDireccio();				// Find a random direction
-				glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb2);
-					glClearColor(0.0,0.0,1.0,1.0);
-					glClearDepth(1.0);
-					glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-				glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-				glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[0] );			// Bind The Buffer
-				glBufferDataARB( GL_PIXEL_PACK_BUFFER_EXT, ResX*ResY*4*sizeof(float), m_pBlau, GL_STREAM_COPY );
-				glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 );
-				RenderProjeccions(1,1);
-				RenderTransfer(1, 1);
-				int l = 0;
-				for(int k=1; k < MAX_LAYERS; k++)
-				{
-					RenderProjeccions(l,0);
-					l = (l == 0)? 1:0;
-					RenderTransfer(l,0);
-				}
-				glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[l] );			// Bind The Buffer
-				glBufferDataARB( GL_PIXEL_PACK_BUFFER_EXT, ResX*ResY*4*sizeof(float), m_pBlau, GL_STREAM_COPY );
-				glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 );			
-				l = (l = 0)? 1:0;
-				RenderTransfer(l,1);
-		}
-		CopyTexture();
-	}
-	printf("\r100%% Done!!!!");
-
-}
-
-// Function that generates the VBOs with the geometric data of the scene.
-// It also initializes the constant textures used.
-void InitGeometry(void)
-{
-	int i, j;
-	m_pBlau = new float[ResX * ResY * 4];
-	//Initialize a blue buffer.
-	for(i = 0; i<ResX; i++)
-	{
-		for(j = 0; j<ResY; j++)
-		{
-			m_pBlau[4 * (i * ResY + j)] = 0.0;
-			m_pBlau[4 * (i * ResY + j) + 1] = 0.0;
-			m_pBlau[4 * (i * ResY + j) + 2] = 1.0;
-			m_pBlau[4 * (i * ResY + j) + 3] = 1.0;
-		}
-	}
-
-	//Initialize a black buffer
-	for(i = 0; i<Res2X; i++)
-	{
-		for(j = 0; j<Res2Y; j++)
-		{
-			m_pNegre[4*(i*Res2Y+j)] = 0.0;
-			m_pNegre[4*(i*Res2Y+j)+1] = 0.0;
-			m_pNegre[4*(i*Res2Y+j)+2] = 0.0;
-			m_pNegre[4*(i*Res2Y+j)+3] = 0.0;
-		}
-	}
-
-
-	for(i = 0; i<g_pMesh.m_pObject._numGeos;i++)
-	{
-		for(j = 0; j<g_pMesh.m_pObject._geo[i]._numTriSets;j++)
-		{
-			//Aqui creeem els VBOs.
-
-			g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOIndexs = 0;
-			// Generate And Bind The Index Buffer
-			glGenBuffersARB( 1,  (unsigned int *)&g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOIndexs );					// Get A Valid Name
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOIndexs );			// Bind The Buffer
-			// Load The Data
-			glBufferDataARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j]._numTris * 3 * sizeof(int), g_pMesh.m_pObject._geo[i]._triSet[j]._index, GL_STATIC_DRAW_ARB );
-
-			g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOVertices = 0;
-			// Generate And Bind The Vertex Buffer
-			glGenBuffersARB( 1, &g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOVertices );			// Get A Valid Name
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOVertices );			// Bind The Buffer
-			// Load The Data
-			glBufferDataARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j]._numVer * 3 * sizeof(float), g_pMesh.m_pObject._geo[i]._triSet[j]._ver, GL_STATIC_DRAW_ARB );
-
-			g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBONormals = 0;
-			// Generate And Bind The Normal Buffer
-			glGenBuffersARB( 1, &g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBONormals );			// Get A Valid Name
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBONormals );			// Bind The Buffer
-			// Load The Data
-			glBufferDataARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j]._numVer * 3 * sizeof(float), g_pMesh.m_pObject._geo[i]._triSet[j]._nor, GL_STATIC_DRAW_ARB );
-
-			g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOTexCoords = 0;
-			// Generate And Bind The TexCoord Buffer
-			glGenBuffersARB( 1, &g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOTexCoords );			// Get A Valid Name
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOTexCoords );			// Bind The Buffer
-			// Load The Data
-			glBufferDataARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j]._numVer * 2 * sizeof(float), g_pMesh.m_pObject._geo[i]._triSet[j]._tex, GL_STATIC_DRAW_ARB );
-
-			g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOColors = 0;
-			// Generate And Bind The Color Buffer
-			glGenBuffersARB( 1, &g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOColors );			// Get A Valid Name
-			glBindBufferARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j].m_nVBOColors );			// Bind The Buffer
-			// Load The Data
-																										//*12
-			glBufferDataARB( GL_ARRAY_BUFFER_ARB, g_pMesh.m_pObject._geo[i]._triSet[j]._numVer * 3 * sizeof(float), g_pMesh.m_pObject._geo[i]._triSet[j]._refl, GL_STATIC_DRAW_ARB );
-		}
-	}	
-	glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 );			// Bind The Buffer
-}
-
-// Functions that initializes the RenderTextures, the shaders and so on...
-void init2(char *argv)
-{	
-
-	g_pMesh.LoadMesh(argv);
-
-	m_pTextureImage = new float[Res2X*Res2Y*4];// Texture of diferent colors.
-	m_pTextureReflect = new float[Res2X*Res2Y*4]; //Texture of reflectivitat.
-	m_pNegre = new float[Res2X*Res2Y*4];
-
-	//Create Textures.
-	glGenTextures(2, &texName[0]);					// Create The Textures
-
-	InitGeometry();
-
-	//Texture
-	// Binding
-	glBindTexture( GL_TEXTURE_2D, texName[0] );
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, ResX, ResY, 0, GL_RGBA, GL_FLOAT, NULL);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
-	//Texture
-	// Binding
-	glBindTexture( GL_TEXTURE_2D, texName[1] );
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, Res2X, Res2Y, 0, GL_RGBA, GL_FLOAT, NULL);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
-	// Setup GL States
-	glEnable (GL_DEPTH_TEST);									// Enable Depth Testing
-
-	// Setup GL States
-	glEnable (GL_DEPTH_TEST);									// Enable Depth Testing
-
-	//FBOs
-	glGenFramebuffersEXT(1, &fb1);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb1);
-
-	glGenTextures(1,&texReflect[0]);
-
-	glBindTexture( GL_TEXTURE_2D, texReflect[0] );
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT16_ATI, Res2X, Res2Y, 0, GL_RGBA, GL_FLOAT, 0);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texReflect[0],0);
-	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0);
-
-	glGenFramebuffersEXT(1, &fb2);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb2);
-
-	glGenTextures(1,&texProjeccions[0]);
-
-	glBindTexture( GL_TEXTURE_2D, texProjeccions[0] );
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, ResX, ResY, 0, GL_RGBA, GL_FLOAT, 0);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texProjeccions[0],0);
-
-	glGenRenderbuffersEXT(1, &texProjeccions[1]);
-	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, texProjeccions[1]);
-	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, ResX, ResY );
-	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, texProjeccions[1]);
-
-	glGenFramebuffersEXT(1, &fb3);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb3);
-
-	glGenTextures(1,&texTransfer[0]);
-
-	glBindTexture( GL_TEXTURE_2D, texTransfer[0] );
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT16_ATI, Res2X, Res2Y, 0, GL_RGBA, GL_FLOAT, 0);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texTransfer[0],0);
-	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0);
-
-	glClearColor(0.0,0.0,0.0,0.0);
-	glClear(GL_COLOR_BUFFER_BIT);
-
-	glGenFramebuffersEXT(1, &fb4);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb4);
-
-	glGenTextures(1,&texCopy[0]);
-
-	glBindTexture( GL_TEXTURE_2D, texCopy[0] );
-	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA_FLOAT32_ATI, Res2X, Res2Y, 0, GL_RGBA, GL_FLOAT, 0);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
-	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texCopy[0],0);
-	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0);
-
-	//Create PBO
-	glGenBuffersARB( 2, &ProjectionsPBO[0] );
-		glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[0] );			// Bind The Buffer
-		glBufferDataARB( GL_PIXEL_PACK_BUFFER_EXT, ResX*ResY*4*sizeof(float), m_pBlau, GL_STREAM_COPY );
-		glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ProjectionsPBO[1] );			// Bind The Buffer
-		glBufferDataARB( GL_PIXEL_PACK_BUFFER_EXT, ResX*ResY*4*sizeof(float), NULL, GL_STREAM_COPY );
-
-
-		glGenBuffersARB( 1, &ObscurancesPBO );
-		glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, ObscurancesPBO );			// Bind The Buffer
-		glBufferDataARB( GL_PIXEL_PACK_BUFFER_EXT, Res2X*Res2Y*4*sizeof(float), m_pNegre, GL_STREAM_COPY );
-	glBindBufferARB( GL_PIXEL_PACK_BUFFER_EXT, 0 );			// Bind The Buffer
-
-	//GLSL
-	//Projection Shaders
-	char *vsProjection = NULL, *fsProjection = NULL;
-	
-	vProjection = glCreateShader(GL_VERTEX_SHADER);
-	fProjection = glCreateShader(GL_FRAGMENT_SHADER);
-
-	vsProjection = textFileRead("projection.vert");
-	fsProjection = textFileRead("projection.frag");
-	
-	const char *vvProjection = vsProjection;
-	const char *ffProjection = fsProjection;
-
-	glShaderSource(vProjection, 1, &vvProjection, NULL);
-	glShaderSource(fProjection, 1, &ffProjection, NULL);
-
-	free(vsProjection); free(fsProjection);
-
-	glCompileShader(vProjection);
-	glCompileShader(fProjection);
-
-	pProjection = glCreateProgram();
-	glAttachShader(pProjection, vProjection);
-	glAttachShader(pProjection, fProjection);
-
-	glLinkProgram(pProjection);
-
-	glUseProgram(pProjection);
-	TexturaDepthProjection = glGetUniformLocation(pProjection, "ztex");
-	SizeProjection = glGetUniformLocation(pProjection, "res");
-	FirstProjection = glGetUniformLocation(pProjection, "first");
-
-	glUseProgram(0);
-
-
-	//Reflect Shaders
-	char *vsReflect = NULL, *fsReflect = NULL;
-	
-	vReflect = glCreateShader(GL_VERTEX_SHADER);
-	fReflect = glCreateShader(GL_FRAGMENT_SHADER);
-
-	vsReflect = textFileRead("reflect.vert");
-	fsReflect = textFileRead("reflect.frag");
-	
-	const char *vvReflect = vsReflect;
-	const char *ffReflect = fsReflect;
-
-	glShaderSource(vReflect, 1, &vvReflect, NULL);
-	glShaderSource(fReflect, 1, &ffReflect, NULL);
-
-	free(vsReflect); free(fsReflect);
-
-	glCompileShader(vReflect);
-	glCompileShader(fReflect);
-
-	pReflect = glCreateProgram();
-	glAttachShader(pReflect, vReflect);
-	glAttachShader(pReflect, fReflect);
-
-	glLinkProgram(pReflect);
-
-//	glUseProgram(pReflect);
-	glUseProgram(0);
-
-	//Texture Copy Shaders
-	char *vsCopy = NULL, *fsCopy = NULL;
-	
-	vCopy = glCreateShader(GL_VERTEX_SHADER);
-	fCopy = glCreateShader(GL_FRAGMENT_SHADER);
-
-	vsCopy = textFileRead("copy.vert");
-	fsCopy = textFileRead("copy.frag");
-	
-	const char *vvCopy = vsCopy;
-	const char *ffCopy = fsCopy;
-
-	glShaderSource(vCopy, 1, &vvCopy, NULL);
-	glShaderSource(fCopy, 1, &ffCopy, NULL);
-
-	free(vsCopy); free(fsCopy);
-
-	glCompileShader(vCopy);
-	glCompileShader(fCopy);
-
-	pCopy = glCreateProgram();
-	glAttachShader(pCopy, vCopy);
-	glAttachShader(pCopy, fCopy);
-
-	glLinkProgram(pCopy);
-
-	glUseProgram(pCopy);
-	TextureCopy = glGetUniformLocation(pCopy, "texture");
-	Texture2Copy = glGetUniformLocation(pCopy, "texture2");
-	glUseProgram(0);
-
-	//Energy Transfer Shaders
-	char *vsTransfer = NULL, *fsTransfer = NULL;
-	
-	vTransfer = glCreateShader(GL_VERTEX_SHADER);
-	fTransfer = glCreateShader(GL_FRAGMENT_SHADER);
-
-	vsTransfer = textFileRead("transfer.vert");
-	fsTransfer = textFileRead("transfer.frag");
-	
-	const char *vvTransfer = vsTransfer;
-	const char *ffTransfer = fsTransfer;
-
-	glShaderSource(vTransfer, 1, &vvTransfer, NULL);
-	glShaderSource(fTransfer, 1, &ffTransfer, NULL);
-
-	free(vsTransfer); free(fsTransfer);
-
-	glCompileShader(vTransfer);
-	glCompileShader(fTransfer);
-
-	pTransfer = glCreateProgram();
-	glAttachShader(pTransfer, vTransfer);
-	glAttachShader(pTransfer, fTransfer);
-
-	glLinkProgram(pTransfer);
-
-	glUseProgram(pTransfer);
-	TexturaReflectTransfer = glGetUniformLocation(pTransfer, "reflectivity");
-	DirectionTransfer = glGetUniformLocation(pTransfer, "direction");
-	DmaxTransfer = glGetUniformLocation(pTransfer, "dmax");
-
-	glUseProgram(0);
-	//Generate the reflectivity texture.
-
-	RenderReflect();
-
-	UpdateTexture(60,3);	
-//	UpdateTexture(1,1);	
-
-}
-
-// Function that interfaces with the VisualCAD.
-int vcObscurerGenerateImage(CMesh &geom, char *argv, int quality, int *imgUsize, int *imgVsize, float **imgRgbBuffer)
-{
-	float divisor;
-	int *DadesTemp = new int[4];
-	float	*dadesf=NULL;
-	float aux[4];
-	int		*dadesi=NULL;
-	float a;
-	int qual;
-
-	glutCreateWindow("T");
-
-	FILE *file = NULL;
-
-	file = fopen("L:\\Ogre3D\\ogrenew\\Tools\\GPUObscurancesOgre3D1\\bin\\Debug\\tmp.txt", "w");
-
-	glerror = glewInit();
-
-	if (glerror != GLEW_OK) fprintf(file, "\nError initializing glew library, %s", glewGetErrorString(glerror));
-	else fprintf(file, "\nTot Correcte!\n");
-
-	fclose(file);
-
-	memset(&aux, 0.0, 4);
-
-	qual = quality;
-
-	if (qual < 1) qual = 1;
-
-	switch (qual)
-	{
-		case 1: *imgVsize = *imgUsize = 256;
-			break;
-		case 2: *imgVsize = *imgUsize = 512;
-			break;
-		case 3: *imgVsize = *imgUsize = 1024;
-			break;
-		case 4: *imgVsize = *imgUsize = 2048;
-			break;
-		default: printf("\nResolution not supported");
-	};
-
-	Res2X = *imgUsize;
-	Res2Y = *imgVsize;
-
-	ResX = Res2X * 2.0; 
-	ResY = Res2Y * 2.0;
-
-	if(ResX == 4096) ResX = 2048;
-	if(ResY == 4096) ResY = 2048;
-
-	printf("\nRes(Plans de projeccio): ResolucioX = %d , ResolucioY = %d", ResX, ResY);
-	printf("\nRes2(Lightmap): ResolucioX = %d , ResolucioY = %d", Res2X, Res2Y);
-	dadesf = new float[Res2X*Res2Y*4];
-	dadesi = new int[Res2X*Res2Y*4];
-
-
-	init2(argv);
- 
-	//g_pMesh.FreeMem();
-
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb4);
-	glReadPixels(0,0,Res2X,Res2Y,GL_RGBA,GL_FLOAT,dadesf);
-	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-
-	for(int i=0; i<Res2X*Res2Y; i++)
-	{
-		divisor = dadesf[4*i+3];
-		if(divisor>15)
-		{
-			dadesf[4*i] = (dadesf[4*i]/divisor);
-			dadesf[4*i+1] = (dadesf[4*i+1]/divisor);
-			dadesf[4*i+2] = (dadesf[4*i+2]/divisor);
-			dadesf[4*i+3] = 1.0;
-		}
-		else
-		{
-			a=0;
-			aux[0] = 0.0;
-			aux[1] = 0.0;
-			aux[2] = 0.0;
-			aux[3] = 0.0;
-			if(i/Res2X > 0)
-			{
-				if(i/Res2X < Res2Y-1)
-				{
-					if(i%Res2X !=0)
-					{
-						if(dadesf[4*(i-Res2X)-1]>15)	//ul();
-						{
-							aux[0] += (dadesf[4*(i-Res2X)-4]/dadesf[4*(i-Res2X)-1]);
-							aux[1] += (dadesf[4*(i-Res2X)-3]/dadesf[4*(i-Res2X)-1]);
-							aux[2] += (dadesf[4*(i-Res2X)-2]/dadesf[4*(i-Res2X)-1]);
-							aux[3] += 1.0;
-							a =+ 1.0;;
-						}
-						if(dadesf[4*i-1]>15)	//l();
-						{
-							aux[0] += (dadesf[4*i-4]/dadesf[4*i-1]);
-							aux[1] += (dadesf[4*i-3]/dadesf[4*i-1]);
-							aux[2] += (dadesf[4*i-2]/dadesf[4*i-1]);
-							aux[3] += 1.0;
-							a =+ 1.0;;
-						}
-						if(dadesf[4*(i+Res2X)-1]>15)	//dl();
-						{
-							aux[0] += (dadesf[4*(i+Res2X)-4]/dadesf[4*(i+Res2X)-1]);
-							aux[1] += (dadesf[4*(i+Res2X)-3]/dadesf[4*(i+Res2X)-1]);
-							aux[2] += (dadesf[4*(i+Res2X)-2]/dadesf[4*(i+Res2X)-1]);
-							aux[3] += 1.0;
-							a =+ 1.0;;
-						}
-					}
-					if(dadesf[4*(i+Res2X)+3]>15)	//d();
-					{
-						aux[0] += (dadesf[4*(i+Res2X)]/dadesf[4*(i+Res2X)+3]);
-						aux[1] += (dadesf[4*(i+Res2X)+1]/dadesf[4*(i+Res2X)+3]);
-						aux[2] += (dadesf[4*(i+Res2X)+2]/dadesf[4*(i+Res2X)+3]);
-						aux[3] += 1.0;
-						a =+ 1.0;;
-					}
-					if(i%Res2X!=Res2X-1)
-					{
-						if(dadesf[4*(i-Res2X)+7]>15)	//ur();
-						{
-							aux[0] += (dadesf[4*(i-Res2X)+4]/dadesf[4*(i-Res2X)+7]);
-							aux[1] += (dadesf[4*(i-Res2X)+5]/dadesf[4*(i-Res2X)+7]);
-							aux[2] += (dadesf[4*(i-Res2X)+6]/dadesf[4*(i-Res2X)+7]);
-							aux[3] += 1.0;
-							a =+ 1.0;;
-						}
-						if(dadesf[4*i+7]>15)	//r();
-						{
-							aux[0] += (dadesf[4*i+4]/dadesf[4*i+7]);
-							aux[1] += (dadesf[4*i+5]/dadesf[4*i+7]);
-							aux[2] += (dadesf[4*i+6]/dadesf[4*i+7]);
-							aux[3] += 1.0;
-							a =+ 1.0;;
-						}
-						if(dadesf[4*(i+Res2X)+7]>15)	//dr();
-						{
-							aux[0] += (dadesf[4*(i+Res2X)+4]/dadesf[4*(i+Res2X)+7]);
-							aux[1] += (dadesf[4*(i+Res2X)+5]/dadesf[4*(i+Res2X)+7]);
-							aux[2] += (dadesf[4*(i+Res2X)+6]/dadesf[4*(i+Res2X)+7]);
-							aux[3] += 1.0;
-							a =+ 1.0;;
-						}
-					}
-					if(dadesf[4*(i-Res2X)+3]>15)	//u();
-					{
-						aux[0] += (dadesf[4*(i-Res2X)]/dadesf[4*(i-Res2X)+3]);
-						aux[1] += (dadesf[4*(i-Res2X)+1]/dadesf[4*(i-Res2X)+3]);
-						aux[2] += (dadesf[4*(i-Res2X)+2]/dadesf[4*(i-Res2X)+3]);
-						aux[3] += 1.0;
-						a =+ 1.0;;
-					}
-				}
-			}
-			else
-			{
-				if(i%Res2X !=0)
-				{
-					if(dadesf[4*i-1]>15)	//l();
-					{
-						aux[0] += (dadesf[4*i-4]/dadesf[4*i-1]);
-						aux[1] += (dadesf[4*i-3]/dadesf[4*i-1]);
-						aux[2] += (dadesf[4*i-2]/dadesf[4*i-1]);
-						aux[3] += 1.0;
-						a =+ 1.0;;
-					}
-					if(dadesf[4*(i+Res2X)-1]>15)	//dl();
-					{
-						aux[0] += (dadesf[4*(i+Res2X)-4]/dadesf[4*(i+Res2X)-1]);
-						aux[1] += (dadesf[4*(i+Res2X)-3]/dadesf[4*(i+Res2X)-1]);
-						aux[2] += (dadesf[4*(i+Res2X)-2]/dadesf[4*(i+Res2X)-1]);
-						aux[3] = 1.0;
-						a =+ 1.0;;
-					}
-				}
-				if(i%Res2X!=Res2X-1)
-				{
-					if(dadesf[4*i+7]>15)	//r();
-					{
-						aux[0] += (dadesf[4*i+4]/dadesf[4*i+7]);
-						aux[1] += (dadesf[4*i+5]/dadesf[4*i+7]);
-						aux[2] += (dadesf[4*i+6]/dadesf[4*i+7]);
-						aux[3] += 1.0;
-						a =+ 1.0;;
-					}
-					if(dadesf[4*(i+Res2X)+7]>15)	//dr();
-					{
-						aux[0] += (dadesf[4*(i+Res2X)+4]/dadesf[4*(i+Res2X)+7]);
-						aux[1] += (dadesf[4*(i+Res2X)+5]/dadesf[4*(i+Res2X)+7]);
-						aux[2] += (dadesf[4*(i+Res2X)+6]/dadesf[4*(i+Res2X)+7]);
-						aux[3] += 1.0;
-						a =+ 1.0;;
-					}
-				}
-				if(dadesf[4*(i+Res2X)+3]>15)	//d();
-				{
-						aux[0] += (dadesf[4*(i+Res2X)]/dadesf[4*(i+Res2X)+3]);
-						aux[1] += (dadesf[4*(i+Res2X)+1]/dadesf[4*(i+Res2X)+3]);
-						aux[2] += (dadesf[4*(i+Res2X)+2]/dadesf[4*(i+Res2X)+3]);
-						aux[3] += 1.0;
-						a =+ 1.0;;
-				}
-			}
-			if(a > 0.0)
-			{
-				dadesf[4*i] = aux[0]/aux[3];
-				dadesf[4*i+1] = aux[1]/aux[3];
-				dadesf[4*i+2] = aux[2]/aux[3];
-				dadesf[4*i+3] = 1.0;
-			}
-			else
-			{
-				dadesf[4*i] = 0.0;
-				dadesf[4*i+1] = 0.0;
-				dadesf[4*i+2] = 0.0;
-				dadesf[4*i+3] = 0.0;
-			}
-		}
-		dadesi[4*i] = (int)(255.0*dadesf[4*i]);
-		dadesi[4*i+1] = (int)(255.0*dadesf[4*i+1]);
-		dadesi[4*i+2] = (int)(255.0*dadesf[4*i+2]);
-		dadesi[4*i+3] = (int)(255.0*dadesf[4*i+3]);
-
-	}
-
-	geom = g_pMesh;
-
-	imdebug("rgba b=32f w=%d h=%d %p", Res2X, Res2Y, dadesf);
-
-	*imgRgbBuffer = dadesf;
-
-	return 0;
-
-}
