24 Object( ) : model(make_identity()), dynamic(make_identity()) {}
26 Object(
const Mesh& m,
const Color& c ) : mesh(m), model(make_identity()), dynamic(make_identity())
34 draw(
object.mesh,
object.model *
object.dynamic, view, projection);
39 draw(
object.mesh,
object.model *
object.dynamic, orbiter);
43 std::vector<Object> objects;
49 Mesh grid= create_mesh(GL_LINES);
51 for(
int x= 0; x < 10; x++)
53 float px= (float) x - 5.f + 0.5f;
54 push_vertex(grid, make_point(px, 0, -4.5f));
55 push_vertex(grid, make_point(px, 0, 4.5f));
58 for(
int z= 0; z < 10; z++)
60 float pz= (float) z - 5.f + 0.5f;
61 push_vertex(grid, make_point(-4.5f, 0, pz));
62 push_vertex(grid, make_point(4.5f, 0, pz));
76 Object cube1(cube, make_red());
77 cube1.model= make_translation(-1, 0, 0);
79 Object cube2(cube, make_blue());
80 cube2.model= make_translation(1, 0, 0);
82 objects.push_back(cube1);
83 objects.push_back(cube2);
85 camera= make_orbiter();
89 glClearColor(0.2f, 0.2f, 0.2f, 1);
92 glDepthFunc(GL_LEQUAL);
93 glEnable(GL_DEPTH_TEST);
104 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
109 unsigned int mb= SDL_GetRelativeMouseState(&mx, &my);
112 if(mb & SDL_BUTTON(1))
114 orbiter_rotation(camera, mx, my);
116 else if(mb & SDL_BUTTON(3))
118 orbiter_move(camera, mx);
120 else if(mb & SDL_BUTTON(2))
128 float time= (float) SDL_GetTicks();
130 static float cube1x= 0;
138 objects[0].dynamic= make_translation(cube1x, 0, 0) * make_rotationY(time / 16);
140 static float cube2z= 0;
146 objects[1].dynamic= make_translation(0, 0, cube2z);
149 for(
unsigned int i= 0; i < objects.size(); i++)
150 draw(objects[i], camera);
163 int main(
int argc,
char **argv )
178 printf(
"[error] init failed.\n");
Context create_context(Window window, const int major, const int minor)
cree et configure un contexte opengl
representation de la camera, type orbiter, placee sur une sphere autour du centre de l'objet...
Mesh & color(const vec4 &c)
definit la couleur du prochain sommet.
representation d'un objet / maillage.
representation d'une couleur (rgba) transparente ou opaque.
void draw(Mesh &m, const Transform &model, const Transform &view, const Transform &projection, const GLuint texture)
applique une texture a la surface de l'objet. ne fonctionne que si les coordonnees de textures sont f...
int window_width()
renvoie la largeur de la fenetre de l'application.
Window create_window(const int w, const int h)
creation d'une fenetre pour l'application.
int key_state(const SDL_Keycode key)
renvoie l'etat d'une touche du clavier. cf la doc SDL2 pour les codes.
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 window_height()
renvoie la hauteur de la fenetre de l'application.
void release_context(Context context)
detruit le contexte openGL.
void release_window(Window window)
destruction de la fenetre.
int run(Window window, int(*draw)(void))
fonction principale. gestion des evenements et appel de la fonction draw de l'application.
Mesh read_mesh(const char *filename)
charge un fichier wavefront .obj et renvoie un mesh compose de triangles non indexes. utiliser glDrawArrays pour l'afficher. a detruire avec Mesh::release( ).