- if(fwrite(&w, sizeof w, 1, fp) < 1 ||
- fwrite(&h, sizeof h, 1, fp) < 1 ||
- fwrite(data, 1, size, fp) < size) {
- fprintf(stderr, "failed to dump compressed texture: %s\n", strerror(errno));
+ printf("%s: %dx%d format: %s\n", fname, tex->width, tex->height, fmtstr(tex->fmt));
+ glutReshapeWindow(tex->width + tex->width / 2, tex->height);
+
+ for(i=0; i<hdr.levels; i++) {
+ if(!hdr.datadesc[i].size) {
+ continue;
+ }
+
+ if(fread(buf, 1, hdr.datadesc[i].size, fp) != hdr.datadesc[i].size) {
+ fprintf(stderr, "unexpected EOF while reading texture: %s\n", fname);
+ fclose(fp);
+ free(buf);
+ glDeleteTextures(1, &tex->id);
+ return -1;
+ }
+ if(i == 0) {
+ memcpy(tex->data, buf, hdr.datadesc[0].size);
+ }
+ glCompressedTexImage2D(GL_TEXTURE_2D, i, hdr.glfmt, hdr.width, hdr.height, 0,
+ hdr.datadesc[i].size, buf);
+
+ hdr.width /= 2;
+ hdr.height /= 2;