/* ============================================================
 * File  : tetrahedron.cpp
 * Author: Stephane Gibault
 * Date  : Sun Feb 4 2007
 * Description :
 *
 * 
 *  (C) 2007 by Stephane Gibault
 *
 * This program is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General
 * Public License as published by the Free Software Foundation;
 * either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * ============================================================ */

#include <QtOpenGL>
#include "tetrahedron.h"
#include <math.h>

Tetrahedron::Tetrahedron(QWidget *parent)
    : QGLWidget(parent)
{
	setFormat(QGLFormat(QGL::DirectRendering | QGL::DepthBuffer));  // | QGL::NoAccumBuffer
	//setAttribute(Qt::WA_PaintOnScreen);
	this->setFocusPolicy(Qt::NoFocus);
    	rotationX = 0.0;
    	rotationY = 0.0;
    	rotationZ = 0.0;
    	deplacementX = 0.0;
    	deplacementY = 0.0;
	zoom = -10.0;
	debut_px = 0;
	debut_py = 0;
	debut_pz = -10;
	debut_rx = 0;
	debut_ry = 0;
	debut_rz = 0;
	//
	fin_px = 0;
	fin_py = 0;
	fin_pz = -10;
	fin_rx = 0;
	fin_ry = 0;
	fin_rz = 0;
	emptydiapo = 1;
	//
	posanim_x = 0;
	posanim_y = 0;
	sizanim = 1.0f;
	iseffect = 0;
	ismblur = 0;
	effetsup = 0;
	is43 = 0;
	path_fond = "$N$U$L$L";
	type3D = 0;
	poursuite = 0;
	element = 0;
	affiche_grille = 0;
	nbre_ani_slide = 0;
	//
	w_x_p = 2;
	w_x_m = -2;
	max_diapo = -1;
	//
	/*int i = 0;
	srand(time(NULL));
	while ( i < 1500 )
	{
		elements[i][0] = (float)(((float)rand() / ((float)RAND_MAX + 1) * 40)-20); //(float)(rand()%(40))-20;
		elements[i][1] = (float)(((float)rand() / ((float)RAND_MAX + 1) * 40)-20); //(float)(rand()%(40))-32;
		elements[i][2] = (float)(((float)rand() / ((float)RAND_MAX + 1) * 20)*-1); //(float)(rand()%(20))*-1;
		if ( elements[i][2] > -1.90f )
		{
			elements[i][2] = -1.90f;
		}
		i++;
	}*/
	//
	QImage wl_img_dec(128,128,QImage::Format_ARGB32_Premultiplied);
	wl_img_dec.fill(0);
	null_img = wl_img_dec.copy ( 0, 0, 128, 128);
	state_mode = 0;
	//
	movie = new QMovie();
	movie_object = new QMovie();
	qDebug() << "SYSTEM OVERLAY : " << QGLFormat::hasOpenGLOverlays();
	if ( format().directRendering() == true )
	{
		qDebug() << "DIRECT RENDERING : TRUE";
	}
	else
	{
		qDebug() << "DIRECT RENDERING : FALSE <--> OOPS WARNING <-->";
	}
	if ( format().doubleBuffer() == true )
	{
		qDebug() << "DOUBLE BUFFERING : TRUE";
	}
	else
	{
		qDebug() << "DOUBLE BUFFERING : FALSE <--> OOPS WARNING <-->";
	}
	if ( format().QGLFormat::hasOpenGL() == true )
	{
		qDebug() << "OPENGL SUPPORT : TRUE";
	}
	else
	{
		qDebug() << "OPENGL SUPPORT : FALSE <--> OOPS WARNING <-->";
	}
	qDebug() << "OPENGL VERSION : " << QGLFormat::openGLVersionFlags();
	//
	forme1 = new QAction(tr("Plaque"), this);
	forme1->setIcon ( QIcon(":/new/prefix2/Interface/Theme/mini_plaque.png") );
	forme2 = new QAction(tr("Boite"), this);
	forme2->setIcon ( QIcon(":/new/prefix2/Interface/Theme/mini_cube.png") );
	forme3 = new QAction(tr("Drapeau"), this);
	forme3->setIcon ( QIcon(":/new/prefix2/Interface/Theme/mini_f_s.png") );
	forme4 = new QAction(tr("Drapeau anime"), this);
	forme4->setIcon ( QIcon(":/new/prefix2/Interface/Theme/mini_f_a.png") );
	forme5 = new QAction(tr("Demi plaque horizontale"), this);
	forme5->setIcon ( QIcon(":/new/prefix2/Interface/Theme/mini_p_h.png") );
	forme6 = new QAction(tr("Demi plaque verticale"), this);
	forme6->setIcon ( QIcon(":/new/prefix2/Interface/Theme/mini_p_v.png") );
	forme7 = new QAction(tr("Fenetre"), this);
	forme7->setIcon ( QIcon(":/new/prefix2/Interface/Theme/mini_window.png") );
	forme8 = new QAction(tr("Livre"), this);
	forme8->setIcon ( QIcon(":/new/prefix2/Interface/Theme/mini_book.png") );
	forme13 = new QAction(tr("Plaque avec reflet"), this);
	forme13->setIcon ( QIcon(":/new/prefix2/Interface/Theme/mini_plaque.png") );
	forme14 = new QAction(tr("Boite avec reflet"), this);
	forme14->setIcon ( QIcon(":/new/prefix2/Interface/Theme/mini_cube.png") );

	forme9 = new QAction(tr("Copier les coordonnees"), this);
	forme9->setIcon ( QIcon(":/new/prefix2/Interface/Theme/copy.png") );
	forme10 = new QAction(tr("Coller les coordonnees"), this);
	forme10->setIcon ( QIcon(":/new/prefix2/Interface/Theme/editpaste.png") );

	forme11 = new QAction(tr("Editer la diapositive"), this);
	forme11->setIcon ( QIcon(":/new/prefix2/Interface/Theme/applications_graphics.png") );

	forme12 = new QAction(tr("Reinitialiser les coordonnees"), this);
	forme12->setIcon ( QIcon(":/new/prefix2/Interface/Theme/eraser.png") );

	forme15 = new QAction(tr("Tourner de -90 degres"), this);
	forme15->setIcon ( QIcon(":/new/prefix2/Interface/Theme/rotate_angle.png") );
	forme16 = new QAction(tr("Tourner de 90 degres"), this);
	forme16->setIcon ( QIcon(":/new/prefix2/Interface/Theme/rotate_angleplus.png") );

	forme17 = new QAction(tr("Charger une image d'arriere plan"), this);
	forme17->setIcon ( QIcon(":/new/prefix2/Interface/Theme/folder.png") );

	connect(forme1, SIGNAL(triggered()), this, SLOT(changeforme_1()));
	connect(forme2, SIGNAL(triggered()), this, SLOT(changeforme_2()));
	connect(forme3, SIGNAL(triggered()), this, SLOT(changeforme_3()));
	connect(forme4, SIGNAL(triggered()), this, SLOT(changeforme_4()));
	connect(forme5, SIGNAL(triggered()), this, SLOT(changeforme_5()));
	connect(forme6, SIGNAL(triggered()), this, SLOT(changeforme_6()));
	connect(forme7, SIGNAL(triggered()), this, SLOT(changeforme_7()));
	connect(forme8, SIGNAL(triggered()), this, SLOT(changeforme_8()));
	connect(forme9, SIGNAL(triggered()), this, SLOT(emitcopy()));
	connect(forme10, SIGNAL(triggered()), this, SLOT(emitpaste()));
	connect(forme11, SIGNAL(triggered()), this, SLOT(emitiedit()));
	connect(forme12, SIGNAL(triggered()), this, SLOT(emiteraser()));
	connect(forme13, SIGNAL(triggered()), this, SLOT(changeforme_9()));
	connect(forme14, SIGNAL(triggered()), this, SLOT(changeforme_10()));
	connect(forme15, SIGNAL(triggered()), this, SLOT(changeforme_15()));
	connect(forme16, SIGNAL(triggered()), this, SLOT(changeforme_16()));
	connect(forme17, SIGNAL(triggered()), this, SLOT(changeforme_17()));
}

void Tetrahedron::sl_grille()
{
	if ( affiche_grille == 0 )
	{
		affiche_grille = 1;
	}
	else
	{
		affiche_grille = 0;
	}
	updateGL();
}

void Tetrahedron::emiteraser()
{
	emit c_eraser();
}

void Tetrahedron::emitiedit()
{
	emit c_iedit();
}

void Tetrahedron::emitcopy()
{
	emit c_copy();
}

void Tetrahedron::emitpaste()
{
	emit c_paste();
}

void Tetrahedron::changeforme_1()
{
	type3D = 0;
	emit updfrm(0);
	updateGL();
}

void Tetrahedron::changeforme_2()
{
	type3D = 2;
	emit updfrm(2);
	updateGL();
}

void Tetrahedron::changeforme_3()
{
	type3D = 1;
	emit updfrm(1);
	sl_charge_image(wg_pathimg,wg_pathfond,wg_pathlegende);
	updateGL();
}

