varying vec3 V;
varying vec3 V1;
varying vec3 dir;

void main() 
{	
   V = vec3(gl_ModelViewMatrix * gl_Vertex);
   V1 = vec3(gl_Vertex);

	dir = vec3(gl_ModelViewMatrix*vec4(0,0,-1,1));

	//Calculate vertex's texture coordinate
	gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;	
	
	gl_ClipVertex = gl_ModelViewMatrix*gl_Vertex;
 
 	//Calculate vertex's final, transformed position.
	gl_Position = ftransform();
}
/*
uniform vec3 vecTranslate;
uniform float dPlaneStart;

uniform int frontIdx;
uniform vec3 vecView;

uniform float dPlaneIncr;
uniform int nSequence[64];
uniform vec3 vecVertices[8];
uniform int v1[24];
uniform int v2[24];

void main() 
{
	vecTranslate = vec3(0.0);
	dPlaneStart = 0.0;
	frontIdx = 1;
	vecView = vec3(0.0,0.0,1.0);
	dPlaneIncr = 1.0;

	vecVertices[0] = vec3(-1.0,  1.0,  1.0);
	vecVertices[1] = vec3( 1.0,  1.0,  1.0);
	vecVertices[2] = vec3(-1.0, -1.0,  1.0);
	vecVertices[3] = vec3( 1.0, -1.0,  1.0);
	vecVertices[4] = vec3(-1.0,  1.0, -1.0);
	vecVertices[5] = vec3( 1.0,  1.0, -1.0);
	vecVertices[6] = vec3(-1.0, -1.0, -1.0);
	vecVertices[7] = vec3( 1.0, -1.0, -1.0);

   //V = vec3(gl_ModelViewMatrix * gl_Vertex);

   float dPlane = dPlaneStart + gl_Vertex.y * dPlaneIncr;
   vec3 Position;

   for(int e=0; e<4; e++)
   {
		int vidx1 = nSequence[int(frontIdx*8+v1[gl_Vertex.y*4+e])];
		int vidx2 = nSequence[int(frontIdx*8+v2[gl_Vertex.y*4+e])];

		vec3 vecV1 = vecVertices[vidx1];
		vec3 vecV2 = vecVertices[vidx2];

		vec3 vecStart = vecV1 + vecTranslate;
		vec3 vecDir = vecV2 - vecV1;

		float denom = dot(vecDir, vecView);
		float lambda = (denom!=0.0) ? (dPlane-dot(vecStart, vecView))/denom : -1.0;

		if((lambda>=0.0) && (lambda<=1.0))
		{
			Position = vecStart + lambda * vecDir;
			break;
		}
   }

    V = vec3(gl_ModelViewMatrix * gl_Vertex);
   V1 = vec3(gl_Vertex);

	dir = vec3(gl_ModelViewMatrix*vec4(0,0,-1,1));
   gl_Position = gl_ModelViewMatrix * vec4(Position, 1.0);
   gl_TexCoord[0].stp = 0.5 * Position + 0.5;
}*/