26GLuint texcoord_buffer;
40 if(mesh.vertex_count() == 0)
43 vertex_count= mesh.vertex_count();
46 mesh.bounds(pmin, pmax);
47 camera.lookat(pmin, pmax);
51 glGenVertexArrays(1, &vao);
52 glBindVertexArray(vao);
55 glGenBuffers(1, &vertex_buffer);
56 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
57 glBufferData(GL_ARRAY_BUFFER, mesh.vertex_buffer_size(), mesh.vertex_buffer(), GL_STATIC_DRAW);
60 GLint position= glGetAttribLocation(program,
"position");
63 glVertexAttribPointer(position, 3, GL_FLOAT, GL_FALSE, 0, 0);
64 glEnableVertexAttribArray(position);
67 glGenBuffers(1, &texcoord_buffer);
68 glBindBuffer(GL_ARRAY_BUFFER, texcoord_buffer);
69 glBufferData(GL_ARRAY_BUFFER, mesh.texcoord_buffer_size(), mesh.texcoord_buffer(), GL_STATIC_DRAW);
72 GLint texcoord= glGetAttribLocation(program,
"texcoord");
75 glVertexAttribPointer(texcoord, 2, GL_FLOAT, GL_FALSE, 0, 0);
76 glEnableVertexAttribArray(texcoord);
81 glBindBuffer(GL_ARRAY_BUFFER, 0);
87 GLenum data_type= GL_UNSIGNED_BYTE;
88 if(image.channels == 3)
93 glGenTextures(1, &texture);
94 glBindTexture(GL_TEXTURE_2D, texture);
96 glTexImage2D(GL_TEXTURE_2D, 0,
97 GL_RGBA, image.width, image.height, 0,
98 data_format, data_type, image.data());
100 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
103 glBindTexture(GL_TEXTURE_2D, 0);
107 glClearColor(0.2f, 0.2f, 0.2f, 1);
110 glDepthFunc(GL_LESS);
111 glEnable(GL_DEPTH_TEST);
115 glEnable(GL_CULL_FACE);
122 glDeleteVertexArrays(1, &vao);
123 glDeleteBuffers(1, &vertex_buffer);
124 glDeleteBuffers(1, &texcoord_buffer);
125 glDeleteTextures(1, &texture);
131 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
136 unsigned int mb= SDL_GetRelativeMouseState(&mx, &my);
139 if(mb & SDL_BUTTON(1))
141 camera.rotation(mx, my);
143 else if(mb & SDL_BUTTON(3))
147 else if(mb & SDL_BUTTON(2))
159 glBindVertexArray(vao);
160 glUseProgram(program);
168 Transform mvp= projection * view * model;
169 program_uniform(program,
"mvpMatrix", mvp);
172 glBindTexture(GL_TEXTURE_2D, texture);
175 GLint location= glGetUniformLocation(program,
"texture0");
176 glUniform1i(location, 0);
179 glDrawArrays(GL_TRIANGLES, 0, vertex_count);
182 glBindTexture(GL_TEXTURE_2D, 0);
184 glBindVertexArray(0);
190int main(
int argc,
char **argv )
205 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.
ImageData read_image_data(const void *buffer, const unsigned size, const bool flipY)
charge les donnees d'un fichier png stocke en memoire. renvoie une image initialisee par defaut en ca...
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)
stockage temporaire des donnees d'une image.
representation d'un point 3d.