invisible

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/texture.cc	Sun Nov 10 14:02:36 2013 +0200
     1.3 @@ -0,0 +1,26 @@
     1.4 +#include <GL/gl.h>
     1.5 +#include <highgui.h>
     1.6 +#include <cv.h>
     1.7 +#include "texture.h"
     1.8 +
     1.9 +unsigned int load_texture(const char* fname)
    1.10 +{
    1.11 +	IplImage* img = cvLoadImage(fname);
    1.12 +	if(!img) {
    1.13 +		fprintf(stderr, "Failed to load image: %s\n", fname);
    1.14 +		return 0;
    1.15 +	}
    1.16 +	cv::Mat mat = cv::Mat(img);
    1.17 +
    1.18 +	unsigned int tex;
    1.19 +	glGenTextures(1, &tex);
    1.20 +	glBindTexture(GL_TEXTURE_2D, tex);
    1.21 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    1.22 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    1.23 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    1.24 +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    1.25 +	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, mat.cols, mat.rows,
    1.26 +			0, GL_BGR, GL_UNSIGNED_BYTE, mat.data);
    1.27 +
    1.28 +	return tex;
    1.29 +}