void Tetrahedron::changeforme_4()
{
	type3D = 3;
	emit updfrm(3);
	sl_charge_image(wg_pathimg,wg_pathfond,wg_pathlegende);
	updateGL();
}

void Tetrahedron::changeforme_5()
{
	type3D = 6;
	emit updfrm(6);
	updateGL();
}

void Tetrahedron::changeforme_6()
{
	type3D = 5;
	emit updfrm(5);
	updateGL();
}

void Tetrahedron::changeforme_7()
{
	type3D = 4;
	emit updfrm(4);
	updateGL();
}

void Tetrahedron::changeforme_8()
{
	type3D = 7;
	emit updfrm(7);
	updateGL();
}

void Tetrahedron::changeforme_9()
{
	type3D = 8;
	emit updfrm(8);
	updateGL();
}

void Tetrahedron::changeforme_10()
{
	type3D = 9;
	emit updfrm(9);
	updateGL();
}

void Tetrahedron::changeforme_15()
{
	rotationZ = rotationZ + 90;
	updateGL();
}

void Tetrahedron::changeforme_16()
{
	rotationZ = rotationZ - 90;
	updateGL();
}

void Tetrahedron::changeforme_17()
{
	emit loadback();
}

void Tetrahedron::contextMenuEvent(QContextMenuEvent *event)
{
	if ( max_diapo >= 0 && emptydiapo == 0 )
	{
		QMenu menu(this);
		menu.addAction(forme1);
		menu.addAction(forme2);
		menu.addAction(forme3);
		menu.addAction(forme4);
		menu.addAction(forme5);
		menu.addAction(forme6);
		menu.addAction(forme7);
		menu.addAction(forme8);
		menu.addAction(forme13);
		menu.addAction(forme14);
		menu.addSeparator();
		menu.addAction(forme15);
		menu.addAction(forme16);
		menu.addSeparator();
		menu.addAction(forme9);
		menu.addAction(forme10);
		menu.addAction(forme12);
		if ( isdiapoanim == 0 )
		{
			menu.addSeparator();
			menu.addAction(forme11);
		}
		menu.addSeparator();
		menu.addAction(forme17);
		menu.exec(event->globalPos());
	}
	else
	{
		if ( max_diapo >= 0 && emptydiapo > 0 )
		{
			QMenu menu(this);
			menu.addAction(forme17);
			menu.exec(event->globalPos());
		}
	}
}

void Tetrahedron::load_effet(QString nomeffet)
{
	bcle_render = 1;
	glDeleteTextures(1, &texture3 );

	if ( nomeffet == tr("Aucun") )
	{
		iseffect = 0;
	}
	else
	{
		iseffect = 1;
		delete movie;
		movie = new QMovie(wg_tet_library + "/BIB_ManSlide/Eff_sup/" + nomeffet);
		if ( movie->isValid() == true )
		{
			movie->setCacheMode( QMovie::CacheAll );
			movie->jumpToFrame( 0 );
			a = movie->currentImage();
			//
			int n;
			if ( a.width() > a.height() )
			{
				n = a.width();
			}
			else
			{
				n = a.height();
			}
			n = n - 1;
			n = n | (n >> 1);
			n = n | (n >> 2);
			n = n | (n >> 4);
			n = n | (n >> 8);
			n = n | (n >> 16);
			n = n + 1;

			wg_puis_001 = a.copy ( 0, 0, n, n);
			size_anim = n;
			size_003 = (float)a.width() / (float)n;
			size_004 = 1-((float)a.height() / (float)n);
			ratioeffet = (float)((float)a.width()/(float)a.height());
			d = QGLWidget::convertToGLFormat( wg_puis_001 );
			glGenTextures( 1, &texture3 );
			glBindTexture( GL_TEXTURE_2D, texture3 );
			glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, d.width(), d.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, d.bits() );
			glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
			long_effet = movie->frameCount();
		}
		else
		{
			qDebug() << "ERROR LOADING EFFECT TEXTURE - INIT POSITION - " << wg_tet_library + "/BIB_ManSlide/Eff_sup/" + nomeffet;
		}
	}
}

void Tetrahedron::sl_charge_image(QString pathimg, QString pathfond, QString pathlegende)
{
	bcle_render = 1;
	glDeleteTextures(1, &texture2 );
	if ( pathimg.right(8) != "$N$U$L$L" )
	{
		if ( pathimg.lastIndexOf( "emptydiapo" ) >= 0 )
		{
			emptydiapo = 1;
		}
		else
		{
			emptydiapo = 0;
		}
    		if ( b.load( pathimg ) == true )
		{
			if ( pathimg.right(4) == ".gif" )
			{
				isdiapoanim = 1;
				delete movie_object;
				movie_object = new QMovie(pathimg);
				if ( movie_object->isValid() == true )
				{
					movie_object->setCacheMode( QMovie::CacheAll );
					movie_object->jumpToFrame( 0 );
				       	int tmpint_3 = pathimg.indexOf("STP", 0);
					if ( tmpint_3 != -1 )
					{
						int tmpint_2 = pathimg.lastIndexOf( "/" );
						if ( tmpint_2 > 0 )
						{
							nbre_ani_slide = pathimg.mid(tmpint_2+1,(tmpint_3-tmpint_2)-1).toInt() - 1;
						}
						else
						{
							nbre_ani_slide = 1;
						}
					}
					else
					{
						nbre_ani_slide = 1;
					}
				}
			}
			else
			{
				isdiapoanim = 0;
			}

			QImage wl_puis_001(1024,1024,QImage::Format_ARGB32_Premultiplied);
			wl_puis_001 = b.copy ( 0, 0, 1024, 1024);
			size_001 = (float)b.width() / (float)1024;
			size_002 = 1-((float)b.height() / (float)1024);
			//
			wratioimg = (float)b.width() / (float)b.height();
			w_x_p = (float)(0-(2 * wratioimg)) * -1;
    			f = QGLWidget::convertToGLFormat( wl_puis_001 );
    			glGenTextures( 1, &texture2 );
			glBindTexture( GL_TEXTURE_2D, texture2 );
			glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, f.width(), f.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, f.bits() );
			glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
			w_x_m = w_x_p * -1;

			if ( type3D == 1 || type3D == 3 )
			{
				for(int x=0; x<45; x++)
				{
					for(int y=0; y<45; y++)
					{
						points[x][y][0]=float((x/5.0f)-4.5f);
						points[x][y][1]=float((y/5.0f)-4.5f);
						points[x][y][2]=float(sin((((x/3.0f)*40.0f)/360.0f)*3.141592654*2.0f));
					}
				}
			}
			// *** CONSTRUCTION DU REFLET ***
			q = b.mirrored(false,true);
			q = q.convertToFormat ( QImage::Format_ARGB32_Premultiplied, Qt::AutoColor );
			QPainter p;
			p.begin(&q);
			QPainter::CompositionMode mode = (QPainter::CompositionMode)6;
			p.setCompositionMode ( mode );
			p.setBackgroundMode(Qt::TransparentMode);
			QPen pen;
			pen.setCapStyle(Qt::RoundCap);
			pen.setJoinStyle(Qt::RoundJoin);
			p.setPen(pen);
			QLinearGradient mygradient2(0,0,0,b.height());
			mygradient2.setColorAt(0.0,QColor(255,255,255,200));
			mygradient2.setColorAt(0.3,QColor(0,0,0,10));
			mygradient2.setColorAt(0.6,QColor(0,0,0,0));
			p.fillRect ( 0, 0, 1024, b.height(), QBrush( mygradient2 ));
			p.end();

			wl_puis_001 = q.copy ( 0, 0, 1024, 1024);
    			e = QGLWidget::convertToGLFormat( wl_puis_001 );
    			glGenTextures( 1, &texture6 );
			glBindTexture( GL_TEXTURE_2D, texture6 );
			glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, e.width(), e.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, e.bits() );
			glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
		}
		else
		{
			qDebug() << "ERROR LOADING TEXTURE PLANE : " << pathimg;
		}
	}
	else
	{
		wratioimg = (float)null_img.width() / (float)null_img.height();
		w_x_p = (float)(0-(2 * wratioimg)) * -1;
    		f = QGLWidget::convertToGLFormat( null_img );
    		glGenTextures( 1, &texture2 );
		glBindTexture( GL_TEXTURE_2D, texture2 );
		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, f.width(), f.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, f.bits() );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
		w_x_m = w_x_p * -1;
	}
	// *** TEXTURE LEGENDE ***
	if ( state_mode == 1 && pathlegende.right(8) != "$N$U$L$L" )
	{
		glDeleteTextures(1, &texture4 );
    		if ( g.load( pathlegende ) == true )
		{
			//
			int n;
			if ( g.width() > g.height() )
			{
				n = g.width();
			}
			else
			{
				n = g.height();
			}
			n = n - 1;
			n = n | (n >> 1);
			n = n | (n >> 2);
			n = n | (n >> 4);
			n = n | (n >> 8);
			n = n | (n >> 16);
			n = n + 1;
			sizexleg = (float)g.width() / (float)n;
			sizeyleg = 1-((float)g.height() / (float)n);
			hauteur_leg = g.height();
			QImage wl_puis_005(n,n,QImage::Format_ARGB32_Premultiplied);
			wl_puis_005 = g.copy ( 0, 0, n, n);
			h = QGLWidget::convertToGLFormat( wl_puis_005 );
    			glGenTextures( 1, &texture4 );
			glBindTexture( GL_TEXTURE_2D, texture4 );
			glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, h.width(), h.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, h.bits() );
			glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
		}
		else
		{
			state_mode = 0;
			qDebug() << "ERROR LOADING TEXTURE LEGEND : " << pathlegende;
		}
	}
	else
	{
		state_mode = 0;
	}
	//
	if ( pathfond.right(8) != "$N$U$L$L" )
	{
		glDeleteTextures(1, &texture1 );
    		if ( c.load( pathfond ) == true )
		{
			QImage wl_puis_002(1024,1024,QImage::Format_ARGB32_Premultiplied);
			wl_puis_002 = c.copy ( 0, 0, 1024, 1024);
			t = QGLWidget::convertToGLFormat( wl_puis_002 );
    			glGenTextures( 1, &texture1 );
			glBindTexture( GL_TEXTURE_2D, texture1 );
			glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits() );
			glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
			path_fond = pathfond;
		}
		else
		{
			qDebug() << "ERROR LOADING TEXTURE BACKGROUND : " << pathfond;
		}
	}
	else
	{
		glDeleteTextures(1, &texture1 );
		//
    		t = QGLWidget::convertToGLFormat( null_img );
    		glGenTextures( 1, &texture1 );
		glBindTexture( GL_TEXTURE_2D, texture1 );
		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits() );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
	}
	wg_pathimg = pathimg;
	wg_pathfond = pathfond;
	wg_pathlegende = pathlegende;
}

