opencv影象轉換為opengl的texture
//opengl
#include <GL/glew.h>
#include <GL/freeglut.h>
GLuint left_Tex;
GLuint right_Tex;
// GLUT initialization
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH );
// Configure Window Postion
//glutInitWindowPosition(50, 25);
// Configure Window Size
glutInitWindowSize(10, 10);
// Create Window
glutCreateWindow("ZED OGL interop");
// init GLEW Library
glewInit();
// Create an OpenGL texture and register the CUDA resource on this texture for left image (8UC4 -- RGBA)
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &left_Tex);
glBindTexture(GL_TEXTURE_2D, left_Tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//glTexCoord2f(0, 1.0);
glBindTexture(GL_TEXTURE_2D, 0);//0 represents unbind status
以上是初始化和開闢記憶體的工作的,接下來就是使用的時候將資料匯入到記憶體上。
glBindTexture(GL_TEXTURE_2D, right_Tex);//選中要使用的記憶體號
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, right_extension.cols, right_extension.rows, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, right_extension.ptr());//GL_BGRA_EXT,right_extension is cv::Mat
glBindTexture(GL_TEXTURE_2D, 0);//用完解綁