2021-12-22 02:17:16 +01:00
|
|
|
/*!\file rasterize.h
|
2021-12-22 01:57:34 +01:00
|
|
|
*
|
|
|
|
* \brief structures de données et protos de fonctions externes pour
|
|
|
|
* réaliser un moteur de rendu DIY par rastérisation.
|
|
|
|
*
|
|
|
|
* \author Farès BELHADJ, amsi@up8.edu
|
2021-12-22 02:17:16 +01:00
|
|
|
* \date November 17, 2021.
|
2021-12-31 14:48:24 +01:00
|
|
|
*/
|
2021-12-22 01:57:34 +01:00
|
|
|
|
|
|
|
#ifndef RASTERIZE_H_SEEN
|
|
|
|
# define RASTERIZE_H_SEEN
|
|
|
|
|
|
|
|
# include <GL4D/gl4dp.h>
|
|
|
|
# include <GL4D/gl4dm.h>
|
|
|
|
|
|
|
|
#include <float.h>
|
|
|
|
#define EPSILON ((double)FLT_EPSILON)
|
|
|
|
|
|
|
|
# ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
# endif
|
2021-12-22 02:17:16 +01:00
|
|
|
|
|
|
|
typedef enum pstate_t pstate_t;
|
|
|
|
typedef enum soptions_t soptions_t;
|
|
|
|
typedef struct vec4 vec4;
|
|
|
|
typedef struct vec3 vec3;
|
|
|
|
typedef struct vec2 vec2;
|
|
|
|
typedef struct vertex_t vertex_t;
|
|
|
|
typedef struct triangle_t triangle_t;
|
|
|
|
typedef struct surface_t surface_t;
|
|
|
|
|
2021-12-31 14:48:24 +01:00
|
|
|
/*!\brief États pour les sommets ou les triangles */
|
2021-12-22 02:17:16 +01:00
|
|
|
enum pstate_t {
|
|
|
|
PS_NONE = 0,
|
|
|
|
PS_TOTALLY_OUT = 1,
|
|
|
|
PS_PARTIALLY_OUT = 2,
|
|
|
|
PS_CULL = 4, /* si en BACKFACE et que
|
2021-12-31 14:48:24 +01:00
|
|
|
* SO_CULL_BACKFACES est actif */
|
2021-12-22 02:17:16 +01:00
|
|
|
PS_TOO_FAR = 8,
|
|
|
|
PS_OUT_LEFT = 16,
|
|
|
|
PS_OUT_RIGHT = 32,
|
|
|
|
PS_OUT_BOTTOM = 64,
|
|
|
|
PS_OUT_TOP = 128,
|
|
|
|
PS_OUT_NEAR = 256,
|
|
|
|
PS_OUT_FAR = 512
|
|
|
|
};
|
|
|
|
|
2021-12-31 14:48:24 +01:00
|
|
|
/*!\brief Options pour les surfaces */
|
2021-12-22 02:17:16 +01:00
|
|
|
enum soptions_t {
|
|
|
|
SO_NONE = 0, /* la surface n'a pas de rendu
|
2021-12-31 14:48:24 +01:00
|
|
|
* "couleur" */
|
2021-12-22 02:17:16 +01:00
|
|
|
SO_USE_TEXTURE = 1, /* utiliser la texture pour
|
2021-12-31 14:48:24 +01:00
|
|
|
* colorer (multiplication si
|
|
|
|
* SO_USE_COLOR est actif) */
|
2021-12-22 02:17:16 +01:00
|
|
|
SO_USE_COLOR = 2, /* utiliser la couleur de la
|
2021-12-31 14:48:24 +01:00
|
|
|
* surface ou des sommets pour
|
|
|
|
* colorer (multiplication si
|
|
|
|
* SO_USE_TEXTURE est actif) */
|
2021-12-22 02:17:16 +01:00
|
|
|
SO_COLOR_MATERIAL = 4, /* utiliser la couleur aux
|
2021-12-31 14:48:24 +01:00
|
|
|
* sommets si actif
|
|
|
|
* (nécessite aussi
|
|
|
|
* l'activation de
|
|
|
|
* SO_USE_COLOR) */
|
2021-12-22 02:17:16 +01:00
|
|
|
SO_CULL_BACKFACES = 8, /* active le fait de cacher
|
2021-12-31 14:48:24 +01:00
|
|
|
* les faces arrières */
|
2021-12-22 02:17:16 +01:00
|
|
|
SO_USE_LIGHTING = 16, /* active le calcul d'ombre
|
2021-12-31 14:48:24 +01:00
|
|
|
* propre (Gouraud sur
|
|
|
|
* diffus) */
|
2021-12-22 02:17:16 +01:00
|
|
|
SO_DEFAULT = SO_CULL_BACKFACES | SO_USE_COLOR /* comportement
|
2021-12-31 14:48:24 +01:00
|
|
|
* par
|
|
|
|
* défaut */
|
2021-12-22 02:17:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct vec4 {
|
2021-12-22 01:57:34 +01:00
|
|
|
float x /* r */, y/* g */, z /* b */, w /* a */;
|
2021-12-22 02:17:16 +01:00
|
|
|
};
|
2021-12-22 01:57:34 +01:00
|
|
|
|
2021-12-22 02:17:16 +01:00
|
|
|
struct vec2 {
|
|
|
|
float x /* s */, y /* t */;
|
|
|
|
};
|
2021-12-22 01:57:34 +01:00
|
|
|
|
2021-12-22 02:17:16 +01:00
|
|
|
struct vec3 {
|
2021-12-22 01:57:34 +01:00
|
|
|
float x /* r */, y/* g */, z/* b */;
|
2021-12-22 02:17:16 +01:00
|
|
|
};
|
2021-12-22 01:57:34 +01:00
|
|
|
|
2021-12-31 14:48:24 +01:00
|
|
|
/*!\brief Sommet et l'ensemble de ses attributs */
|
2021-12-22 02:17:16 +01:00
|
|
|
struct vertex_t {
|
2021-12-22 01:57:34 +01:00
|
|
|
vec4 position;
|
|
|
|
vec4 color0;
|
|
|
|
/* début des données à partir desquelles on peut interpoler en masse */
|
|
|
|
vec2 texCoord; /* coordonnée de texture */
|
|
|
|
vec4 icolor; /* couleur à interpoler */
|
|
|
|
float li; /* intensité de lumière (lambertien) */
|
|
|
|
float zmod; /* z après modelview, sert à corriger
|
2021-12-31 14:48:24 +01:00
|
|
|
* l'interpolation par rapport à une projection en
|
|
|
|
* perspective */
|
2021-12-22 01:57:34 +01:00
|
|
|
float z; /* ce z représente la depth */
|
|
|
|
/* fin des données à partir desquelles on peut interpoler */
|
|
|
|
vec3 normal; /* interpolez les normales si vous implémentez Phong */
|
|
|
|
int x, y;
|
|
|
|
enum pstate_t state;
|
2021-12-22 02:17:16 +01:00
|
|
|
};
|
2021-12-22 01:57:34 +01:00
|
|
|
|
2021-12-31 14:48:24 +01:00
|
|
|
/*!\brief Triangle */
|
2021-12-22 02:17:16 +01:00
|
|
|
struct triangle_t {
|
2021-12-22 01:57:34 +01:00
|
|
|
vertex_t v[3];
|
2021-12-22 02:17:16 +01:00
|
|
|
vec3 normal;
|
2021-12-22 01:57:34 +01:00
|
|
|
enum pstate_t state;
|
2021-12-22 02:17:16 +01:00
|
|
|
};
|
2021-12-22 01:57:34 +01:00
|
|
|
|
2021-12-31 14:48:24 +01:00
|
|
|
/*!\brief Surface englobe plusieurs triangles et des options
|
|
|
|
* telles que le type de rendu, la couleur diffuse ou la texture. */
|
2021-12-22 02:17:16 +01:00
|
|
|
struct surface_t {
|
2021-12-22 01:57:34 +01:00
|
|
|
int n;
|
|
|
|
triangle_t * t;
|
|
|
|
GLuint tex_id;
|
|
|
|
vec4 dcolor; /* couleur diffuse, ajoutez une couleur ambiante et
|
2021-12-31 14:48:24 +01:00
|
|
|
* spéculaire si vous souhaitez compléter le
|
|
|
|
* modèle */
|
2021-12-22 01:57:34 +01:00
|
|
|
soptions_t options; /* paramétrage du rendu de la surface */
|
|
|
|
void (*interpolatefunc)(vertex_t *, vertex_t *, vertex_t *, float, float);
|
|
|
|
void (*shadingfunc)(surface_t *, GLuint *, vertex_t *);
|
2021-12-22 02:17:16 +01:00
|
|
|
};
|
|
|
|
|
2021-12-31 14:48:24 +01:00
|
|
|
/* Dans rasterize.c */
|
2021-12-22 02:17:16 +01:00
|
|
|
extern void transform_n_rasterize(surface_t * s, float * model_view_matrix, float * projection_matrix);
|
|
|
|
extern void clear_depth_map(void);
|
|
|
|
extern void set_texture(GLuint screen);
|
|
|
|
extern void updatesfuncs(surface_t * s);
|
|
|
|
|
2021-12-31 14:48:24 +01:00
|
|
|
/* Dans vtranform.c */
|
2021-12-22 02:17:16 +01:00
|
|
|
extern vertex_t vtransform(surface_t * s, vertex_t v, float * model_view_matrix, float * ti_model_view_matrix, float * projection_matrix, float * viewport);
|
|
|
|
extern void stransform(surface_t * s, float * model_view_matrix, float * projection_matrix, float * viewport);
|
|
|
|
extern void mult_matrix(float * res, float * m);
|
|
|
|
extern void translate(float * m, float tx, float ty, float tz);
|
|
|
|
extern void rotate(float * m, float angle, float x, float y, float z);
|
|
|
|
extern void scale(float * m, float sx, float sy, float sz);
|
|
|
|
extern void lookAt(float * m, float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ);
|
|
|
|
|
2021-12-31 14:48:24 +01:00
|
|
|
/* Dans surface.c */
|
2021-12-22 02:17:16 +01:00
|
|
|
extern void tnormal(triangle_t * t);
|
|
|
|
extern void snormals(surface_t * s);
|
|
|
|
extern void tnormals2vertices(surface_t * s);
|
|
|
|
extern void set_texture_id(surface_t * s, GLuint tex_id);
|
|
|
|
extern void set_diffuse_color(surface_t * s, vec4 dcolor);
|
|
|
|
extern void enable_surface_option(surface_t * s, soptions_t option);
|
|
|
|
extern void disable_surface_option(surface_t * s, soptions_t option);
|
|
|
|
extern surface_t * new_surface(triangle_t * t, int n, int duplicateTriangles, int hasNormals);
|
|
|
|
extern void free_surface(surface_t * s);
|
|
|
|
extern GLuint get_texture_from_BMP(const char * filename);
|
|
|
|
|
2021-12-31 14:48:24 +01:00
|
|
|
/* Dans geometry.c */
|
2021-12-22 02:17:16 +01:00
|
|
|
extern surface_t * mk_quad(void);
|
|
|
|
extern surface_t * mk_cube(void);
|
|
|
|
extern surface_t * mk_sphere(int longitudes, int latitudes);
|
2021-12-22 01:57:34 +01:00
|
|
|
# ifdef __cplusplus
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|