void Tetrahedron::loadeffetsup(int state)
{
	bcle_render = 1;
	QString effects;
	if (state == 1)
	{
		effects = ":/new/prefix2/Interface/Theme/snowflakes.png";
	}
	else
	{
		if (state == 2)
		{
			effects = ":/new/prefix2/Interface/Theme/heartsnow.png";
		}
		else
		{
			if (state == 3)
			{
				effects = ":/new/prefix2/Interface/Theme/flowersnow.png";
			}
			else
			{
				if (state == 4)
				{
					effects = ":/new/prefix2/Interface/Theme/nounourssnow.png";
				}
				else
				{
					if (state == 5)
					{
						effects = ":/new/prefix2/Interface/Theme/rainsnow.png";
					}
					else
					{
						if (state == 6)
						{
							effects = ":/new/prefix2/Interface/Theme/feuillesnow.png";
						}
						else
						{
							effects = chemin_flocon;
						}
					}
				}
			}
		}
	}
	glDeleteTextures(1, &texture8 );
	if ( r.load( effects ) == true )
	{
		int n;
		if ( r.width() > r.height() )
		{
			n = r.width();
		}
		else
		{
			n = r.height();
		}
		n = n - 1;
		n = n | (n >> 1);
		n = n | (n >> 2);
		n = n | (n >> 4);
		n = n | (n >> 8);
		n = n | (n >> 16);
		n = n + 1;

		QImage wl_puis_001(n,n,QImage::Format_ARGB32_Premultiplied);
		wl_puis_001 = r.copy ( 0, 0, n, n);
		size_f_001 = (float)r.width() / (float)n;
		size_f_002 = 1-((float)r.height() / (float)n);
		wratiof = (float)r.width() / (float)r.height();
		//
		r2 = QGLWidget::convertToGLFormat( wl_puis_001 );
		glGenTextures( 1, &texture8 );
		glBindTexture( GL_TEXTURE_2D, texture8 );
		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, r2.width(), r2.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, r2.bits() );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
		updateGL();
	}
	else
	{
		qDebug() << "ERROR LOADING TEXTURE SNOW";
	}
}

void Tetrahedron::sl_charge_dessin(QString pathimg)
{
	glDeleteTextures(1, &texture5 );
	if ( w.load( pathimg ) == true )
	{
		QImage wl_puis_005(1024,1024,QImage::Format_ARGB32_Premultiplied);
		wl_puis_005 = w.copy ( 0, 0, 1024, 1024);
		j = QGLWidget::convertToGLFormat( wl_puis_005 );
		glGenTextures( 1, &texture5 );
		glBindTexture( GL_TEXTURE_2D, texture5 );
		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, j.width(), j.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, j.bits() );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
	}
	else
	{
		qDebug() << "ERROR LOADING TEXTURE DRAW : " << pathimg;
	}
}

void Tetrahedron::sl_go_start()
{
	rotationX = debut_rx;
	rotationY = debut_ry;
	rotationZ = debut_rz;
	deplacementX = debut_px;
	deplacementY = debut_py;
	zoom = debut_pz;
	if ( fadels == 0 )
	{
		wg_percent_trans = 1.0f;
	}
	else
	{
		wg_percent_trans = 0.0f;
	}
	progress = 0;
	updateGL();
}

void Tetrahedron::sl_go_end()
{
	rotationX = fin_rx;
	rotationY = fin_ry;
	rotationZ = fin_rz;
	deplacementX = fin_px;
	deplacementY = fin_py;
	zoom = fin_pz;
	if ( fadele == 0 && wg_cpt_002 == duree )
	{
		wg_percent_trans = 1.0f;
	}
	else
	{
		wg_percent_trans = 0.0f;
	}
	progress = duree;
	updateGL();
}

void Tetrahedron::sl_wait_stop()
{
	if ( iseffect > 0 )
	{
		glDeleteTextures(1, &texture3 );
		movie->jumpToFrame(0);
		a = movie->currentImage();
		glGenTextures( 1, &texture3 );
		glBindTexture( GL_TEXTURE_2D, texture3 );
		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, d.width(), d.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, d.bits() );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
	}
    	rotationX = debut_rx;
    	rotationY = debut_ry;
    	rotationZ = debut_rz;
    	deplacementX = debut_px;
    	deplacementY = debut_py;
	wg_percent = start_opacity;
	zoom = debut_pz;
	bcle_render = 1;
	updateGL();
}

void Tetrahedron::sl_mark_deb()
{
	debut_px = deplacementX;
	debut_py = deplacementY;
	debut_pz = zoom;
	debut_rx = rotationX;
	debut_ry = rotationY;
	debut_rz = rotationZ;
}

void Tetrahedron::sl_mark_fin()
{
	fin_px = deplacementX;
	fin_py = deplacementY;
	fin_pz = zoom;
	fin_rx = rotationX;
	fin_ry = rotationY;
	fin_rz = rotationZ;
}

void Tetrahedron::initializeGL()
{
    	qglClearColor(Qt::black);
	glClearAccum(0.0, 0.0, 0.0, 1.0);
	glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
	bcle_render = 0;
	//
 	fogcolor[0] = 0.5;
 	fogcolor[1] = 0.5;
 	fogcolor[2] = 0.5;
 	fogcolor[3] = 0.5;
 	GLint fogmode = GL_EXP;
 	glFogi (GL_FOG_MODE, fogmode);
 	glFogfv(GL_FOG_COLOR, fogcolor);
 	glFogf(GL_FOG_DENSITY, 0.30);
 	glFogf(GL_FOG_START, -4.0);
 	glFogf(GL_FOG_END, -10.0);
	glDisable(GL_FOG);
	glEnable( GL_DEPTH_TEST );
	glDisable( GL_NORMALIZE );
	glDisable( GL_DITHER );
	glDisable( GL_SMOOTH );
	//
	glDisable( GL_LIGHTING );
	glShadeModel(GL_SMOOTH);
	glEnable( GL_ALPHA_TEST ); //***
	glEnable( GL_BLEND );
	glDisable( GL_STENCIL_TEST );
	glDepthMask(GL_FALSE);
	glAlphaFunc(GL_GREATER, 0.0f);
	glEnable(GL_COLOR_MATERIAL); //***

	glDepthMask(1);

 	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
	#ifdef Q_WS_WIN
		glHint(0x84EF, GL_FASTEST);
	#else
		glHint(GL_TEXTURE_COMPRESSION_HINT, GL_FASTEST);
	#endif
	//
    	glMatrixMode(GL_MODELVIEW);
    	glEnable(GL_TEXTURE_2D);
	null_img.fill(1);
	t = QGLWidget::convertToGLFormat(null_img );
	glGenTextures( 1, &texture1 );
	glBindTexture( GL_TEXTURE_2D, texture1 );
	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits() );
	f = QGLWidget::convertToGLFormat( null_img );
	glGenTextures( 1, &texture2 );
	glBindTexture( GL_TEXTURE_2D, texture2 );
	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, f.width(), f.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, f.bits() );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
	d = QGLWidget::convertToGLFormat( null_img );
	glGenTextures( 1, &texture3 );
	glBindTexture( GL_TEXTURE_2D, texture3 );
	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, d.width(), d.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, d.bits() );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
	h = QGLWidget::convertToGLFormat( null_img );
	glGenTextures( 1, &texture4 );
	glBindTexture( GL_TEXTURE_2D, texture4 );
	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, h.width(), h.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, h.bits() );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
	j = QGLWidget::convertToGLFormat( null_img );
	glGenTextures( 1, &texture5 );
	glBindTexture( GL_TEXTURE_2D, texture5 );
	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, j.width(), j.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, j.bits() );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
	e = QGLWidget::convertToGLFormat( null_img );
	glGenTextures( 1, &texture6 );
	glBindTexture( GL_TEXTURE_2D, texture6 );
	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, e.width(), e.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, e.bits() );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
	//
	QImage wli1;
	wli1.fill(0);
	glGenTextures( 1, &texture7 );
	glBindTexture( GL_TEXTURE_2D, texture7 );
	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, wli1.width(), wli1.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, wli1.bits() );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );

	glGenTextures( 1, &texture8 );
	glBindTexture( GL_TEXTURE_2D, texture8 );
	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, wli1.width(), wli1.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, wli1.bits() );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
}

