/*   EXTRAITS DE LA LICENCE
	Copyright CEA, contributeurs : Luc BILLARD et Damien
	CALISTE, laboratoire L_Sim, (2001-2006)
  
	Adresse mèl :
	BILLARD, non joignable par mèl ;
	CALISTE, damien P caliste AT cea 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 et Damien
	CALISTE, laboratoire L_Sim, (2001-2006)

	E-mail address:
	BILLARD, not reachable any more ;
	CALISTE, damien P caliste AT cea 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 OPENGL_H
#define OPENGL_H

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

#include <glib.h>

#include "visu_data.h"
#include "OSOpenGL/visu_OSInterface.h"
#include "openGLFunctions/light.h"
#include "openGLFunctions/view.h"

/***************/
/* Public part */
/***************/

/**
 * setOpenGLContext:
 * @contextIsPixmap: TRUE to render in a pixmap, FALSE to render to a window ;
 * @dumpData: a pointer to store a pointer to a newly created #DumpImage ;
 * @width: new width ;
 * @height: new height.
 * 
 * Use this method to change of OpenGL context. If the context is a pixmap,
 * dumpData points to a newly created description of this pixmap. The given
 * size (@width, @height) is used to set the size of the pixmap if the context
 * is indirect rendering.
 *
 * Returns: 0 if no error occured. 
 */
int setOpenGLContext(gboolean contextIsPixmap, DumpImage **dumpData,
		     guint width, guint height);

/**
 * openGLInit_context:
 *
 * Basic method to be called whenever a new context is used. It sets the
 * OpenGL variable values (enabling depth buffer...), applying light model and
 * rendering mode.
 */
void openGLInit_context();

/**
 * setOpenGlMaterial:
 * @material: a 5 elements array with the material properties ;
 * @rgba: a 4 elements array with the color values.
 *
 * This method call glMaterial to create the right shiningness, emission, diffuse...
 */
void setOpenGlMaterial(float* material, float* rgba);


/* Object to deal with quadrics. */
GLUquadricObj *obj;

/**
 * initOpengl:
 *
 * This initialises the drawing window and all the variables used
 * by this module. It must be called once by the main program and should
 * not be used otherwise.
 *
 * Returns: 1 if everything goes right.
 */
int initOpengl();

/* Objects to play with lights. */
LightEnvironnement *currentLights;


/* Draw methods */

/**
 * dumpViewToImage:
 * @dataObj: the #VisuData object to dump ;
 * @buffer: a #GString to store messages ;
 * @width: an integer used as I/O;
 * @height: an integer used as I/O.
 *
 * This method takes a screenshot of the current content of the
 * rendering window and put it in a big array. The #GString buffer
 * is used to store messages about this process. If width or height are
 * null or negative values, the current window size is used ; but if they
 * are positive, it change the size of the rendering area during the export.
 * The @width and @height values are modified by this method and the size
 * the dumped image is returned.
 *
 * Returns : a big array with all the colors of the pixels of
 * the rendering window. It returns a NULL pointer if something goes wrong.
 */
unsigned char * dumpViewToImage(VisuData *dataObj, GString *buffer, int *width, int *height);

/**
 * setAntialias:
 * @value: a boolean to activate or not the lines antialias.
 *
 * To set the antialiasing on lines.
 *
 * Returns: TRUE if the signal OpenGLAskForReDraw should be emitted.
 */
int setAntialias(int value);
/**
 * getAntialias:
 *
 * Get the value of the antialiasing parameter.
 *
 * Returns: wether or not the antialising for lines is activated.
 */
int getAntialias();

/**
 * setFakeBackingStore:
 * @bool: a boolean to activate or not the faked backing-store.
 *
 * The fake backing-store is a way to act as if there was a backing-store
 * in the Xserver. It calls a redraw each time the window receive an exposure
 * event. It is not optimized at all and can be very slow. Use it only
 * if the backing-store of the Xserver is broken or not activated.
 */
void setFakeBackingStore(int bool);
/**
 * getFakeBackingStore:
 * 
 * Get the value of the fakeBackingStore option.
 *
 * Returns: wether the faked backing-store is activated or not.
 */
int getFakeBackingStore();

/**
 * setImmediateDrawing:
 * @bool: a boolean to set or not the immediateDrawing option.
 *
 * If true all changes are applied only when the refresh button
 * is pushed.
 */
void setImmediateDrawing(int bool);
/**
 * getImmediateDrawing:
 *
 * Get the value of the immediateDrawing option.
 *
 * Returns: the value of the immediateDrawing option.
 */
int getImmediateDrawing();

/****************/
/* Private part */
/****************/


/* This variable stores the fact that OBJECT is
   allocated or not. No redraw is possible if OBJECT
   is not allocated. */
int isOBJECTReady;


gboolean exportParametersOpenGL(GString *data, int *nbLinesWritten);


void project(void);


/* redraw methods */
void reDraw(GObject *obj, gpointer data);
void drawToEmpty(void);



#endif
