nuclear@0: #include nuclear@0: #include "texture.h" nuclear@0: #include "image.h" nuclear@0: #include "opengl.h" nuclear@0: nuclear@0: #ifndef GL_GENERATE_MIPMAP_SGIS nuclear@0: #define GL_GENERATE_MIPMAP_SGIS 0x8191 nuclear@0: #endif nuclear@0: nuclear@0: unsigned int load_texture(const char *fname) nuclear@0: { nuclear@0: unsigned int tex; nuclear@0: struct image *img; nuclear@0: nuclear@0: if(!(img = load_image(fname))) { nuclear@0: fprintf(stderr, "failed to load image: %s\n", fname); nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: glGenTextures(1, &tex); nuclear@0: glBindTexture(GL_TEXTURE_2D, tex); nuclear@0: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); nuclear@0: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); nuclear@0: glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); nuclear@0: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->width, img->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img->pixels); nuclear@0: free_image(img); nuclear@0: return tex; nuclear@0: }