void Tetrahedron::change_fog_color()
{
 	//GLint fogmode = GL_EXP;
 	glFogfv(GL_FOG_COLOR, fogcolor);
}

void Tetrahedron::sl_opacity(int wopacity)
{
	float recval = (float)wopacity;
	GLfloat fopacity;
	fopacity = recval / 100;
	glFogfv(GL_FOG_DENSITY, &fopacity);
	updateGL();
}

void Tetrahedron::sl_set_opacity()
{
	glFogfv(GL_FOG_DENSITY, &start_opacity);
}

void Tetrahedron::sl_brouillard(int wstate)
{
	isfog = wstate;
	if ( wstate == 0)
	{
		glDisable(GL_FOG);
	}
	else
	{
		glEnable(GL_FOG);
	}
	updateGL();
}

void Tetrahedron::resizeGL(int width, int height)
{
    	glViewport(0, 0, width, height);
    	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
    	GLfloat szx = GLfloat(width) / GLfloat(height);
    	glFrustum(-szx, szx, -1.0, 1.0, 1.9, 30.1);
    	glMatrixMode(GL_MODELVIEW);
}

void Tetrahedron::paintGL()
{
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	draw();
}

void Tetrahedron::sl_change_fond(QString myfic)
{
	bcle_render = 1;
	if ( myfic.right(8) != "$N$U$L$L" )
	{
		path_fond = myfic;
		glDeleteTextures(1, &texture1 );
		c.load( myfic );
		//
		QImage wl_puis_001(1024,1024,QImage::Format_ARGB32_Premultiplied);
		wl_puis_001 = c.copy ( 0, 0, 1024, 1024);
		t = QGLWidget::convertToGLFormat( wl_puis_001 );
		glGenTextures( 1, &texture1 );
		glBindTexture( GL_TEXTURE_2D, texture1 );
		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits() );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
	}
	else
	{
		glDeleteTextures(1, &texture1 );
		t = QGLWidget::convertToGLFormat( null_img );
		glGenTextures( 1, &texture1 );
		glBindTexture( GL_TEXTURE_2D, texture1 );
		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits() );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
	}
	wg_pathfond = myfic;
}

void Tetrahedron::sl_fond_color(int red, int green, int blue)
{
	QImage wl_puis_001(1024,1024,QImage::Format_ARGB32_Premultiplied);
	QColor wlcolor(red,green,blue,255);
	wl_puis_001.fill(wlcolor.rgb());
	t = QGLWidget::convertToGLFormat( wl_puis_001 );
	glGenTextures( 1, &texture1 );
	glBindTexture( GL_TEXTURE_2D, texture1 );
	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits() );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
	updateGL();
}

void Tetrahedron::sl_fond_degrade(int red, int green, int blue, int fred, int fgreen, int fblue, int longueur)
{
	QImage wl_puis_001(1024,1024,QImage::Format_ARGB32_Premultiplied);
	QColor wlcolor(red,green,blue,255);
	QColor wlcolor2(fred,fgreen,fblue,255);

	QLinearGradient mygradient(512,0,512,576);
	if ( longueur <= 100 )
	{
		mygradient.setColorAt(0.0,wlcolor);
		mygradient.setColorAt((float)((float)longueur/(float)100),wlcolor2);
	}
	else
	{
		mygradient.setColorAt((float)((float)(longueur-100)/(float)100),wlcolor);
		mygradient.setColorAt(1.0,wlcolor2);
	}
	QPainter p;
	p.begin(&wl_puis_001);
	p.fillRect ( 0, 0, 1024 ,1024, QBrush( mygradient ) );
	p.end();

	t = QGLWidget::convertToGLFormat( wl_puis_001 );
	glGenTextures( 1, &texture1 );
	glBindTexture( GL_TEXTURE_2D, texture1 );
	glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, t.width(), t.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, t.bits() );
	glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
	updateGL();
}

void Tetrahedron::mousePressEvent(QMouseEvent *event)
{
    	lastPos = event->pos();
}

void Tetrahedron::wheelEvent(QWheelEvent *event)
{
	if ( element == 0 )
	{
		if ( event->delta() > 0 )
		{
			if ( zoom < -2.2 )
			{
				zoom = zoom + 0.1;
			}
		}
		else
		{
			if ( zoom > -29.6 )
			{
				zoom = zoom - 0.1;
			}
		}
		updateGL();
	}
	else
	{
		if ( event->delta() > 0 )
		{
			emit sizep();
		}
		else
		{
			emit sizem();
		}
	}
}

void Tetrahedron::mouseMoveEvent(QMouseEvent *event)
{
    	GLfloat dx = GLfloat(event->x() - lastPos.x()) / width();
    	GLfloat dy = GLfloat(event->y() - lastPos.y()) / height();

    	if (event->buttons() & Qt::LeftButton) 
	{
		if ( element == 0 )
		{
			if ( tool == 2 )
			{
				deplacementX += (dx * (zoom * -1));
				deplacementY += (dy * (zoom * -1)) * -1;
			}
			else
			{
				if ( tool == 1 )
				{
					if ( event->x() > lastPos.x() )
					{
						if ( zoom < -2.2 )
						{
							zoom = zoom + 0.1;
						}
					}
					else
					{
						if ( zoom > -29.6 )
						{
							zoom = zoom - 0.1;
						}
					}
				}
				else
				{
					if ( tool == 3 )
					{
						if ( event->x() > lastPos.x() )
						{
							rotationX = rotationX + (1 * (event->x() - lastPos.x()));
						}
						else
						{
							rotationX = rotationX - (1 * (lastPos.x() - event->x()));
						}
					}
					else
					{
						if ( tool == 4 )
						{
							if ( event->x() > lastPos.x() )
							{
								rotationY = rotationY + (1 * (event->x() - lastPos.x()));
							}
							else
							{
								rotationY = rotationY - (1 * (lastPos.x() - event->x()));
							}
						}
						else
						{
							if ( tool == 5 )
							{
								if ( event->x() > lastPos.x() )
								{
									rotationZ = rotationZ + (1 * (event->x() - lastPos.x()));
								}
								else
								{
									rotationZ = rotationZ - (1 * (lastPos.x() - event->x()));
								}
							}
							else
							{
							if ( tool == 6 )
							{
									if ( event->x() > lastPos.x() )
									{
										rotationY = rotationY + (1 * (event->x() - lastPos.x()));
									}
									else
									{
										rotationY = rotationY - (1 * (lastPos.x() - event->x()));
									}
									if ( event->y() > lastPos.y() )
									{
										rotationX = rotationX + (1 * (event->y() - lastPos.y()));
									}
									else
									{
										rotationX = rotationX - (1 * (lastPos.y() - event->y()));
									}
									if ( event->x() > lastPos.x() && event->y() > lastPos.y())
									{
										rotationZ = rotationZ + (1 * (event->x() - lastPos.x()));
									}
									else
									{
										if ( event->x() < lastPos.x() && event->y() < lastPos.y())
										rotationZ = rotationZ - (1 * (lastPos.x() - event->x()));
									}
								}
							}
						}
					}
				} 
			}
			updateGL();
		}
		else
		{
			posanim_x += (dx * 2.6);
			posanim_y += (dy * 2.0) * -1;
			emit chg_pos_legende();
			updateGL();
		}
	}
    	lastPos = event->pos();
}

