27unsigned int vertex_count;
36 program=
read_program(
"gkit2_tutos/tuto4GL_normals.glsl");
41 vertex_count= mesh.vertex_count();
45 mesh.bounds(pmin, pmax);
47 camera.lookat(pmin, pmax);
49 glGenBuffers(1, &vertex_buffer);
50 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
53 glBufferData(GL_ARRAY_BUFFER,
54 mesh.vertex_buffer_size(),
60 glGenBuffers(1, &normal_buffer);
61 glBindBuffer(GL_ARRAY_BUFFER, normal_buffer);
62 glBufferData(GL_ARRAY_BUFFER, mesh.normal_buffer_size(), mesh.normal_buffer(), GL_STATIC_DRAW);
68 glGenVertexArrays(1, &vao);
69 glBindVertexArray(vao);
72 GLint attribute= glGetAttribLocation(program,
"position");
77 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
79 glVertexAttribPointer(attribute, 3, GL_FLOAT, GL_FALSE, 0, 0);
80 glEnableVertexAttribArray(attribute);
83 attribute= glGetAttribLocation(program,
"normal");
88 glBindBuffer(GL_ARRAY_BUFFER, normal_buffer);
89 glVertexAttribPointer(attribute, 3, GL_FLOAT, GL_FALSE, 0, 0);
90 glEnableVertexAttribArray(attribute);
125 glBindVertexArray(0);
126 glBindBuffer(GL_ARRAY_BUFFER, 0);
129 glClearColor(0.2f, 0.2f, 0.2f, 1);
132 glDepthFunc(GL_LESS);
133 glEnable(GL_DEPTH_TEST);
135 glEnable(GL_CULL_FACE);
143 glDeleteBuffers(1, &vertex_buffer);
144 glDeleteVertexArrays(1, &vao);
150 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
155 unsigned int mb= SDL_GetRelativeMouseState(&mx, &my);
158 if(mb & SDL_BUTTON(1))
160 camera.rotation(mx, my);
162 else if(mb & SDL_BUTTON(3))
166 else if(mb & SDL_BUTTON(2))
176 glBindVertexArray(vao);
178 glUseProgram(program);
186 Transform mvp= projection * view * model;
190 location= glGetUniformLocation(program,
"mvpMatrix");
191 glUniformMatrix4fv(location, 1, GL_TRUE, mvp.
data());
194 program_uniform(program,
"mvMatrix", mv.
normal());
196 program_uniform(program,
"color",
vec3(1, 0.5, 0.));
198 glDrawArrays(GL_TRIANGLES, 0, vertex_count);
202 glBindVertexArray(0);
207int main(
int argc,
char **argv )
222 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)
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, const char *filename)
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.
vecteur generique, utilitaire.