iDevGames Forums
OpenGL Pixel Buffer Object setup issue - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Graphics & Audio Programming (/forum-9.html)
+--- Thread: OpenGL Pixel Buffer Object setup issue (/thread-10516.html)



OpenGL Pixel Buffer Object setup issue - dotbianry - Jan 6, 2013 06:58 AM

Hello!

I'm trying to render a texture on a quad using the PBO,the quad is displayed but the texterure doesn't show up on it.

This is how I've set up things:

- Before the main loop

Code:
drawMode = 0;
imageData = new GLubyte[DATA_SIZE];
memset(imageData, 0, DATA_SIZE);

glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
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_RGBA8, IMAGE_WIDTH, IMAGE_HEIGHT, 0, PIXEL_FORMAT,           GL_UNSIGNED_BYTE, (GLvoid*)imageData);
glBindTexture(GL_TEXTURE_2D, 0);

    glGenBuffersARB = (PFNGLGENBUFFERSARBPROC)wglGetProcAddress("glGenBuffersARB");
    glBindBufferARB = (PFNGLBINDBUFFERARBPROC)wglGetProcAddress("glBindBufferARB");
    glBufferDataARB = (PFNGLBUFFERDATAARBPROC)wglGetProcAddress("glBufferDataARB");
    glBufferSubDataARB = (PFNGLBUFFERSUBDATAARBPROC)wglGetProcAddress("glBufferSubDataARB");
    glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC)wglGetProcAddress("glDeleteBuffersARB");
    glGetBufferParameterivARB = (PFNGLGETBUFFERPARAMETERIVARBPROC)wglGetProcAddress("glGetBufferParameterivARB");
    glMapBufferARB = (PFNGLMAPBUFFERARBPROC)wglGetProcAddress("glMapBufferARB");
    glUnmapBufferARB = (PFNGLUNMAPBUFFERARBPROC)wglGetProcAddress("glUnmapBufferARB");

    pboMode = 1;    

    glGenBuffersARB(2, pboIds);
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboIds[0]);
    glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, DATA_SIZE, 0, GL_STREAM_DRAW_ARB);
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboIds[1]);
    glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, DATA_SIZE, 0, GL_STREAM_DRAW_ARB);
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);




- In the main loop

Code:
static int index = 0;
int nextIndex = 0;                  // pbo index used for next frame

    glBindTexture(GL_TEXTURE_2D, textureId);
    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboIds[index]);

    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, PIXEL_FORMAT, GL_UNSIGNED_BYTE, 0);

    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pboIds[nextIndex]);

    glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, DATA_SIZE, 0, GL_STREAM_DRAW_ARB);
    GLubyte* ptr = (GLubyte*)glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, GL_WRITE_ONLY_ARB);
    if(ptr)
    {
        // update data directly on the mapped buffer
        updatePixels(ptr, DATA_SIZE);
        glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB); // release pointer to mapping buffer
    }

    glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glPushMatrix();

glBindTexture(GL_TEXTURE_2D, textureId);
glColor4f(1, 0, 1, 1);
glBegin(GL_QUADS);
glNormal3f(0, 0, 1);
glTexCoord2f(0.0f, 0.0f);   glVertex3f(-1.0f, -1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);   glVertex3f( 1.0f, -1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f);   glVertex3f( 1.0f,  1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);   glVertex3f(-1.0f,  1.0f, 0.0f);
glEnd();

glBindTexture(GL_TEXTURE_2D, 0);  
glPopMatrix();

- the updatePixels() function

Code:
void updatePixels(GLubyte* dst, int size)
     {

   unsigned int a,b,c,h;
if(!dst)
    return;
int* ptr = (int*)dst;

for(int i = 0; i < height; ++i)
{
    for(int j = 0; j < width; ++j)
    {
          h = (j+(width*i))*4;  
         a = video[0] << 16;  
         b = video[h+1] << 8;
         c = int(video[h+2]) << 0;

        *ptr = a+b+c ;
        ++ptr;
    }
}      

}



RE: OpenGL Pixel Buffer Object setup issue - ThemsAllTook - Jan 6, 2013 10:38 AM

After a quick skim of the code, one possible problem I see is that you're not enabling GL_TEXTURE_2D anywhere.

An aside: I see you're using WGL. Just so you know, this is a Mac and iOS programming forum, so it might not be the best place to ask if you want help with Windows programming. We can answer pure OpenGL questions like this one (assuming the problem doesn't stem specifically from WGL), but you might get more help from a forum that isn't specific to a platform other than the one you're writing for.


RE: OpenGL Pixel Buffer Object setup issue - dotbianry - Jan 6, 2013 11:03 AM

I've just enabled texture_2D and it seems the problem is from somewhere else.

As for been a Mac and IOS forum, I'll take that in consideration.