19Mesh make_grid(
const int n= 10 )
25 float w= float(n-1) / 2;
26 for(
int x= 0; x < n; x++)
32 for(
int z= 0; z < n; z++)
61 TP(
const int msaa= 1 ) :
AppCamera(1024, 640, 4,3, msaa) {}
67 m_repere= make_grid(20);
69 Point grid_pmin, grid_pmax;
70 m_repere.bounds(grid_pmin, grid_pmax);
76 m_objet.bounds(pmin, pmax);
78 pmin=
min(pmin, grid_pmin);
79 pmax=
max(pmax, grid_pmax);
87 for(
unsigned i= 0; i < m_textures.size(); i++)
92 for(
int i= 0; i < materials.
count(); i++)
102 m_groups= m_objet.groups();
107 m_program=
read_program(
"gkit2_tutos/alpha_notexture.glsl");
111 glClearColor(0.2f, 0.2f, 0.2f, 1.f);
114 glDepthFunc(GL_LESS);
115 glEnable(GL_DEPTH_TEST);
117 glEnable(GL_MULTISAMPLE);
118 glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE);
134 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
144 reload_program(m_program,
"gkit2_tutos/alpha_notexture.glsl");
148 glBindVertexArray(m_vao);
149 glUseProgram(m_program);
157 program_uniform(m_program,
"mvMatrix", mv);
158 program_uniform(m_program,
"mvpMatrix", mvp);
162 for(
unsigned i= 0; i < m_groups.size(); i++)
172 glDrawArrays(GL_TRIANGLES, m_groups[i].first, m_groups[i].n);
191 std::vector<GLuint> m_textures;
192 std::vector<TriangleGroup> m_groups;
196int 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.
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 & 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.
void printf(Text &text, const int px, const int py, const char *format,...)
affiche un texte a la position x, y. meme utilisation que printf().
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 Blue()
utilitaire. renvoie une couleur bleue.
Color Green()
utilitaire. renvoie une couleur verte.
Color White()
utilitaire. renvoie une couleur blanche.
Point max(const Point &a, const Point &b)
renvoie la plus grande composante de chaque point { max(a.x, b.x), max(a.y, b.y), max(a....
Transform Identity()
construit la transformation identite.
Point min(const Point &a, const Point &b)
renvoie la plus petite composante de chaque point { min(a.x, b.x), min(a.y, b.y), min(a....
Mesh read_mesh(const char *filename)
charge un fichier wavefront .obj et renvoie un mesh compose de triangles non indexes....
@ USE_POSITION
inclut l'attribut position dans les buffers.
@ USE_TEXCOORD
inclut l'attribut coordonnees de texture dans les buffers.
@ USE_NORMAL
inclut l'attribut normale dans les buffers.
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.
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)
int diffuse_texture
indice de la texture de la couleur de base, ou -1.
Color diffuse
couleur diffuse / de base.
int filename_count() const
renvoie le nombre de noms de fichiers de textures.
const char * filename(const int id) const
renvoie le nom de fichier d'une texture.
int count() const
nombre de matieres.
std::vector< Material > materials
description des matieres.
const Material & material(const int id) const
renvoie la ieme matiere.
const char * name(const int id) const
renvoie le nom de la ieme matiere.
representation d'un point 3d.