/*
** vertex.h for Factory 0.1
**
** Made by caput_r and yousfi_r
** Login caput_r <caput_r@epita.fr> yousfi_r <yousfi_r@epita.fr>
**
** Started on  Tue Sep 27 01:34:52 2005 remi caput
** Last update Tue Sep 27 02:51:08 2005 remi caput
*/

#ifndef VERTEX_H_
#define VERTEX_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(__APPLE__) && defined(__MACH__)
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#endif
#include <SDL/SDL.h>

#define VTX_COUNT_BUTTON		512

#define VTX_KEY_CAPTURE() ({ gl_vertex.input.pending = 0; gl_vertex.input.last; })
#define VTX_KEY_HIT(K) ({ char pressed = gl_vertex.input.button[(int)(K)]; gl_vertex.input.button[(int)(K)] = 0; pressed; })
#define VTX_KEY_LAST() (gl_vertex.input.last)
#define VTX_KEY_PENDING() (gl_vertex.input.pending)
#define VTX_KEY_PRESSED(K) (gl_vertex.input.button[(int)(K)])
#define VTX_KEY_RESET(K) ({ gl_vertex.input.button[(int)(K)] = 0; })

enum	vtx_dimention
{
	VTX_DIMENTION_3D,
	VTX_DIMENTION_2D
};

struct				s_vertex_input
{
	unsigned int	last;
	char			button[VTX_COUNT_BUTTON];
	char			pending;
	int				mouse_x;
	int				mouse_y;
};

struct					s_vertex_screen
{
	SDL_Surface			*surface;
	enum vtx_dimention	dimention;
	int					height;
	int					width;
};

struct						s_vertex
{
	struct s_vertex_input	input;
	struct s_vertex_screen	screen;
	unsigned int			time;
	float					factor;
	float					speed;
	char					exit;
	char					ready;
};

extern struct s_vertex	gl_vertex;

int		VTX_InternalRead (FILE *, void *, size_t);
void	VTX_InternalReset (void);

float	VTX_GetFps (void);

void	VTX_SetMouse (char, char);
void	VTX_SetWindow (const char*, const char*);

int		VTX_Init (int, int, int, char);
int		VTX_Loop (GLuint);
void	VTX_ScrDimention (enum vtx_dimention);
void	VTX_ScrResize (GLuint, GLuint);
void	VTX_Stop (void);

#ifdef __cplusplus
}
#endif

#endif
