Hi,
I need to display mutiple images resting in cuda’s memory to screen and then refresh them so that it gets displayed as video stream … .How can I do this with a Pixel Buffer object … As of now I am generating 4 textures and mapping these to GL_QUADS but all of the Quads have the same texture regardless of whatever I set them too… Here is the code …
[codebox]void initOpenGLBuffers(float w_new,float h_new,int subWindow_index)
{
printf(“Creating GL texture…\n”);
glEnable(GL_TEXTURE_2D);
//glGenTextures(1, &(gl_Tex[subWindow_index]));
glBindTexture(GL_TEXTURE_2D, gl_Tex[subWindow_index]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,w_new,h_new,0, GL_RGBA, GL_UNSIGNED_BYTE, h_Src[subWindow_index]);
printf(“Texture created.\n”);
printf(“Creating PBO…\n”);
//glGenBuffers(1, &(gl_PBO[subWindow_index]));
glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, gl_PBO[subWindow_index]);
glBufferData(GL_PIXEL_UNPACK_BUFFER_ARB, w_new * h_new * 4, h_Src[subWindow_index], GL_STREAM_COPY);
cutilSafeCall( cudaGLRegisterBufferObject(gl_PBO[subWindow_index]) );
CUT_CHECK_ERROR_GL();
printf(“PBO created.\n”);
glRotatef(180, 0, 0, 1);
glRotatef(180, 0 ,1, 0);
shader = compileASMShader(GL_FRAGMENT_PROGRAM_ARB, shader_code);
if (g_FrameBufferObject) {
delete g_FrameBufferObject; g_FrameBufferObject = NULL;
}
}void subdisplayFunc(int index)
{
//cutStartTimer(hTimer);
unsigned int *d_dst = NULL;
cutilSafeCall( cudaGLMapBufferObject((void**)&d_dst, gl_PBO[index] ) );
cutilSafeCall( CUDA_Bind2TextureArray());
runSubImageFilters(d_dst,index);
cutilSafeCall( CUDA_UnbindTexture() );
cutilSafeCall( cudaGLUnmapBufferObject(gl_PBO[index]) );
// Common display code path
{
glClear(GL_COLOR_BUFFER_BIT);
glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, imageW[index], imageH[index], GL_RGBA, GL_UNSIGNED_BYTE,BUFFER_DATA(0) );
glBegin(GL_QUADS);
glTexCoord2f(0,1); glVertex2f(-1, +1);
glTexCoord2f(1,1); glVertex2f(1, +1);
glTexCoord2f(1, 0); glVertex2f(+1, -1);
glTexCoord2f(0, 0); glVertex2f(-1, -1);
glEnd();
glFinish();
}
if(frameCounter == frameN){
frameCounter = 0;
if(g_FPS){
g_FPS = false;
}
}
glutSwapBuffers();
glutPostRedisplay();
}
[/codebox]