PDA

View Full Version : Unwanted vertical offset



chrisbbc
08-24-2010, 04:49 AM
I am attempting to draw a 2D texture full-screen, but am faced with a vertical offset, as seen in the following image:
http://www.chrisbaume.co.uk/uploads/offset-small.jpg

The offset is the same every time the code is run. The work I am doing is with CUDA, so an image is copied from CUDA to a PBO, then from the PBO to a texture which is drawn.

Here is the relevant code:

// Set-up
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0);

glGenBuffersARB(1, &pbo);
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, width*height*sizeof(unsigned char), 0, GL_STREAM_DRAW_ARB);
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);

// Render

glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0);

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, width, height, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

glDisable(GL_DEPTH_TEST);

glClear(GL_COLOR_BUFFER_BIT);

glBindTexture(GL_TEXTURE_2D, texture);
glBegin(GL_QUADS);
glTexCoord2f(0.0f,1.0f); glVertex3i(0, height, 0);
glTexCoord2f(0.0f,0.0f); glVertex3i(0, 0, 0);
glTexCoord2f(1.0f,0.0f); glVertex3i(width, 0, 0);
glTexCoord2f(1.0f,1.0f); glVertex3i(width, height, 0);
glEnd();

glXSwapBuffers(dpy, win);

When I draw the PBO directly to the screen using the following code, it works perfectly which leads me to conclude that the PBO is fine. Perhaps there is a problem copying the image from the PBO to the texture, or with the co-ordinates.


glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo);
glDrawPixels(width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0);
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);

The screen is set up using xlib and everything appears to line-up fine apart from this texture.

Any help you can give is much appreciated! Thanks.


Chris

chrisbbc
08-27-2010, 03:00 AM
Forgot to mention that this is running on Ubuntu 9.10 64-bit and OpenGL 3.3.