nuclear@3: #include nuclear@3: #include "opengl.h" nuclear@3: #include nuclear@3: #include "texture.h" nuclear@3: nuclear@3: unsigned int load_texture(const char *fname) nuclear@3: { nuclear@3: int xsz, ysz; nuclear@3: void *pixels; nuclear@3: unsigned int tex; nuclear@3: nuclear@3: if(!(pixels = img_load_pixels(fname, &xsz, &ysz, IMG_FMT_RGB24))) { nuclear@3: fprintf(stderr, "failed to load texture: %s\n", fname); nuclear@3: return 0; nuclear@3: } nuclear@3: nuclear@3: glGenTextures(1, &tex); nuclear@3: glBindTexture(GL_TEXTURE_2D, tex); nuclear@3: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); nuclear@3: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); nuclear@3: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, xsz, ysz, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels); nuclear@3: nuclear@3: img_free_pixels(pixels); nuclear@3: nuclear@3: return tex; nuclear@3: } nuclear@3: nuclear@3: void free_texture(unsigned int tex) nuclear@3: { nuclear@3: glDeleteTextures(1, &tex); nuclear@3: }