17Mesh make_grid(
const int n= 10 )
24 float w= float(n-1) / 2;
25 for(
int x= 0; x < n; x++)
31 for(
int z= 0; z < n; z++)
54Mesh make_ground(
const int n= 10 )
59 int a= grid.
vertex(-n/2, -1, n/2);
60 int b= grid.
vertex( n/2, -1, n/2);
61 int c= grid.
vertex( n/2, -1, -n/2);
62 int d= grid.
vertex(-n/2, -1, -n/2);
76 camera.vertex(
Point(0, 0, 0));
77 camera.vertex(
Point(1, 0, 0));
79 camera.color(
Green());
80 camera.vertex(
Point(0, 0, 0));
81 camera.vertex(
Point(0, 1, 0));
84 camera.vertex(
Point(0, 0, 0));
85 camera.vertex(
Point(0, 0, 1));
97 camera.vertex(-1, -1, -1);
98 camera.vertex(-1, 1, -1);
99 camera.vertex(-1, 1, -1);
100 camera.vertex(1, 1, -1);
101 camera.vertex(1, 1, -1);
102 camera.vertex(1, -1, -1);
103 camera.vertex(1, -1, -1);
104 camera.vertex(-1, -1, -1);
107 camera.vertex(-1, -1, 1);
108 camera.vertex(-1, 1, 1);
109 camera.vertex(-1, 1, 1);
110 camera.vertex(1, 1, 1);
111 camera.vertex(1, 1, 1);
112 camera.vertex(1, -1, 1);
113 camera.vertex(1, -1, 1);
114 camera.vertex(-1, -1, 1);
117 camera.vertex(-1, -1, -1);
118 camera.vertex(-1, -1, 1);
119 camera.vertex(-1, 1, -1);
120 camera.vertex(-1, 1, 1);
121 camera.vertex(1, 1, -1);
122 camera.vertex(1, 1, 1);
123 camera.vertex(1, -1, -1);
124 camera.vertex(1, -1, 1);
134 camera.vertex(0,0,0);
135 camera.vertex(-0.5, -0.5, -1);
136 camera.vertex(0,0,0);
137 camera.vertex(-0.5, 0.5, -1);
138 camera.vertex(0,0,0);
139 camera.vertex(0.5, 0.5, -1);
140 camera.vertex(0,0,0);
141 camera.vertex(0.5, -0.5, -1);
143 camera.vertex(-0.5, -0.5, -1);
144 camera.vertex(-0.5, 0.5, -1);
146 camera.vertex(-0.5, 0.5, -1);
147 camera.vertex(0.5, 0.5, -1);
149 camera.vertex(0.5, 0.5, -1);
150 camera.vertex(0.5, -0.5, -1);
152 camera.vertex(0.5, -0.5, -1);
153 camera.vertex(-0.5, -0.5, -1);
157 camera.vertex(
Point(0, 0, 0));
158 camera.vertex(
Point(1, 0, 0));
160 camera.color(
Green());
161 camera.vertex(
Point(0, 0, 0));
162 camera.vertex(
Point(0, 1, 0));
164 camera.color(
Blue());
165 camera.vertex(
Point(0, 0, 0));
166 camera.vertex(
Point(0, 0, 1));
184 m_repere= make_grid(20);
185 m_local= make_grid(2);
186 m_ground= make_ground(20);
190 m_frustum= make_frustum();
202 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
203 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
204 float border[]= { 1, 1, 1, 1 };
205 glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border);
216 m_ground.bounds(pmin, pmax);
221 glClearColor(0.2f, 0.2f, 0.2f, 1.f);
224 glDepthFunc(GL_LESS);
225 glEnable(GL_DEPTH_TEST);
240 glDeleteTextures(1, &m_texture);
247 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
275 Transform decal_projection=
Ortho(-2, 2, -2, 2,
float(0.1),
float(10));
285 projection= decal_projection;
288 draw(m_objet, m_position, view, projection);
290 draw(m_local, m_position, view, projection);
296 draw(m_proxy, m_position * m, view, projection);
304 draw(m_frustum, decal_m, view, projection);
311 draw(m_ground,
Identity(), view, projection);
317 glUseProgram(m_program);
324 program_uniform(m_program,
"mvpMatrix", mvp);
325 program_uniform(m_program,
"mvMatrix", mv);
331 Transform decal= decal_viewport * decal_projection * decal_view;
333 program_uniform(m_program,
"decalMatrix", decal);
336 m_ground.draw(m_program);
365int main(
int argc,
char **argv )
const Orbiter & camera() const
renvoie l'orbiter gere par l'application.
AppCamera(const int width, const int height, const int major=3, const int minor=3, const int samples=0)
constructeur, dimensions de la fenetre et version d'openGL.
int run()
execution de l'application.
representation d'un objet / maillage.
unsigned int vertex(const vec3 &p)
insere un sommet de position p, et ses attributs (s'ils sont definis par color(), texcoord(),...
Mesh & triangle(const unsigned int a, const unsigned int b, const unsigned int c)
Mesh & normal(const vec3 &n)
definit la normale du prochain sommet.
Mesh & color(const vec4 &c)
definit la couleur du prochain sommet.
void lookat(const Point ¢er, const float size)
observe le point center a une distance size.
Transform projection(const int width, const int height, const float fov)
fixe la projection reglee pour une image d'aspect width / height, et une demi ouverture de fov degres...
Transform view() const
renvoie la transformation vue.
int render()
a deriver pour afficher les objets. renvoie 1 pour continuer, 0 pour fermer l'application.
int quit()
a deriver pour detruire les objets openGL. renvoie -1 pour indiquer une erreur, 0 sinon.
int init()
a deriver pour creer les objets openGL. renvoie -1 pour indiquer une erreur, 0 sinon.
void clear_key_state(const SDL_Keycode key)
desactive une touche du clavier.
int key_state(const SDL_Keycode key)
renvoie l'etat d'une touche du clavier. cf la doc SDL2 pour les codes.
Color Red()
utilitaire. renvoie une couleur rouge.
Color Yellow()
utilitaire. renvoie une couleur jaune.
Color Blue()
utilitaire. renvoie une couleur bleue.
Color Green()
utilitaire. renvoie une couleur verte.
Color White()
utilitaire. renvoie une couleur blanche.
Transform Inverse(const Transform &m)
renvoie l'inverse de la matrice.
Transform Viewport(const float width, const float height)
renvoie la matrice representant une transformation viewport.
Transform Identity()
construit la transformation identite.
Transform RotationX(const float a)
renvoie la matrice representation une rotation de angle degree autour de l'axe X.
Transform RotationY(const float a)
renvoie la matrice representation une rotation de a degree autour de l'axe Y.
Transform Ortho(const float left, const float right, const float bottom, const float top, const float znear, const float zfar)
renvoie la matrice representant une transformation orthographique, passage d'un cube []x[]x[] vers [-...
Transform Translation(const Vector &v)
renvoie la matrice representant une translation par un vecteur.
Mesh read_mesh(const char *filename)
charge un fichier wavefront .obj et renvoie un mesh compose de triangles non indexes....
int screenshot(const char *filename)
enregistre le contenu de la fenetre dans un fichier. doit etre de type .png / .bmp
GLuint read_program(const char *filename, const char *definitions)
int program_print_errors(const GLuint program)
affiche les erreurs de compilation.
int release_program(const GLuint program)
detruit les shaders et le program.
void program_use_texture(const GLuint program, const char *uniform, const int unit, const GLuint texture, const GLuint sampler)
configure le pipeline et le shader program pour utiliser une texture, et des parametres de filtrage,...
GLuint read_texture(const int unit, const char *filename, const GLenum texel_type)
representation d'un point 3d.