我只是想给 cvMat 提供一个由片段着色器生成的纹理,屏幕上什么也没有出现,我不知道问题出在哪里,是在驱动程序中还是在 glreadPixels 中。我只是加载一个 TGA 图像,到一个片段着色器,然后纹理化一个四边形,我想将该纹理提供给一个 cvMat,所以我使用 glReadPixesl 然后生成一个新纹理,并将它绘制在四边形上,但没有出现。
请注意,以下代码会在每一帧执行。
cv::Mat pixels;
glPixelStorei(GL_PACK_ALIGNMENT, (pixels.step & 3) ? 1 : 4);
glReadPixels(0, 0, 1024, 1024, GL_RGB, GL_UNSIGNED_BYTE, pixels.data);
glEnable(GL_TEXTURE_2D);
GLuint textureID;
glGenTextures(1, &textureID);
//glDeleteTextures(1, &textureID);
// Create the texture
glTexImage2D(GL_TEXTURE_2D, // Type of texture
0, // Pyramid level (for mip-mapping) - 0 is the top level
GL_RGB, // Internal colour format to convert to
1024, // Image width i.e. 640 for Kinect in standard mode
1024, // Image height i.e. 480 for Kinect in standard mode
0, // Border width in pixels (can either be 1 or 0)
GL_RGB, // Input image format (i.e. GL_RGB, GL_RGBA, GL_BGR etc.)
GL_UNSIGNED_BYTE, // Image data type
pixels.data); // The actual image data itself
glActiveTexture ( textureID );
glBindTexture ( GL_TEXTURE_2D,textureID );
glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices );
最佳答案
textureID
看起来像 incomplete texture .
将 GL_TEXTURE_MIN_FILTER
设置为 GL_NEAREST
或 GL_LINEAR
。
或提供一套完整的 mipmap。
关于c++ - 从帧缓冲区 GLSL 读取到 OpenCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14978226/