invisible

view src/texture.cc @ 19:f756fc9fdd3e

quick backup
author Eleni Maria Stea <eleni@mutantstargoat.com>
date Sun, 10 Nov 2013 14:02:36 +0200
parents
children b50ad2711f5f
line source
1 #include <GL/gl.h>
2 #include <highgui.h>
3 #include <cv.h>
4 #include "texture.h"
6 unsigned int load_texture(const char* fname)
7 {
8 IplImage* img = cvLoadImage(fname);
9 if(!img) {
10 fprintf(stderr, "Failed to load image: %s\n", fname);
11 return 0;
12 }
13 cv::Mat mat = cv::Mat(img);
15 unsigned int tex;
16 glGenTextures(1, &tex);
17 glBindTexture(GL_TEXTURE_2D, tex);
18 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
19 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
20 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
21 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
22 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, mat.cols, mat.rows,
23 0, GL_BGR, GL_UNSIGNED_BYTE, mat.data);
25 return tex;
26 }