OpenGL Pixel Buffer Object setup issue
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
- In the main loop
- the updatePixels() function
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;
}
}
}
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.
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.
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.
As for been a Mac and IOS forum, I'll take that in consideration.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| OpenGL ES2 matrix setup (humbly crawling back) | Fenris | 2 | 5,239 |
Aug 31, 2011 06:47 AM Last Post: Fenris |
|
| Combining OpenGL vertex data into 1 object | Jmcclane | 0 | 2,704 |
Jun 17, 2011 12:03 PM Last Post: Jmcclane |
|
| [CoreGraphics] Image manipulation - pixel by pixel | g00se | 5 | 7,122 |
Jul 28, 2010 08:27 AM Last Post: ThemsAllTook |
|
| ? Find color value of 'pixel' in color buffer? | Elphaba | 1 | 3,505 |
Jul 22, 2009 01:23 PM Last Post: Bachus |
|
| OpenGL Texture from Char* Buffer | gradyeightythree | 0 | 3,391 |
May 15, 2009 08:26 PM Last Post: gradyeightythree |
|

