Ask Your Question

OpenCV error by using OpenGL

asked 2013-11-09 05:50:18 -0500

Nightrush0179 gravatar image

updated 2013-11-09 05:57:28 -0500

Hi, I am trying to copy a Mat in a ogl::Texture2D.

void CVMat_ImageWidget::setImage(cv::Mat img)
    cv::ogl::Texture2D texture(img);


But I always get the error "OpenCV Error: OpenGL API call (Can't load OpenGL extension [glBindBuffer]) in IntGetProcAddress, file C:\LIBS\OpenCV_2_4_6\src\opencv\modules\core\src\gl_core_3_1.cpp, line 141". I built OpenCV (2.4.6) with OpenGL so this shouldn´t be the problem. What is the problem ?

edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted

answered 2014-08-06 08:59:45 -0500

protonmesh gravatar image

I was having the same problem. My mistake:

Making OpenGL calls, for example like the one you posted: cv::ogl::Texture2D texture(img);

without first having an OpenGL context current on the calling thread. Because a texture2D needs to be created within a certain encapsulated context.

The OpenGL context can constructed either through the OpenCV provided HighGUI module, using namedWindow(<window_name>, WINDOW_OPENGL), which creates a new window and corresponding OpenGL context, and sets the context of that window active (look at setOpenGLContext(..) for switches between contexts of multiple namedWindows ) .

The context can also be created through 3rd party windowing / multimedia libraries (GLUT, OpenTK, SDL, GLFW, etc.) or full blown UI toolkits (Qt, wxWidgets) (see Whichever library you use to create the context, ensure that the context is made active (the library should provide a method for this) and all subsequent calls from the ogl:: namespace should work.

edit flag offensive delete link more

answered 2014-07-29 01:31:52 -0500

MRDaniel gravatar image

updated 2014-07-29 01:32:52 -0500


You need to do a little more work than this.

int loadTexture_Ipl(IplImage *image, GLuint *text) {

if (image==NULL) return -1;

glGenTextures(1, text);

glBindTexture( GL_TEXTURE_2D, *text ); //bind the texture to it's array



glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image->width, image->height,0, GL_BGR, GL_UNSIGNED_BYTE, image->imageData);

return 0;


The above is pretty old school. Are there no examples?

Clearly you are using a cv::Mat but i think you can use in place of when defining the texture.

edit flag offensive delete link more



please, anything with IplImages in it is not old school, but plain outdated.

berak gravatar imageberak ( 2014-07-29 01:35:27 -0500 )edit

Question Tools


Asked: 2013-11-09 05:50:18 -0500

Seen: 953 times

Last updated: Aug 06 '14