In this tutorial we see how we can acces to OpenCV functions and use the images we process with it to use in our OpenGL program.

To use an OpenCV image (IplImage) and use it as an OpenGL textures we mus use this function.

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
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

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;

}

This function only get data image and store it as an image Texture.

We can get a camera image and use it  to texture aplane, to do it we need a function to update the texture data, this we can do in OpenGL main loop or in glutiddleFunc as show

//En la funcion donde se actualizen los datos
frame = cvQueryFrame( capture );
if( frame ){
loadTexture_Ipl(frame, &texture);
}

Download source