/*   EXTRAITS DE LA LICENCE
	Copyright CEA, contributeurs : Luc BILLARD, Damien
	CALISTE, Olivier D'Astier, laboratoire L_Sim, (2001-2006)
  
	Adresses mèl :
	BILLARD, non joignable par mèl ;
	CALISTE, damien P caliste AT cea P fr.
	D'ASTIER, dastier AT iie P cnam P fr.

	Ce logiciel est un programme informatique servant à visualiser des
	structures atomiques dans un rendu pseudo-3D. 

	Ce logiciel est régi par la licence CeCILL soumise au droit français et
	respectant les principes de diffusion des logiciels libres. Vous pouvez
	utiliser, modifier et/ou redistribuer ce programme sous les conditions
	de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA 
	sur le site "http://www.cecill.info".

	Le fait que vous puissiez accéder à cet en-tête signifie que vous avez 
	pris connaissance de la licence CeCILL, et que vous en avez accepté les
	termes (cf. le fichier Documentation/licence.fr.txt fourni avec ce logiciel).
*/

/*   LICENCE SUM UP
	Copyright CEA, contributors : Luc BILLARD and Damien
	CALISTE and Olivier D'Astier, laboratoire L_Sim, (2001-2006)

	E-mail addresses :
	BILLARD, not reachable any more ;
	CALISTE, damien P caliste AT cea P fr.
	D'ASTIER, dastier AT iie P cnam P fr.

	This software is a computer program whose purpose is to visualize atomic
	configurations in 3D.

	This software is governed by the CeCILL  license under French law and
	abiding by the rules of distribution of free software.  You can  use, 
	modify and/ or redistribute the software under the terms of the CeCILL
	license as circulated by CEA, CNRS and INRIA at the following URL
	"http://www.cecill.info". 

	The fact that you are presently reading this means that you have had
	knowledge of the CeCILL license and that you accept its terms. You can
	find a copy of this licence shipped with this software at Documentation/licence.en.txt.
*/

#ifndef SURFACES_H
#define SURFACES_H

#include <GL/gl.h>
#include <GL/glu.h> 

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <glib.h>

#include <openGLFunctions/view.h>
#include <visu_data.h>

/* max length of surface name */
/* #define vgl_MAX_SURF_NAME_LENGTH 256 */
/* CAUTION: corresponding (char *) variables should have size 
   vgl_MAX_SURF_NAME_LENGTH + 1
   to accomodate final \0 */

typedef struct surf_res_ {
  gboolean rendered;
  /*  float red;
  float green;
  float blue;
  float alpha;
  float ambient;
  float diffuse;
  float shininess;
  float specular;
  float emission;*/
  float material[9];
} surf_res;

gpointer isosurfaces_resources_get(const gchar *surf_name);
gboolean isosurfaces_read_resources(gchar **lines, int nbLines, int position, GString *errorMessage);
gboolean isosurfaces_export_resources(GString *data, int *nbLinesWritten);


/** 
 * vgl_load_surfaces:
 * @fich : target file to load
 * @buf : a buffer to store errors
 *
 * This loads a surface file and set default material properties for it.
 * See surf file specifications.
 *
 * Return value: 0 in case of success, n != 0 otherwise. In case of error,
 * @buf will be filled with some error info.
 *
 */
int vgl_load_surfaces(const char *fich, GString *buf);

void isoSurfacesSet_fitToBox(VisuData *data);


/** 
 * vgl_get_surfaces_number:
 * @surfaces_number: an allocated int.
 *
 * Stores the current number of surfaces in the given int.
 *
 */
void vgl_get_surfaces_number(int *surfaces_number);

/**
 * vgl_get_surface_name:
 * @surf_index: the number of the surface
 * 
 * This returns for the given surf_index its name 
 * (1 <= surf_index <= surfaces_number) 
 *
 * Return value: the name of the surface or empty name or NULL, if surf_index is invalid
 */
const char* vgl_get_surface_name(int surf_index);

/**
 * vgl_get_surface_index:
 * @name: the surface name
 *
 * stores the index of the surface which name is @name
 * name should always begin with the 8 characters: surface_
 * (1 <= surf_index <= surfaces_number).
 * If the specified name matches no surface, int is set to 0.
 *
 * Returns: the number of the surface named @name
*/
int vgl_get_surface_index(const char *name);

/**
 * vgl_order_polygons:
 *
 * Re-orders the polygons in back to front order.
 * This function should be called everytime a redraw is needed.
 *
*/
void vgl_order_polygons();

/**
 * draw_surfaces:
 * @view: a #OpenGLView object that describes the rendering box.
 *
 * Rebuild each visible surface's list.
 *
 */
void draw_surfaces(OpenGLView *view);

#endif
