34{
35
38
39
41 if(mesh.vertex_count() == 0)
42 return -1;
43
44 vertex_count= mesh.vertex_count();
45
47 mesh.bounds(pmin, pmax);
48 camera.lookat(pmin, pmax);
49
50
51
52 glGenVertexArrays(1, &vao);
53 glBindVertexArray(vao);
54
55
56 glGenBuffers(1, &vertex_buffer);
57 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
58 glBufferData(GL_ARRAY_BUFFER, mesh.vertex_buffer_size(), mesh.vertex_buffer(), GL_STATIC_DRAW);
59
60
61 GLint position= glGetAttribLocation(program, "position");
62 if(position < 0)
63 return -1;
64 glVertexAttribPointer(position, 3, GL_FLOAT, GL_FALSE, 0, 0);
65 glEnableVertexAttribArray(position);
66
67
68 glGenBuffers(1, &texcoord_buffer);
69 glBindBuffer(GL_ARRAY_BUFFER, texcoord_buffer);
70 glBufferData(GL_ARRAY_BUFFER, mesh.texcoord_buffer_size(), mesh.texcoord_buffer(), GL_STATIC_DRAW);
71
72
73 GLint texcoord= glGetAttribLocation(program, "texcoord");
74 if(texcoord < 0)
75 return -1;
76 glVertexAttribPointer(texcoord, 2, GL_FLOAT, GL_FALSE, 0, 0);
77 glEnableVertexAttribArray(texcoord);
78
79
80 mesh.release();
81 glBindVertexArray(0);
82 glBindBuffer(GL_ARRAY_BUFFER, 0);
83
84
85 glGenSamplers(1, &sampler);
86
87 glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
88 glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
89 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
90 glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
91
92
94
95 GLenum data_format= GL_RGBA;
96 GLenum data_type= GL_UNSIGNED_BYTE;
97 if(image.channels == 3)
98 data_format= GL_RGB;
99
100 glGenTextures(1, &texture);
101 glBindTexture(GL_TEXTURE_2D, texture);
102
103 glTexImage2D(GL_TEXTURE_2D, 0,
104 GL_RGBA, image.width, image.height, 0,
105 data_format, data_type, image.data() );
106
107 glGenerateMipmap(GL_TEXTURE_2D);
108
109
110 glBindTexture(GL_TEXTURE_2D, 0);
111 glUseProgram(0);
112
113
114 glClearColor(0.2f, 0.2f, 0.2f, 1);
115 glClearDepthf(1);
116
117 glDepthFunc(GL_LESS);
118 glEnable(GL_DEPTH_TEST);
119
120 glFrontFace(GL_CCW);
121 glCullFace(GL_BACK);
122 glEnable(GL_CULL_FACE);
123 return 0;
124}
representation d'un objet / maillage.
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...
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.
stockage temporaire des donnees d'une image.
representation d'un point 3d.