我计划开发一种使用C ++,QT 4.7.4和OpenGL进行实时视频处理的工具,并且我使用的是Visual Studio2008。我检查了许多网站,但是由于尝试使用PBO,我的代码无法正常工作。目前,我想象下面的步骤序列:
是正确的吗?
在成功获取多个图像之后,我将以视频开始。
看看我是否想念我的代码解释一下: 在里面 我使用glut,所以我以:
进行了初始化。glutInit(&iArgc, cppArgv);
glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA);
glutInitWindowSize(1000, 1000);
glutInitWindowPosition(500, 10);
glutCreateWindow("Texture");
glEnable(GL_TEXTURE_2D);
在我的主要信息中:
GLuint pboIds[2];
glGenBuffers(N_MAX_BUFFERS, pboIds);
//for two buffers
glBindBuffer(GL_PIXEL_PACK_BUFFER, pboIds[iBuffer]);
glBufferData(GL_PIXEL_PACK_BUFFER, DATA_SIZE, NULL, GL_STREAM_DRAW);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
glReadBuffer(GL_FRONT);
glGenTextures(1,&texture)
在功能loadImage中,我执行步骤1:
QImage image;
image.load(name);
imageGL = QGLWidget::convertToGLFormat(image);
imageGL = (image.convertToFormat(QImage::Format_RGB888));//format is important
第2步:
for (int iBuffer = 0; iBuffer < N_MAX_BUFFERS; ++iBuffer)
{
glBindBuffer(GL_PIXEL_PACK_BUFFER_EXT, pboIds[iBuffer]);
glBufferData(GL_PIXEL_PACK_BUFFER_EXT, DATA_SIZE, NULL, GL_STREAM_DRAW);
void * pPixelsPBO = glMapBuffer(GL_PIXEL_PACK_BUFFER_EXT, GL_WRITE_ONLY);
// copy original image into the buffer (Step 2)
if(pPixelsPBO)
{
pPixelsPBO = new unsigned char[imageGL.width() * imageGL.height() * 3];
memcpy(pPixelsPBO, imageGL.bits(), DATA_SIZE);
}
glUnmapBuffer(GL_PIXEL_PACK_BUFFER_EXT
glBindBuffer(GL_PIXEL_PACK_BUFFER_EXT, 0);
}
最后是glutDisplayFunc():
//step 3
glBindTexture(GL_TEXTURE_2D, texture);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pboIds[Index]);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, imageGL.width(), imageGL.height(), GL_RGB, GL_UNSIGNED_BYTE, 0);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
///
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, texture);
glColor4f(1, 1, 1, 1);
glBegin(GL_QUADS);
glTexCoord2i(0,0); glVertex2i(0,imageGL.height());
glTexCoord2i(0,1); glVertex2i(0,0);
glTexCoord2i(1,1); glVertex2i(imageGL.width(),0);
glTexCoord2i(1,0); glVertex2i(imageGL.width(),imageGL.height());
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
glutSwapBuffers();
//to load the next data from image
// I do the step 1 et 2 at the end
LoadImg("./Code.jpg");
我在glTexSubImage2D()上仅收到一个错误INVALID_OPERATION 通常表示格式问题,但我检查了许多不同的格式。
我不知道自己是否完全输了,或者我是否成功。
答案 0 :(得分:0)
好吧,我只调用一次glTexImage2D来初始化loadImage函数中的纹理对象:
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR);//GL_NEAREST GL_LINEAR
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(GL_TEXTURE_2D, 0, GL_SRGB8,imageGL.width(), imageGL.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)imageGL.bits());
glBindTexture(GL_TEXTURE_2D, 0);