Last active
January 18, 2018 04:32
-
-
Save saccadic/2a40b09e3fc4623cb14c02cac3ddbe6c to your computer and use it in GitHub Desktop.
Mat画像をImGuiで表示したときのやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ConvertMatToGL(const cv::Mat& src,GLuint* texID){ | |
if(src.empty() == true) | |
return; | |
glDeleteTextures(1, texID); | |
glPixelStorei(GL_UNPACK_ALIGNMENT,1); | |
glGenTextures(1, texID); | |
glBindTexture(GL_TEXTURE_2D, *texID); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); | |
if(src.channels() == 4){ | |
glTexImage2D( | |
GL_TEXTURE_2D, | |
0, | |
GL_RGBA, | |
src.cols, src.rows, | |
0, | |
GL_RGBA, | |
GL_UNSIGNED_BYTE, | |
src.ptr<unsigned char>() | |
); | |
}else if(src.channels() == 3){ | |
glTexImage2D( | |
GL_TEXTURE_2D, | |
0, | |
GL_RGB, | |
src.cols, src.rows, | |
0, | |
GL_RGB, | |
GL_UNSIGNED_BYTE, | |
src.ptr<unsigned char>() | |
); | |
}else if(src.channels() == 1){ | |
glTexImage2D( | |
GL_TEXTURE_2D, | |
0, | |
GL_LUMINANCE, | |
src.cols, src.rows, | |
0, | |
GL_LUMINANCE, | |
GL_UNSIGNED_BYTE, | |
src.ptr<unsigned char>() | |
); | |
}else{ | |
ofLog() << "other channel !"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment