labyrinth

annotate src/texture.c @ 0:8ba79034e8a6

labyrinth example initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 15 Jan 2015 14:59:38 +0200
parents
children c8826e5ebec1
rev   line source
nuclear@0 1 #include <stdio.h>
nuclear@0 2 #include "texture.h"
nuclear@0 3 #include "image.h"
nuclear@0 4 #include "opengl.h"
nuclear@0 5
nuclear@0 6 #ifndef GL_GENERATE_MIPMAP_SGIS
nuclear@0 7 #define GL_GENERATE_MIPMAP_SGIS 0x8191
nuclear@0 8 #endif
nuclear@0 9
nuclear@0 10 unsigned int load_texture(const char *fname)
nuclear@0 11 {
nuclear@0 12 unsigned int tex;
nuclear@0 13 struct image *img;
nuclear@0 14
nuclear@0 15 if(!(img = load_image(fname))) {
nuclear@0 16 fprintf(stderr, "failed to load image: %s\n", fname);
nuclear@0 17 return 0;
nuclear@0 18 }
nuclear@0 19
nuclear@0 20 glGenTextures(1, &tex);
nuclear@0 21 glBindTexture(GL_TEXTURE_2D, tex);
nuclear@0 22 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
nuclear@0 23 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
nuclear@0 24 glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
nuclear@0 25 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->width, img->height, 0, GL_RGB, GL_UNSIGNED_BYTE, img->pixels);
nuclear@0 26 free_image(img);
nuclear@0 27 return tex;
nuclear@0 28 }