Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Unwanted vertical offset

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2010
    Posts
    2

    Unwanted vertical offset

    I am attempting to draw a 2D texture full-screen, but am faced with a vertical offset, as seen in the following image:


    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:
    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.

    Code :
    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

  2. #2
    Junior Member Newbie
    Join Date
    Aug 2010
    Posts
    2

    Re: Unwanted vertical offset

    Forgot to mention that this is running on Ubuntu 9.10 64-bit and OpenGL 3.3.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •