Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You must simply use opengGL with openCV and not viceversa. You can build your shape in openGL and apply the texture using the tools that opencv come with. For example this is a function to transform a IplImage into a texture for openGL:

GLuint ConvertIplToTexture(IplImage *image){
    GLuint texture;
    glGenTextures(1,&texture);
    glBindTexture(GL_TEXTURE_2D,texture);
    glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
    gluBuild2DMipmaps(GL_TEXTURE_2D,3,image->width,image->height,
                             GL_BGR,GL_UNSIGNED_BYTE,image->imageData);
    return texture;
}

You must simply use opengGL with openCV and not viceversa. You can build your shape in openGL and apply the texture using the tools that opencv come with. For example this is a function to transform a IplImage into a texture for openGL:

GLuint ConvertIplToTexture(IplImage *image){
    GLuint texture;
    glGenTextures(1,&texture);
    glBindTexture(GL_TEXTURE_2D,texture);
    glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
    gluBuild2DMipmaps(GL_TEXTURE_2D,3,image->width,image->height,
                             GL_BGR,GL_UNSIGNED_BYTE,image->imageData);
    return texture;
}