int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutCreateWindow("3D lighted cube"); glutDisplayFunc(display); loadtex(); init(); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
int loadatlas(Array *map, const char *spec, const char *image) { if(!map || !spec || !image) return 0; FILE *specfile = fopen(spec, "rb"); if(!spec) return 0; unsigned int atlas = loadtex(image); if(!atlas) return 0; size_t nprev = map->nmemb; Texture *tex; Texture *dup; int ntex; for(ntex = 0; (tex = specline(map, specfile)); ) { tex->handle = atlas; dup = findntex(map, nprev, tex->name); // Ignore this line on duplicate, or we could: // memset(dup, tex, // sizeof(Texture) - sizeof(tex->name)); // freetex(tex); // tex = dup; if(dup) { printf("duplicate found: %s\n", tex->name); freetex(tex); } else { printf("inserting: %s\n", tex->name); arraypush(map, &tex); ntex++; } } fclose(specfile); if(!ntex) { glDeleteTextures(1, &atlas); return 0; } qsort(map->ptr, map->nmemb, map->size, (int(*)(const void*, const void*))texcmp); return ntex; }