invisible

view src/texture.cc @ 26:61d593076c56

foo
author Eleni Maria Stea <eleni@mutantstargoat.com>
date Sun, 17 Nov 2013 23:02:40 +0200
parents f756fc9fdd3e
children
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, int *xsz, int *ysz)
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 if(xsz) {
26 *xsz = mat.cols;
27 }
28 if(ysz) {
29 *ysz = mat.rows;
30 }
31 return tex;
32 }