/***************************************************************************
 *   Copyright (C) 2004-2005 by                                            *
 *     Paolo Sacconier   <axa1981@tin.it>                                  *
 *     Francesco Tamagni <minchiahead@hacari.org>                          *
 *                                                                         *
 *   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 of the License, 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.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "overlay.h"

namespace gillo {

Overlay::Overlay() {
    
}

Overlay::~Overlay() {
    // @FIXME
/*    list<Rect*>::iterator i = this->rects.begin();
    while( i != this->rects.end() ) {
        delete (*i);
        i++;
    }*/
	printf("Overlay(%p): destroyed\n",this);
}

void Overlay::draw(int w, int h) {
	if (rects.size() == 0)
		return;
  
	glPushAttrib   ( GL_ENABLE_BIT | GL_VIEWPORT_BIT | GL_TRANSFORM_BIT | GL_LIGHTING_BIT ) ;
	glDisable      ( GL_LIGHTING   ) ;
	glDisable      ( GL_FOG        ) ;
	glDisable      ( GL_TEXTURE_2D ) ;
	glDisable      ( GL_DEPTH_TEST ) ;
	glDisable      ( GL_CULL_FACE  ) ;
	glEnable       ( GL_ALPHA_TEST ) ;
	glEnable       ( GL_BLEND ) ;
	glAlphaFunc    ( GL_GREATER, 0.1f ) ;
	glBlendFunc    ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
	
	glViewport     ( 0, 0, w, h ) ;
	glMatrixMode   ( GL_PROJECTION ) ;
	glPushMatrix   () ;
	glLoadIdentity () ;
	gluOrtho2D     ( 0, 1, 0, 1 ) ;
	glMatrixMode   ( GL_MODELVIEW ) ;
	glPushMatrix   () ;
	glLoadIdentity () ;
    
    list<Rect*>::iterator i = this->rects.begin();
    while( i != this->rects.end() ) {
        (*i)->draw();
        i++;
    }
  
	glMatrixMode   ( GL_PROJECTION ) ;
	glPopMatrix    () ;
	glMatrixMode   ( GL_MODELVIEW ) ;
	glPopMatrix    () ;
	glPopAttrib    () ;
    
/*	glEnable(GL_DEPTH_TEST);
    glEnable(GL_LIGHTING);
    glEnable(GL_DEPTH_TEST);*/
}

}
