int loadTexture(char* filename) { int texWidth, texHeight; FILE *fp; if ( (fp = fopen(filename,"rb")) == NULL) { fprintf(stderr, "Unable to open %s\n", filename); return -1; } char buff[128]; fgets(buff, 128, fp); while(buff[0] == '#') fgets(buff, 128, fp); if(strncmp(buff, "P6", 2)) { fclose(fp); return -1; } fgets(buff, 128, fp); while(buff[0] == '#') fgets(buff, 128, fp); sscanf(buff, "%d %d", &texWidth, &texHeight); fgets(buff, 128, fp); while(buff[0] == '#') fgets(buff, 128, fp); image = new GLubyte [ texWidth * texHeight * 3]; fread(image, 1, texWidth * texHeight * 3, fp); fclose(fp); return 0; }