OpenGL快速渲染2d图像

时间:2017-09-10 11:39:30

标签: c++ opengl rendering

我当前的绘图管道就像互联网上的大多数现有示例,但是当同时渲染多个视频时,这种渲染2D纹理管道可能会非常慢。有办法改善吗?有谁可以提供一些例子?谢谢。

// when initializing
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.cols,
         image.rows, 0, GL_RGB, GL_UNSIGNED_BYTE,
         NULL);
glBindTexture(GL_TEXTURE_2D, 0);
glFinish();


// another thread to load image
cv::Mat image = loadImage();

//initializeGL()
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//paintGL()
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glClearColor(0.0, 0.0, 0.0, 1.0);
glLoadIdentity();

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image.cols,
             image.rows,  GL_RGB, GL_UNSIGNED_BYTE,
             image.data);
glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(0, 0, 0.0f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f(width, 0.0f, 0.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f(width, height,  0.0f);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(0,  height,  0.0f);
glEnd();

0 个答案:

没有答案