annotate 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 |
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@19
|
6 unsigned int load_texture(const char* fname)
|
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@19
|
25 return tex;
|
eleni@19
|
26 }
|