Andre Ahmed
Andre Ahmed

Reputation: 1891

Reading from framebuffer GLSL to OpenCV

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

Upvotes: 3

Views: 1393

Answers (1)

genpfault
genpfault

Reputation: 52090

textureID looks like an incomplete texture.

Set GL_TEXTURE_MIN_FILTER to GL_NEAREST or GL_LINEAR.

Or supply a complete set of mipmaps.

Upvotes: 2

Related Questions