void Tetrahedron::draw()
{
	if ( bcle_render == 1 )
	{
		glClearAccum(0.0, 0.0, 0.0, 1.0);
		glClear(GL_DEPTH_BUFFER_BIT);
	}
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	//glMatrixMode( GL_MODELVIEW );

	glEnable(GL_BLEND);
	glBlendFunc(GL_ONE, GL_ZERO);

	//
	if ( path_fond == "$N$U$L$L" )
	{
	}
	else
	{
		glLoadIdentity(); // *** Renouvellement matrice ***
		glTranslatef(0.0f, 0.0f, -30.0f);
		glBindTexture( GL_TEXTURE_2D, texture1 );
		glBegin(GL_QUADS);
		if ( is43 == 1 )
		{
			glTexCoord2f(0.703125f, 0.4375f);
			glVertex3f( 19.75f, -15.8f, 0.0f); 
			glTexCoord2f(0.703125f, 1.0f);
			glVertex3f(19.75f, 15.8f, 0.0f);
			glTexCoord2f(0.0f, 1.0f);
			glVertex3f(-19.75f, 15.8f, 0.0f);
			glTexCoord2f(0.0f, 0.4375f);
			glVertex3f(-19.75f, -15.8f, 0.0f);
		}
		else
		{
			if ( is43 == 0 )
			{
				glTexCoord2f(1.0f, 0.4375f);
				glVertex3f( 28.08f, -15.8f, 0.0f); 
				glTexCoord2f(1.0f, 1.0f);
				glVertex3f(28.08f, 15.8f, 0.0f);
				glTexCoord2f(0.0f, 1.0f);
				glVertex3f(-28.08f, 15.8f, 0.0f);
				glTexCoord2f(0.0f, 0.4375f);
				glVertex3f(-28.08f, -15.8f, 0.0f);
			}
			else
			{
				glTexCoord2f(0.703125f, 0.53125f);
				glVertex3f( 23.67f, -15.78f, 0.0f); 
				glTexCoord2f(0.703125f, 1.0f);
				glVertex3f(23.67f, 15.78f, 0.0f);
				glTexCoord2f(0.0f, 1.0f);
				glVertex3f(-23.67f, 15.78f, 0.0f);
				glTexCoord2f(0.0f, 0.53125f);
				glVertex3f(-23.67f, -15.78f, 0.0f);
			}
		}
		glEnd();
	}

	if ( isbackanim == 1 && iseffect > 0 )
	{
		glLoadIdentity(); // *** Renouvellement matrice ***
		glTranslatef(posanim_x*15, posanim_y*15, -29.8f);
    		glRotatef(-rotanim, 0.0, 0.0, 1.0);
		glColor4f(1.0f,1.0f,1.0f,wg_percent);
		glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glBindTexture( GL_TEXTURE_2D, texture3 );
		glBegin(GL_QUADS);
		glTexCoord2f(size_003, size_004);
		glVertex3f( 15.72f * sizanim, -(15.72f/ratioeffet) * sizanim, 0.0f); 
		glTexCoord2f(size_003, 1.0f);
		glVertex3f(15.72f * sizanim, (15.72f/ratioeffet) * sizanim, 0.0f);
		glTexCoord2f(0.0f, 1.0f);
		glVertex3f(-15.72f * sizanim, (15.72f/ratioeffet) * sizanim, 0.0f);
		glTexCoord2f(0.0f, size_004);
		glVertex3f(-15.72f * sizanim, -(15.72f/ratioeffet) * sizanim, 0.0f);
    		glEnd();
	}
	// *** EFFETS SUPPLEMENTAIRES ***
	if ( effetsup > 0 )
	{
		int i=0;
		while ( i < nombre_effet )
		{
			//
			elements[i][1] = elements[i][1] - speed_effet;
			if ( elements[i][1] < elements[i][2] )
			{
				elements[i][1] = -elements[i][2];
			}
			//
			glLoadIdentity(); // *** Renouvellement matrice ***
			glBindTexture( GL_TEXTURE_2D, texture8 );
			glTranslatef(0.0f, 0.0f, elements[i][2]);
			if ( rotation_effet == 2 )
			{
				glRotatef(elements[i][1]*30, 0.0, 0.5, 0.0);
			} 
			glColor4f(1.0f,1.0f,1.0f,1.0f);
			glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
			glBegin(GL_QUADS);
			glTexCoord2f(size_f_001, size_f_002);
			glVertex3f(elements[i][0]*wratiof, elements[i][1]-size_effet, 0.0f);
			glTexCoord2f(size_f_001, 1.0f);
			glVertex3f(elements[i][0]*wratiof, elements[i][1], 0.0f);
			glTexCoord2f(0.0f, 1.0f);
			glVertex3f((elements[i][0]-size_effet)*wratiof, elements[i][1], 0.0f);
			glTexCoord2f(0.0f, size_f_002);
			glVertex3f((elements[i][0]-size_effet)*wratiof, elements[i][1]-size_effet, 0.0f);

			glEnd();
			i++;
		}
	}
	//
	if ( emptydiapo == 0 )
	{
	 	glLoadIdentity(); // *** Renouvellement matrice ***
	// *** Transformations ***
		glTranslatef(deplacementX, deplacementY, zoom);
		glRotatef(rotationX, 1.0, 0.0, 0.0);
	   	glRotatef(rotationY, 0.0, 1.0, 0.0);
	    	glRotatef(rotationZ, 0.0, 0.0, 1.0);
	// *** Gestion de la texture ***
		//
	    	glBindTexture( GL_TEXTURE_2D, texture2 );
		glColor4f(1.0f,1.0f,1.0f,wg_percent_slide);
		glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	// *** Creation des elements du dessin ***

		switch(type3D)
		{
		case 0:
			glBegin(GL_QUADS);
	    		glTexCoord2f(size_001, size_002);
	    		glVertex3f(w_x_p * size_factor , -2.0f * size_factor , 0.0f);

	    		glTexCoord2f(size_001, 1.0f);
	    		glVertex3f(w_x_p * size_factor , 2.0f * size_factor , 0.0f);

	    		glTexCoord2f(0.0f, 1.0f);
	    		glVertex3f(w_x_m * size_factor , 2.0f * size_factor , 0.0f);

	    		glTexCoord2f(0.0f, size_002);
	    		glVertex3f(w_x_m * size_factor , -2.0f * size_factor , 0.0f);
			break;
		case 1:
			glBegin(GL_QUADS);
			for( x = 0; x < 44; x++ )	
			{
				for( y = 0; y < 44; y++ )
				{
					float_x = (float(x)/44)*size_001;
					float_y = (float(y*(1-size_002))/44)+size_002;	
					float_xb = (float(x+1)/44)*size_001;	
					float_yb = (float((y+1)*(1-size_002))/44)+size_002;
					glTexCoord2f( float_x, float_y);
					glVertex3f( points[x][y][0] * size_factor , points[x][y][1] * size_factor , points[x][y][2] * size_factor  );
	
					glTexCoord2f( float_x, float_yb );
					glVertex3f( points[x][y+1][0] * size_factor , points[x][y+1][1] * size_factor , points[x][y+1][2] * size_factor  );
			
					glTexCoord2f( float_xb, float_yb );
					glVertex3f( points[x+1][y+1][0] * size_factor , points[x+1][y+1][1] * size_factor , points[x+1][y+1][2] * size_factor  );
			
					glTexCoord2f( float_xb, float_y );
					glVertex3f( points[x+1][y][0] * size_factor , points[x+1][y][1] * size_factor , points[x+1][y][2] * size_factor  );
				}
			}
			break;
		case 2:
			glBegin(GL_QUADS);
			// *** FACE ARRIERE ***
			glTexCoord2f(size_001, size_002); 
			glVertex3f(-1.0f * size_factor * wratioimg, -1.0f * size_factor, -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(size_001, 1.0f); 
			glVertex3f(-1.0f * size_factor * wratioimg,  1.0f * size_factor, -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(0.0f, 1.0f); 
			glVertex3f( 1.0f * size_factor * wratioimg,  1.0f * size_factor, -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(0.0f, size_002); 
			glVertex3f( 1.0f * size_factor * wratioimg, -1.0f * size_factor, -1.0f * size_factor * (wratioimg/2) );
			// *** FACE DU HAUT ***
			glTexCoord2f(0.0f, 1.0f); 
			glVertex3f(-1.0f * size_factor * wratioimg,  1.0f * size_factor , -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(0.0f, size_002); 
			glVertex3f(-1.0f * size_factor * wratioimg,  1.0f * size_factor ,  1.0f * size_factor );
			glTexCoord2f(size_001, size_002); 
			glVertex3f( 1.0f * size_factor * wratioimg,  1.0f * size_factor ,  1.0f * size_factor );
			glTexCoord2f(size_001, 1.0f); 
			glVertex3f( 1.0f * size_factor * wratioimg,  1.0f * size_factor , -1.0f * size_factor * (wratioimg/2) );
			// *** FACE DU BAS ***
			glTexCoord2f(size_001, 1.0f); 
			glVertex3f(-1.0f * size_factor * wratioimg , -1.0f * size_factor , -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(0.0f, 1.0f); 
			glVertex3f( 1.0f * size_factor * wratioimg , -1.0f * size_factor , -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(0.0f, size_002); 
			glVertex3f( 1.0f * size_factor * wratioimg , -1.0f * size_factor ,  1.0f * size_factor );
			glTexCoord2f(size_001, size_002);
			glVertex3f(-1.0f * size_factor * wratioimg , -1.0f * size_factor ,  1.0f * size_factor );
			// *** FACE DE GAUCHE ***
			glTexCoord2f(0.0f, size_002); 
			glVertex3f(-1.0f * size_factor * wratioimg , -1.0f * size_factor, -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(size_001, size_002); 
			glVertex3f(-1.0f * size_factor * wratioimg , -1.0f * size_factor,  1.0f * size_factor );
			glTexCoord2f(size_001, 1.0f); 
			glVertex3f(-1.0f * size_factor * wratioimg ,  1.0f * size_factor,  1.0f * size_factor );
			glTexCoord2f(0.0f, 1.0f); 
			glVertex3f(-1.0f * size_factor * wratioimg ,  1.0f * size_factor, -1.0f * size_factor * (wratioimg/2) );
			// *** FACE DE DROITE ***
			glTexCoord2f(size_001, 	size_002); 
			glVertex3f( 1.0f * size_factor * wratioimg , -1.0f * size_factor , -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(size_001, 1.0f); 
			glVertex3f( 1.0f * size_factor * wratioimg ,  1.0f * size_factor , -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(0.0f, 1.0f); 
			glVertex3f( 1.0f * size_factor * wratioimg ,  1.0f * size_factor ,  1.0f * size_factor );
			glTexCoord2f(0.0f, size_002); 
			glVertex3f( 1.0f * size_factor * wratioimg , -1.0f * size_factor ,  1.0f * size_factor );
			// *** FACE AVANT ***
			glTexCoord2f(0.0f, size_002); 
			glVertex3f(-1.0f * size_factor * wratioimg , -1.0f * size_factor ,  1.0f * size_factor );
			glTexCoord2f(size_001, size_002); 
			glVertex3f( 1.0f * size_factor * wratioimg , -1.0f * size_factor ,  1.0f * size_factor );
			glTexCoord2f(size_001, 1.0f); 
			glVertex3f( 1.0f * size_factor * wratioimg ,  1.0f * size_factor ,  1.0f * size_factor );
			glTexCoord2f(0.0f, 1.0f); 
			glVertex3f(-1.0f * size_factor * wratioimg ,  1.0f * size_factor ,  1.0f * size_factor );
			//
			break;
		case 3:
			glBegin(GL_QUADS);
			for(z=0; z<45; z++)
			{
				oldpoints[z]=points[0][z][2];
			}
			for(z=0; z<45; z++)
			{
				for(int y=0; y<45; y++)
				{
					//points[z][y][2]=float(sin((((z/3.0f)*40.0f)/360.0f)*3.141592654*sin(myvariance)));
					if ( z < 44)
					{
						points[z][y][2]=points[z+1][y][2];
					}
					else
					{
						points[z][y][2]=oldpoints[z];
					}
				}
			}
			for( x = 0; x < 44; x++ )			
			{
				for( y = 0; y < 44; y++ )		
				{
					float_x = (float(x)/44)*size_001;
					float_y = (float(y*(1-size_002))/44)+size_002;	
					float_xb = (float(x+1)/44)*size_001;		
					float_yb = (float((y+1)*(1-size_002))/44)+size_002;	
					glTexCoord2f( float_x, float_y);
					glVertex3f( points[x][y][0] * size_factor , points[x][y][1] * size_factor , points[x][y][2] * size_factor );
		
					glTexCoord2f( float_x, float_yb );
					glVertex3f( points[x][y+1][0] * size_factor , points[x][y+1][1] * size_factor , points[x][y+1][2] * size_factor );
			
					glTexCoord2f( float_xb, float_yb );
					glVertex3f( points[x+1][y+1][0] * size_factor , points[x+1][y+1][1] * size_factor , points[x+1][y+1][2] * size_factor );
			
					glTexCoord2f( float_xb, float_y );
					glVertex3f( points[x+1][y][0] * size_factor , points[x+1][y][1] * size_factor , points[x+1][y][2] * size_factor );
				}
			}
			break;
		case 4:
			glBegin(GL_QUADS);
			glTexCoord2f(size_001, size_002);
			glVertex3f(w_x_p * size_factor , -2.0f * size_factor , 0.0f);
			glTexCoord2f(size_001, size_002 + ((1-size_002)/2));
			glVertex3f(w_x_p * size_factor , -0.1f * size_factor, 0.0f);
			glTexCoord2f(size_001/2, size_002 + ((1-size_002)/2));
			glVertex3f(0.1f * size_factor, -0.1f * size_factor, 0.0f);
			glTexCoord2f(size_001/2, size_002);
			glVertex3f(0.1f * size_factor, -2.0f * size_factor, 0.0f);
			//
			glTexCoord2f(size_001, size_002 + ((1-size_002)/2));
			glVertex3f(w_x_p * size_factor , 0.1f * size_factor, 0.0f);
			glTexCoord2f(size_001, 1.0f);
			glVertex3f(w_x_p * size_factor , 2.0f * size_factor , 0.0f);
			glTexCoord2f(size_001/2, 1.0f);
			glVertex3f(0.1f * size_factor, 2.0f  * size_factor, 0.0f);
			glTexCoord2f(size_001/2, size_002 + ((1-size_002)/2));
			glVertex3f(0.1f * size_factor, 0.1f * size_factor , 0.0f);
			//
			glTexCoord2f(size_001/2, size_002 + ((1-size_002)/2));
			glVertex3f(-0.1f * size_factor, 0.1f * size_factor, 0.0f);
			glTexCoord2f(size_001/2, 1.0f);
			glVertex3f(-0.1f * size_factor, 2.0f * size_factor , 0.0f);
			glTexCoord2f(0.0f, 1.0f);
			glVertex3f(w_x_m  * size_factor, 2.0f * size_factor , 0.0f);
			glTexCoord2f(0.0f, size_002 + ((1-size_002)/2));
			glVertex3f(w_x_m  * size_factor, 0.1f * size_factor, 0.0f);
			//
			glTexCoord2f(size_001/2, size_002);
			glVertex3f(-0.1f * size_factor, -2.0f * size_factor , 0.0f);
			glTexCoord2f(size_001/2, size_002 + ((1-size_002)/2));
			glVertex3f(-0.1f * size_factor, -0.1f * size_factor, 0.0f);
			glTexCoord2f(0.0f, size_002 + ((1-size_002)/2));
			glVertex3f(w_x_m * size_factor , -0.1f * size_factor, 0.0f);
			glTexCoord2f(0.0f, size_002);
			glVertex3f(w_x_m * size_factor , -2.0f * size_factor , 0.0f);
			break;
		case 5:
			glBegin(GL_QUADS);
			glTexCoord2f(size_001, size_002); // A
			glVertex3f((w_x_p * size_factor)/2, -2.0f * size_factor , 0.0f);

			glTexCoord2f(size_001, 1.0f); // B
			glVertex3f((w_x_p * size_factor)/2, 2.0f * size_factor , 0.0f);

			glTexCoord2f(size_001/2, 1.0f); // C
			glVertex3f((w_x_m * size_factor)/2, 2.0f * size_factor , 0.0f);

			glTexCoord2f(size_001/2, size_002); // D
			glVertex3f((w_x_m * size_factor)/2, -2.0f * size_factor , 0.0f);
			//
			glTexCoord2f(0.0f, size_002); // A
			glVertex3f((w_x_p * size_factor)/2, -2.0f * size_factor , -0.01f);

			glTexCoord2f(0.0f, 1.0f); // B
			glVertex3f((w_x_p * size_factor)/2, 2.0f * size_factor , -0.01f);

			glTexCoord2f(size_001/2, 1.0f); // C
			glVertex3f((w_x_m * size_factor)/2, 2.0f * size_factor , -0.01f);

			glTexCoord2f(size_001/2, size_002); // D
			glVertex3f((w_x_m * size_factor)/2, -2.0f * size_factor , -0.01f);
			break;
		case 6:
			glBegin(GL_QUADS);
			glTexCoord2f(size_001, size_002 + ((1-size_002)/2)); // A
			glVertex3f(w_x_p * size_factor , (-2.0f * size_factor )/2, 0.0f);

			glTexCoord2f(size_001, 1.0f); // B
			glVertex3f(w_x_p * size_factor , (2.0f * size_factor )/2, 0.0f);

			glTexCoord2f(0.0f, 1.0f); // C
			glVertex3f(w_x_m * size_factor , (2.0f * size_factor )/2, 0.0f);

			glTexCoord2f(0.0f, size_002 + ((1-size_002)/2)); // D
			glVertex3f(w_x_m * size_factor , (-2.0f * size_factor )/2, 0.0f);
			//
			glTexCoord2f(size_001, size_002); // A
			glVertex3f(w_x_p * size_factor , (-2.0f * size_factor )/2, -0.01f);

			glTexCoord2f(size_001, size_002 + ((1-size_002)/2)); // B
			glVertex3f(w_x_p * size_factor , (2.0f * size_factor )/2, -0.01f);

			glTexCoord2f(0.0f, size_002 + ((1-size_002)/2)); // C
			glVertex3f(w_x_m * size_factor , (2.0f * size_factor )/2, -0.01f);

			glTexCoord2f(0.0f, size_002); // D
			glVertex3f(w_x_m * size_factor , (-2.0f * size_factor )/2, -0.01f);
			break;
		case 7:
			glBegin(GL_QUADS);
			glTexCoord2f(size_001, size_002); // A
			glVertex3f((w_x_p * size_factor ), -2.0f * size_factor , 0.0f);

			glTexCoord2f(size_001, 1.0f); // B
			glVertex3f((w_x_p * size_factor ), 2.0f * size_factor , 0.0f);

			glTexCoord2f(size_001/2, 1.0f); // C
			glVertex3f(0.0f, 2.0f * size_factor , -0.8f * size_factor);

			glTexCoord2f(size_001/2, size_002); // D
			glVertex3f(0.0f, -2.0f * size_factor , -0.8f * size_factor);
			//
			glTexCoord2f(size_001/2, size_002); // D
			glVertex3f(0.0f, -2.0f * size_factor , -0.8f * size_factor);

			glTexCoord2f(size_001/2, 1.0f); // C
			glVertex3f(0.0f, 2.0f * size_factor , -0.8f * size_factor);

			glTexCoord2f(0.0f, 1.0f); // B
			glVertex3f((w_x_m * size_factor ), 2.0f * size_factor , 0.0f);

			glTexCoord2f(0.0f, size_002); // A
			glVertex3f((w_x_m * size_factor ), -2.0f * size_factor , 0.0f);
			break;
		case 8:
			glBegin(GL_QUADS);
	    		glTexCoord2f(size_001, size_002);
	    		glVertex3f(w_x_p * size_factor , -2.0f * size_factor , 0.0f);

	    		glTexCoord2f(size_001, 1.0f);
	    		glVertex3f(w_x_p * size_factor , 2.0f * size_factor , 0.0f);

	    		glTexCoord2f(0.0f, 1.0f);
	    		glVertex3f(w_x_m * size_factor , 2.0f * size_factor , 0.0f);

	    		glTexCoord2f(0.0f, size_002);
	    		glVertex3f(w_x_m * size_factor , -2.0f * size_factor , 0.0f);
			glEnd();
			//
	    		glBindTexture( GL_TEXTURE_2D, texture6 );
			glColor4f(1.0f,1.0f,1.0f,wg_percent_slide);
			glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
			glBegin(GL_QUADS);
	    		glTexCoord2f(size_001, size_002);
	    		glVertex3f(w_x_p * size_factor , -6.0f * size_factor , 0.0f);

	    		glTexCoord2f(size_001, 1.0f);
	    		glVertex3f(w_x_p * size_factor , -2.0f * size_factor , 0.0f);

	    		glTexCoord2f(0.0f, 1.0f);
	    		glVertex3f(w_x_m * size_factor , -2.0f * size_factor , 0.0f);

	    		glTexCoord2f(0.0f, size_002);
	    		glVertex3f(w_x_m * size_factor , -6.0f * size_factor , 0.0f);
			break;
		case 9:
			glBegin(GL_QUADS);
			// *** FACE ARRIERE ***
			glTexCoord2f(size_001, size_002); 
			glVertex3f(-1.0f * size_factor * wratioimg, -1.0f * size_factor, -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(size_001, 1.0f); 
			glVertex3f(-1.0f * size_factor * wratioimg,  1.0f * size_factor, -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(0.0f, 1.0f); 
			glVertex3f( 1.0f * size_factor * wratioimg,  1.0f * size_factor, -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(0.0f, size_002); 
			glVertex3f( 1.0f * size_factor * wratioimg, -1.0f * size_factor, -1.0f * size_factor * (wratioimg/2) );
			// *** FACE DU HAUT ***
			glTexCoord2f(0.0f, 1.0f); 
			glVertex3f(-1.0f * size_factor * wratioimg,  1.0f * size_factor , -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(0.0f, size_002); 
			glVertex3f(-1.0f * size_factor * wratioimg,  1.0f * size_factor ,  1.0f * size_factor );
			glTexCoord2f(size_001, size_002); 
			glVertex3f( 1.0f * size_factor * wratioimg,  1.0f * size_factor ,  1.0f * size_factor );
			glTexCoord2f(size_001, 1.0f); 
			glVertex3f( 1.0f * size_factor * wratioimg,  1.0f * size_factor , -1.0f * size_factor * (wratioimg/2) );
			// *** FACE DU BAS ***
			glTexCoord2f(size_001, 1.0f); 
			glVertex3f(-1.0f * size_factor * wratioimg , -1.0f * size_factor , -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(0.0f, 1.0f); 
			glVertex3f( 1.0f * size_factor * wratioimg , -1.0f * size_factor , -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(0.0f, size_002); 
			glVertex3f( 1.0f * size_factor * wratioimg , -1.0f * size_factor ,  1.0f * size_factor );
			glTexCoord2f(size_001, size_002);
			glVertex3f(-1.0f * size_factor * wratioimg , -1.0f * size_factor ,  1.0f * size_factor );
			// *** FACE DE GAUCHE ***
			glTexCoord2f(0.0f, size_002); 
			glVertex3f(-1.0f * size_factor * wratioimg , -1.0f * size_factor, -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(size_001, size_002); 
			glVertex3f(-1.0f * size_factor * wratioimg , -1.0f * size_factor,  1.0f * size_factor );
			glTexCoord2f(size_001, 1.0f); 
			glVertex3f(-1.0f * size_factor * wratioimg ,  1.0f * size_factor,  1.0f * size_factor );
			glTexCoord2f(0.0f, 1.0f); 
			glVertex3f(-1.0f * size_factor * wratioimg ,  1.0f * size_factor, -1.0f * size_factor * (wratioimg/2) );
			// *** FACE DE DROITE ***
			glTexCoord2f(size_001, 	size_002); 
			glVertex3f( 1.0f * size_factor * wratioimg , -1.0f * size_factor , -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(size_001, 1.0f); 
			glVertex3f( 1.0f * size_factor * wratioimg ,  1.0f * size_factor , -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(0.0f, 1.0f); 
			glVertex3f( 1.0f * size_factor * wratioimg ,  1.0f * size_factor ,  1.0f * size_factor );
			glTexCoord2f(0.0f, size_002); 
			glVertex3f( 1.0f * size_factor * wratioimg , -1.0f * size_factor ,  1.0f * size_factor );
			// *** FACE AVANT ***
			glTexCoord2f(0.0f, size_002); 
			glVertex3f(-1.0f * size_factor * wratioimg , -1.0f * size_factor ,  1.0f * size_factor );
			glTexCoord2f(size_001, size_002); 
			glVertex3f( 1.0f * size_factor * wratioimg , -1.0f * size_factor ,  1.0f * size_factor );
			glTexCoord2f(size_001, 1.0f); 
			glVertex3f( 1.0f * size_factor * wratioimg ,  1.0f * size_factor ,  1.0f * size_factor );
			glTexCoord2f(0.0f, 1.0f); 
			glVertex3f(-1.0f * size_factor * wratioimg ,  1.0f * size_factor ,  1.0f * size_factor );
			glEnd();
			//
	    		glBindTexture( GL_TEXTURE_2D, texture6 );
			glColor4f(1.0f,1.0f,1.0f,wg_percent_slide);
			glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
			glBegin(GL_QUADS);
			// *** FACE ARRIERE ***
			glTexCoord2f(size_001, size_002); 
			glVertex3f(-1.0f * size_factor * wratioimg , -3.0f * size_factor , -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(size_001, 1.0f); 
			glVertex3f(-1.0f * size_factor * wratioimg , -1.0f * size_factor , -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(0.0f, 1.0f); 
			glVertex3f( 1.0f * size_factor * wratioimg , -1.0f * size_factor , -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(0.0f, size_002); 
			glVertex3f( 1.0f * size_factor * wratioimg , -3.0f * size_factor , -1.0f * size_factor * (wratioimg/2) );
			// *** FACE DE GAUCHE ***
			glTexCoord2f(0.0f, size_002); 
			glVertex3f(-1.0f * size_factor * wratioimg , -3.0f * size_factor , -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(size_001, size_002); 
			glVertex3f(-1.0f * size_factor * wratioimg , -3.0f * size_factor ,  1.0f * size_factor );
			glTexCoord2f(size_001, 1.0f); 
			glVertex3f(-1.0f * size_factor * wratioimg ,  -1.0f * size_factor ,  1.0f * size_factor );
			glTexCoord2f(0.0f, 1.0f); 
			glVertex3f(-1.0f * size_factor * wratioimg ,  -1.0f * size_factor , -1.0f * size_factor * (wratioimg/2) );
			// *** FACE DE DROITE ***
			glTexCoord2f(size_001, 	size_002); 
			glVertex3f( 1.0f * size_factor * wratioimg , -3.0f * size_factor , -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(size_001, 1.0f); 
			glVertex3f( 1.0f * size_factor * wratioimg ,  -1.0f * size_factor , -1.0f * size_factor * (wratioimg/2) );
			glTexCoord2f(0.0f, 1.0f); 
			glVertex3f( 1.0f * size_factor * wratioimg ,  -1.0f * size_factor ,  1.0f * size_factor );
			glTexCoord2f(0.0f, size_002); 
			glVertex3f( 1.0f * size_factor * wratioimg , -3.0f * size_factor ,  1.0f * size_factor );
			// *** FACE AVANT ***
			glTexCoord2f(0.0f, size_002); 
			glVertex3f(-1.0f * size_factor * wratioimg , -3.0f * size_factor ,  1.0f * size_factor );
			glTexCoord2f(size_001, size_002);
			glVertex3f( 1.0f * size_factor * wratioimg , -3.0f * size_factor ,  1.0f * size_factor );
			glTexCoord2f(size_001, 1.0f); 
			glVertex3f( 1.0f * size_factor * wratioimg ,  -1.0f * size_factor ,  1.0f * size_factor );
			glTexCoord2f(0.0f, 1.0f); 
			glVertex3f(-1.0f * size_factor * wratioimg ,  -1.0f * size_factor ,  1.0f * size_factor );
			//
			break;
		}
		//
	    	glEnd();
	}
	//
	if ( isbackanim == 0 && iseffect > 0 )
	{
		glLoadIdentity(); // *** Renouvellement matrice ***
		glTranslatef(posanim_x, posanim_y, -2.1f); //-2.01f
    		glRotatef(-rotanim, 0.0, 0.0, 1.0);
		glColor4f(1.0f,1.0f,1.0f,wg_percent);
		glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glBindTexture( GL_TEXTURE_2D, texture3 );
		glBegin(GL_QUADS);
		glTexCoord2f(size_003, size_004);
    		glVertex3f(1.21f * sizanim, -(1.21f/ratioeffet) * sizanim, 0.0f); //1.128
		glTexCoord2f(size_003, 1.0f);
    		glVertex3f(1.21f * sizanim, (1.21f/ratioeffet) * sizanim, 0.0f);
		glTexCoord2f(0.0f, 1.0f);
    		glVertex3f(-1.21f * sizanim, (1.21f/ratioeffet) * sizanim, 0.0f);
		glTexCoord2f(0.0f, size_004);
    		glVertex3f(-1.21f * sizanim, -(1.21f/ratioeffet) * sizanim, 0.0f);
    		glEnd();
	}
	// *** INSERTION DU DESSIN ***
	if ( isdraw == 1 )
	{
		glLoadIdentity(); // *** Renouvellement matrice ***
		glTranslatef(0.0f, 0.0f, -2.00f);
		glBindTexture( GL_TEXTURE_2D, texture5 );
		//glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glBegin(GL_QUADS);

		if ( is43 == 1 )
		{

			glTexCoord2f(0.703125f, 0.4375f);
	    		glVertex3f(1.32f, -1.056f, 0.0f);
			glTexCoord2f(0.703125f, 1.0f);
	    		glVertex3f(1.32f, 1.056f, 0.0f);
			glTexCoord2f(0.0f, 1.0f);
	    		glVertex3f(-1.32f, 1.056f, 0.0f);
			glTexCoord2f(0.0f, 0.4375f);
	    		glVertex3f(-1.32f, -1.056f, 0.0f);
		}
		else
		{
			if ( is43 == 0 )
			{
				glTexCoord2f(1.0f, 0.4375f);
		    		glVertex3f(1.873f, -1.051f, 0.0f);
				glTexCoord2f(1.0f, 1.0f);
		    		glVertex3f(1.873f, 1.051f, 0.0f);
				glTexCoord2f(0.0f, 1.0f);
		    		glVertex3f(-1.873f, 1.051f, 0.0f);
				glTexCoord2f(0.0f, 0.4375f);
		    		glVertex3f(-1.873f, -1.051f, 0.0f);
			}
			else
			{
				glTexCoord2f(0.703125f, 0.53125f);
		    		glVertex3f(1.58f, -1.053f, 0.0f);
				glTexCoord2f(0.703125f, 1.0f);
		    		glVertex3f(1.58f, 1.053f, 0.0f);
				glTexCoord2f(0.0f, 1.0f);
		    		glVertex3f(-1.58f, 1.053f, 0.0f);
				glTexCoord2f(0.0f, 0.53125f);
		    		glVertex3f(-1.58f, -1.053f, 0.0f);
			}
		}

		glEnd();
	}
	// *** INSERTION DE LA LEGENDE ***
	if ( state_mode == 1 && progress <= wg_cpt_002 )
	{
		if ( wg_percent_trans > 0 )
		{
			glLoadIdentity(); // *** Renouvellement matrice ***
			if ( is43 < 2 )
			{
				glTranslatef(posxleg, posyleg-((GLfloat)((GLfloat)hauteur_leg*(GLfloat)1.046)/(GLfloat)576), -1.99f);
			}
			else
			{
				glTranslatef(posxleg, posyleg-((GLfloat)((GLfloat)hauteur_leg*(GLfloat)1.046)/(GLfloat)480), -1.99f);
			}
			glBindTexture( GL_TEXTURE_2D, texture4 );
			glColor4f(1.0f,1.0f,1.0f,wg_percent_trans);
			glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
			glBegin(GL_QUADS);

			if ( is43 == 1 )
			{
				glTexCoord2f(sizexleg, sizeyleg);
		    		glVertex3f(1.308f, -((GLfloat)((GLfloat)hauteur_leg*(GLfloat)1.046)/(GLfloat)576), 0.0f);
				glTexCoord2f(sizexleg, 1.0f);
		    		glVertex3f(1.308f, ((GLfloat)((GLfloat)hauteur_leg*(GLfloat)1.046)/(GLfloat)576), 0.0f);
				glTexCoord2f(0.0f, 1.0f);
		    		glVertex3f(-3.924f, ((GLfloat)((GLfloat)hauteur_leg*(GLfloat)1.046)/(GLfloat)576), 0.0f);
				glTexCoord2f(0.0f, sizeyleg);
		    		glVertex3f(-3.924f, -((GLfloat)((GLfloat)hauteur_leg*(GLfloat)1.046)/(GLfloat)576), 0.0f);
			}
			else
			{
				if ( is43 == 0 )
				{
					glTexCoord2f(sizexleg, sizeyleg);
			    		glVertex3f(1.860f, -((GLfloat)((GLfloat)hauteur_leg*(GLfloat)1.051)/(GLfloat)576), 0.0f); //1.867
					glTexCoord2f(sizexleg, 1.0f);
			    		glVertex3f(1.860f, ((GLfloat)((GLfloat)hauteur_leg*(GLfloat)1.051)/(GLfloat)576), 0.0f);
					glTexCoord2f(0.0f, 1.0f);
			    		glVertex3f(-5.580f, ((GLfloat)((GLfloat)hauteur_leg*(GLfloat)1.051)/(GLfloat)576), 0.0f);
					glTexCoord2f(0.0f, sizeyleg);
			    		glVertex3f(-5.580f, -((GLfloat)((GLfloat)hauteur_leg*(GLfloat)1.051)/(GLfloat)576), 0.0f); //5.601
				}
				else
				{
					glTexCoord2f(sizexleg, sizeyleg);
			    		glVertex3f(1.57f, -((GLfloat)((GLfloat)hauteur_leg*(GLfloat)1.046)/(GLfloat)480), 0.0f);
					glTexCoord2f(sizexleg, 1.0f);
			    		glVertex3f(1.57f, ((GLfloat)((GLfloat)hauteur_leg*(GLfloat)1.046)/(GLfloat)480), 0.0f);
					glTexCoord2f(0.0f, 1.0f);
			    		glVertex3f(-4.71f, ((GLfloat)((GLfloat)hauteur_leg*(GLfloat)1.046)/(GLfloat)480), 0.0f);
					glTexCoord2f(0.0f, sizeyleg);
			    		glVertex3f(-4.71f, -((GLfloat)((GLfloat)hauteur_leg*(GLfloat)1.046)/(GLfloat)480), 0.0f);
				}
			}
			glEnd();
		}
	}

	if ( affiche_grille == 1 )
	{
		glLoadIdentity(); // *** Renouvellement matrice ***
		glBindTexture( GL_TEXTURE_2D, texture7 );
		glTranslatef(-1.870f, -1.051f, -1.99f);
		glColor4f(1.0f,1.0f,1.0f,1.0f);
		//glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glBegin(GL_LINES);

		for (int i=0; i<=20; i++) 
		{
			glVertex3f(0, (float)i/(float)10,0);
			glVertex3f(4, (float)i/(float)10,0);
		}

		for (int j=0; j<=36; j++) 
		{
			glVertex3f((float)j/(float)10, 0,0);
			glVertex3f((float)j/(float)10, 4,0);
		}
		glEnd();
	}

	if ( ismblur == 1 )
	{
		if ( bcle_render == 1 )
		{
			glClear(GL_ACCUM_BUFFER_BIT);
			glAccum(GL_LOAD, 1.0);
			bcle_render = 2;
		}
		else
		{
			if ( bcle_render == 2 )
			{
				glAccum(GL_ACCUM, 0.1);
				glAccum(GL_MULT, 0.9);
				glAccum(GL_RETURN, 1.0);
			}
		}
	}
	glFlush();
}

void Tetrahedron::grabframe(QString pathimg)
{
	QImage myimg = this->grabFrameBuffer ( false );
	myimg.save( pathimg ,"JPEG", 100 );
}

