35{
36
39
40
42 if(mesh.vertex_count() == 0)
43 return -1;
44
45 vertex_count= mesh.vertex_count();
46
48 mesh.bounds(pmin, pmax);
49 camera.lookat(pmin, pmax);
50
51
52
53 glGenVertexArrays(1, &vao);
54 glBindVertexArray(vao);
55
56
57 glGenBuffers(1, &vertex_buffer);
58 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
59 glBufferData(GL_ARRAY_BUFFER, mesh.vertex_buffer_size(), mesh.vertex_buffer(), GL_STATIC_DRAW);
60
61
62 GLint position= glGetAttribLocation(program, "position");
63 if(position < 0)
64 return -1;
65 glVertexAttribPointer(position, 3, GL_FLOAT, GL_FALSE, 0, 0);
66 glEnableVertexAttribArray(position);
67
68
69 glGenBuffers(1, &texcoord_buffer);
70 glBindBuffer(GL_ARRAY_BUFFER, texcoord_buffer);
71 glBufferData(GL_ARRAY_BUFFER, mesh.texcoord_buffer_size(), mesh.texcoord_buffer(), GL_STATIC_DRAW);
72
73
74 GLint texcoord= glGetAttribLocation(program, "texcoord");
75 if(texcoord < 0)
76 return -1;
77 glVertexAttribPointer(texcoord, 2, GL_FLOAT, GL_FALSE, 0, 0);
78 glEnableVertexAttribArray(texcoord);
79
80
81 mesh.release();
82 glBindVertexArray(0);
83 glBindBuffer(GL_ARRAY_BUFFER, 0);
84
85
86 glGenSamplers(1, &sampler);
87
88 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
89 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
90 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
91 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
92
93
94
95
98
99
100 glBindTexture(GL_TEXTURE_2D, 0);
101 glUseProgram(0);
102
103
104 glClearColor(0.2f, 0.2f, 0.2f, 1);
105 glClearDepthf(1);
106
107 glDepthFunc(GL_LESS);
108 glEnable(GL_DEPTH_TEST);
109
110 glFrontFace(GL_CCW);
111 glCullFace(GL_BACK);
112 glEnable(GL_CULL_FACE);
113 return 0;
114}
representation d'un objet / maillage.
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.
GLuint read_texture(const int unit, const char *filename, const GLenum texel_type)
representation d'un point 3d.