Reading from framebuffer GLSL to OpenCV

烈酒焚心 提交于 2019-12-10 19:43:41

问题


I'm just trying to feed a cvMat a texture that is generated by fragment shader, there is nothing appears on the screen, I don't know where is the problem, is this in the driver or glreadPixels.. I just loaded a TGA Image, to a fragment shader, then textured a quad, I wanted to feed that texture to a cvMat, so I used glReadPixesl then genereated a new texture, and drew it on the quad, but nothing appears.

Kindly note that the following code is executed at each frame.

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 );

回答1:


textureID looks like an incomplete texture.

Set GL_TEXTURE_MIN_FILTER to GL_NEAREST or GL_LINEAR.

Or supply a complete set of mipmaps.



来源:https://stackoverflow.com/questions/14981881/reading-from-framebuffer-glsl-to-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!