invisible

annotate 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
rev   line source
eleni@19 1 #include <GL/gl.h>
eleni@19 2 #include <highgui.h>
eleni@19 3 #include <cv.h>
eleni@19 4 #include "texture.h"
eleni@19 5
eleni@23 6 unsigned int load_texture(const char* fname, int *xsz, int *ysz)
eleni@19 7 {
eleni@19 8 IplImage* img = cvLoadImage(fname);
eleni@19 9 if(!img) {
eleni@19 10 fprintf(stderr, "Failed to load image: %s\n", fname);
eleni@19 11 return 0;
eleni@19 12 }
eleni@19 13 cv::Mat mat = cv::Mat(img);
eleni@19 14
eleni@19 15 unsigned int tex;
eleni@19 16 glGenTextures(1, &tex);
eleni@19 17 glBindTexture(GL_TEXTURE_2D, tex);
eleni@19 18 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
eleni@19 19 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
eleni@19 20 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
eleni@19 21 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
eleni@19 22 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, mat.cols, mat.rows,
eleni@19 23 0, GL_BGR, GL_UNSIGNED_BYTE, mat.data);
eleni@19 24
eleni@23 25 if(xsz) {
eleni@23 26 *xsz = mat.cols;
eleni@23 27 }
eleni@23 28 if(ysz) {
eleni@23 29 *ysz = mat.rows;
eleni@23 30 }
eleni@19 31 return tex;
eleni@19 32 }