35 if (img.depth() != CV_8U)
LFATAL(
"Only 8-bit/channel images are supported");
38 cv::Mat cvt; GLint fmt;
39 switch (img.channels())
46 if (isbgr) cv::cvtColor(img, cvt, cv::COLOR_BGR2RGB);
else cvt = img;
50 case 4:
if (isbgr) cv::cvtColor(img, cvt, cv::COLOR_BGRA2RGBA);
else cvt = img;
54 default:
LFATAL(
"Unsupported image format with " << img.channels() <<
" channels, should be 1, 3, or 4");
60 int const newcols = cvt.cols + 8 - (cvt.cols % 8);
65 glGenTextures(1, &itsId);
66 glBindTexture(GL_TEXTURE_2D, itsId);
67 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
68 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
69 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
70 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
71 glTexImage2D(GL_TEXTURE_2D, 0, fmt, cvt.cols, cvt.rows, 0, fmt, GL_UNSIGNED_BYTE, cvt.ptr());
72 glBindTexture(GL_TEXTURE_2D, 0);