36 vertex_count= mesh.vertex_count();
40 mesh.bounds(pmin, pmax);
41 camera.lookat(pmin, pmax);
49 glGenBuffers(1, &vertex_buffer);
51 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
54 glBufferData(GL_ARRAY_BUFFER,
55 mesh.vertex_buffer_size(),
73 glGenVertexArrays(1, &vao);
75 glBindVertexArray(vao);
78 GLint attribute= glGetAttribLocation(program,
"position");
85 glVertexAttribPointer(attribute, 3, GL_FLOAT,
90 glEnableVertexAttribArray(attribute);
99 glBindBuffer(GL_ARRAY_BUFFER, 0);
102 glClearColor(0.2f, 0.2f, 0.2f, 1);
106 glDepthFunc(GL_LESS);
107 glEnable(GL_DEPTH_TEST);
111 glEnable(GL_CULL_FACE);
118 glDeleteBuffers(1, &vertex_buffer);
119 glDeleteVertexArrays(1, &vao);
125 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
130 unsigned int mb= SDL_GetRelativeMouseState(&mx, &my);
133 if(mb & SDL_BUTTON(1))
135 camera.rotation(mx, my);
137 else if(mb & SDL_BUTTON(3))
141 else if(mb & SDL_BUTTON(2))
151 glBindVertexArray(vao);
153 glUseProgram(program);
161 Transform mvp= projection * view * model;
164 location= glGetUniformLocation(program,
"mvpMatrix");
165 glUniformMatrix4fv(location, 1, GL_TRUE, mvp.
data());
172 location= glGetUniformLocation(program,
"color");
173 glUniform3f(location, 1, 0.5, 0);
176 glDrawArrays(GL_TRIANGLES, 0, vertex_count);
180 glBindVertexArray(0);
185int main(
int argc,
char **argv )
200 printf(
"[error] init failed.\n");
representation d'un objet / maillage.
representation de la camera, type orbiter, placee sur une sphere autour du centre de l'objet.
Context create_context(Window window)
cree et configure un contexte opengl
int window_height()
renvoie la hauteur de la fenetre de l'application.
void release_window(Window window)
destruction de la fenetre.
int run(Window window, int(*draw)())
boucle de gestion des evenements de l'application.
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().
Window create_window(const int w, const int h, const int major, const int minor, const int samples)
creation d'une fenetre pour l'application.
void release_context(Context context)
detruit le contexte openGL.
int window_width()
renvoie la largeur de la fenetre de l'application.
Transform Identity()
construit la transformation identite.
Mesh read_mesh(const char *filename)
charge un fichier wavefront .obj et renvoie un mesh compose de triangles non indexes....
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.
int init(std::vector< const char * > &options)
representation d'un point 3d.