// 1=OK, 0=error (?) int load_game_data(uint8_t *data) { // XXX asserts loaded data // last line f_lseek (&file,file_header.offbits); return load_pixels(LEVEL_HEIGHT, data); }
int load_texture(const std::string &filename, GLuint *id, int filter) { unsigned char* pixel_buf; img_info_t img_info; if (!load_pixels(filename, &pixel_buf, &img_info)) { fprintf(stderr, "[load_texture]: load_pixels failed!\n"); return 0; } glGenTextures(1, id); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, *id); GLint colortype; switch (img_info.num_channels) { case 3: colortype = GL_RGB; break; case 4: colortype = GL_RGBA; break; default: fprintf(stderr, "load_texture: error: invalid number of channels in image resource file (%d)\n", img_info.num_channels); return 0; } glTexImage2D(GL_TEXTURE_2D, 0, colortype, img_info.width, img_info.height, 0, colortype, GL_UNSIGNED_BYTE, pixel_buf); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST); glGenerateMipmap(GL_TEXTURE_2D); free(pixel_buf); return 1; }