Skip to content

Instantly share code, notes, and snippets.

View bigfacebear's full-sized avatar

Qiancheng Zhao bigfacebear

  • Hangzhou, Zhejiang, China
View GitHub Profile
@bigfacebear
bigfacebear / glGetTexImage.cpp
Last active October 16, 2022 21:36
How to read an image by opencv, then copy it to a texture, and read it out at last.
cv::Mat img = cv::imread("img.png");
GLuint tex_in;
glGenTextures(1, &tex_in);
glBindTexture(GL_TEXTURE_2D, tex_in);
/*By practice, the internalParam:
* GL_RGB, GL_RGBA, GL_RGB8, GL_RGBA8 work
* GL_RGB8UI, GL_RGBA8UI don't work
*/
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, img.cols, img.rows, 0, GL_BGR, GL_UNSIGNED_BYTE, img.data); // copy data to texture object