eleni@19: #include eleni@19: #include eleni@19: #include eleni@19: #include "texture.h" eleni@19: eleni@23: unsigned int load_texture(const char* fname, int *xsz, int *ysz) eleni@19: { eleni@19: IplImage* img = cvLoadImage(fname); eleni@19: if(!img) { eleni@19: fprintf(stderr, "Failed to load image: %s\n", fname); eleni@19: return 0; eleni@19: } eleni@19: cv::Mat mat = cv::Mat(img); eleni@19: eleni@19: unsigned int tex; eleni@19: glGenTextures(1, &tex); eleni@19: glBindTexture(GL_TEXTURE_2D, tex); eleni@19: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); eleni@19: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); eleni@19: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); eleni@19: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); eleni@19: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, mat.cols, mat.rows, eleni@19: 0, GL_BGR, GL_UNSIGNED_BYTE, mat.data); eleni@19: eleni@23: if(xsz) { eleni@23: *xsz = mat.cols; eleni@23: } eleni@23: if(ysz) { eleni@23: *ysz = mat.rows; eleni@23: } eleni@19: return tex; eleni@19: }