2013-02-20 52 views
3

我只是想提供一個由片段着色器生成的紋理,沒有什麼出現在屏幕上,我不知道問題在哪裏,這是在驅動程序中或glreadPixels ..我只是加載一個TGA圖像,一個片段着色器,然後紋理一個四邊形,我想喂這個紋理到一個cvMat,所以我用glReadPixesl然後genereated一個新的紋理,並繪製在四,但沒有出現。從framebuffer GLSL讀取到OpenCV

請注意,下面的代碼在每一幀執行。

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

請給我清楚一點。你試圖從OpenGL紋理創建一個Mat,對吧? – 2013-09-12 09:19:09

+0

我正在嘗試創建一個紋理數學 – 2013-09-12 12:37:23

+0

好的。你能告訴我你在前兩行「glPixelStorei()」和「glReadPixels()」中做了什麼。在我看來,你正在將OpenGL紋理複製到像素中。 – 2013-09-12 15:38:55

回答

2

textureID看起來像一個incomplete texture

設置GL_TEXTURE_MIN_FILTERGL_NEARESTGL_LINEAR

或提供一套完整的mipmap。