36{
37
38
39 program=
read_program(
"gkit2_tutos/tuto5GL_cubemap.glsl");
41
42
43 program_cubemap=
read_program(
"gkit2_tutos/cubemap.glsl");
45
46
47
49 if(mesh.vertex_count() == 0)
50 return -1;
51
52 vertex_count= mesh.vertex_count();
53
55 mesh.bounds(pmin, pmax);
56 camera.lookat(pmin, pmax);
57
58
59 glGenVertexArrays(1, &vao);
60 glBindVertexArray(vao);
61
62
63 glGenBuffers(1, &vertex_buffer);
64 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
65 glBufferData(GL_ARRAY_BUFFER, mesh.vertex_buffer_size(), mesh.vertex_buffer(), GL_STATIC_DRAW);
66
67
68 GLint position= glGetAttribLocation(program, "position");
69 if(position >= 0)
70 {
71 glVertexAttribPointer(position, 3, GL_FLOAT, GL_FALSE, 0, 0);
72 glEnableVertexAttribArray(position);
73 }
74
75
76 if(!mesh.normal_buffer_size())
77 {
78 printf(
"[oops] pas de normales...\n");
79 return -1;
80 }
81
82 glGenBuffers(1, &normal_buffer);
83 glBindBuffer(GL_ARRAY_BUFFER, normal_buffer);
84 glBufferData(GL_ARRAY_BUFFER, mesh.normal_buffer_size(), mesh.normal_buffer(), GL_STATIC_DRAW);
85
86 GLint normal= glGetAttribLocation(program, "normal");
87 if(normal >= 0)
88 {
89 glVertexAttribPointer(normal, 3, GL_FLOAT, GL_FALSE, 0, 0);
90 glEnableVertexAttribArray(normal);
91 }
92
93
94 mesh.release();
95 glBindVertexArray(0);
96 glBindBuffer(GL_ARRAY_BUFFER, 0);
97
98
99#if 0
101
103
104
105 int size= image.width;
106
107 GLenum data_format;
108 GLenum data_type= GL_UNSIGNED_BYTE;
109 if(image.channels == 3)
110 data_format= GL_RGB;
111 else
112 data_format= GL_RGBA;
113
114
115 glGenTextures(1, &texture);
116 glBindTexture(GL_TEXTURE_CUBE_MAP, texture);
117
118
119 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0,
120 GL_RGBA, size, size, 0,
121 data_format, data_type, image.data());
122
123 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0,
124 GL_RGBA, size, size, 0,
125 data_format, data_type, image.data());
126
127 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0,
128 GL_RGBA, size, size, 0,
129 data_format, data_type, image.data());
130
131 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0,
132 GL_RGBA, size, size, 0,
133 data_format, data_type, image.data());
134
135 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0,
136 GL_RGBA, size, size, 0,
137 data_format, data_type, image.data());
138
139 glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0,
140 GL_RGBA, size, size, 0,
141 data_format, data_type, image.data());
142#endif
143
144#if 0
145
147
148
149 int size= image.width / 6;
150
151 GLenum data_format;
152 GLenum data_type= GL_UNSIGNED_BYTE;
153 if(image.channels == 3)
154 data_format= GL_RGB;
155 else
156 data_format= GL_RGBA;
157
158
159 glGenTextures(1, &texture);
160 glBindTexture(GL_TEXTURE_CUBE_MAP, texture);
161
162
163
164 int faces[]= { 0, 1, 2, 3, 4, 5 };
165
166
167 for(int i= 0; i < 6; i++)
168 {
169
171
172
173
174 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X +i, 0,
175 GL_RGBA, size, size, 0,
176 data_format, data_type, face.data());
177 }
178#endif
179
180#if 1
181
182
183
185
186
187 int w= image.width / 4;
188 int h= image.height / 3;
189 assert(w == h);
190
191 GLenum data_format;
192 GLenum data_type= GL_UNSIGNED_BYTE;
193 if(image.channels == 3)
194 data_format= GL_RGB;
195 else
196 data_format= GL_RGBA;
197
198
199 glGenTextures(1, &texture);
200 glBindTexture(GL_TEXTURE_CUBE_MAP, texture);
201
202
203
204 struct { int x, y; } faces[]= {
205 {0, 1},
206 {2, 1},
207 {1, 2},
208 {1, 0},
209 {1, 1},
210 {3, 1},
211 };
212
213 for(int i= 0; i < 6; i++)
214 {
216
217
218 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X +i, 0,
219 GL_RGBA, w, h, 0,
220 data_format, data_type, face.data());
221 }
222#endif
223
224#if 0
225
226 const char *filenames[]= {
227 "data/cubemap/cubemap_opensea/opensea_posx.png",
228 "data/cubemap/cubemap_opensea/opensea_negx.png",
229 "data/cubemap/cubemap_opensea/opensea_posy.png",
230 "data/cubemap/cubemap_opensea/opensea_negy.png",
231 "data/cubemap/cubemap_opensea/opensea_posz.png",
232 "data/cubemap/cubemap_opensea/opensea_negz.png"
233
234
235
236
237
238
239 };
240
241
242 glGenTextures(1, &texture);
243 glBindTexture(GL_TEXTURE_CUBE_MAP, texture);
244
245 for(int i= 0; i < 6; i++)
246 {
248
250
251 GLenum data_format;
252 GLenum data_type= GL_UNSIGNED_BYTE;
253 if(image.channels == 3)
254 data_format= GL_RGB;
255 else
256 data_format= GL_RGBA;
257
258 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X +i, 0,
259 GL_RGBA, image.width, image.height, 0,
260 data_format, data_type, image.data());
261 }
262#endif
263
264 glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
265
266
267 glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
268
269 glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
270
271
272 glGenVertexArrays(1, &vao_null);
273 glBindVertexArray(vao_null);
274
275
276 glUseProgram(0);
277 glBindVertexArray(0);
278
279
280 glClearColor(0.2f, 0.2f, 0.2f, 1);
281 glClearDepthf(1);
282
283 glDepthFunc(GL_LEQUAL);
284
285
286 glEnable(GL_DEPTH_TEST);
287
288 glFrontFace(GL_CCW);
289 glCullFace(GL_BACK);
290
291 glDisable(GL_CULL_FACE);
292 return 0;
293}
representation d'un objet / maillage.
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().
Image flipY(const Image &image)
retourne l'image
Image flipX(const Image &image)
retourne l'image
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...
Image copy(const Image &image, const unsigned xmin, const unsigned ymin, const unsigned width, const unsigned height)
renvoie un bloc de l'image
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.