0

I'm trying to display OpenCV Mat image using Opengl, And I'm Getting blank screen. I'm new to OpenGL

Code:

img = imread("Test2.jpg", 1);
//img = Mat(640, 480, CV_8UC3, Scalar(0, 0, 255));
flip(img, img, 0);

Render Code:

glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,img.cols , img.rows,0,GL_BGR,GL_UNSIGNED_BYTE, img.data);
glUniform1i(textureId, 0);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glFlush();
glutSwapBuffers();

Interesting thing noted is that when I dynamically create Mat Image using

Mat(640, 480, CV_8UC3, Scalar(0, 0, 255));

The Mat image is being rendered correctly, But when I load image from local, I'm seeing blank screen. Is there anything I need to be taken care??

Thank you

venkat
  • 21
  • 7
  • does img.empty() return true? – Asesh Jul 04 '17 at 11:41
  • No... I also checked with OpenCV imshow the img variable contains image. – venkat Jul 04 '17 at 11:42
  • Looks like you have not swapped the chain ie present the back buffer. Are those the only 3 OpenGL API calls you have made to render your image? You will have to invoke glFlush to flush the OpenGL buffers to the window. Besides you are using fixed function pipeline – Asesh Jul 04 '17 at 11:48
  • 1
    @Asesh I have edited my render code – venkat Jul 04 '17 at 11:50
  • @Asesh Does this sufficient?? Or I need anything to be taken care??? – venkat Jul 04 '17 at 11:51
  • This thread will answer your question: https://stackoverflow.com/questions/16809833/opencv-image-loading-for-opengl-texture – Asesh Jul 04 '17 at 11:54
  • @Asesh.. the link says about the byte arrangements... Actually i have checked that too – venkat Jul 04 '17 at 12:11
  • What about OpenGL frustum creation? Have you created one? Your code looks ok but you might have missed something else – Asesh Jul 04 '17 at 14:02

0 Answers0