从帧缓冲区 GLSL 读取到 OpenCV

2024-04-01

我只是想向 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看起来像一个不完整的纹理 http://www.opengl.org/wiki/Common_Mistakes#Creating_a_complete_texture.

Set GL_TEXTURE_MIN_FILTER to GL_NEAREST or GL_LINEAR.

或者提供一套完整的 mipmap。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从帧缓冲区 GLSL 读取到 OpenCV 的相关文章

随机推荐