Results 1 to 2 of 2

Thread: Offset for 2D-paintings

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2011
    Location
    Germany
    Posts
    9

    Offset for 2D-paintings

    Hello all,

    I created a window which is 600x400 pixels. I checked the size with another tool, the size is correct.
    I use OpenGL and minGW on Windows XP

    Now I want to paint a red frame around this window with this code

    glViewport(0, 0, 600, 400); // x, y, w, h

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, 599, // left/right
    0, 399, // bottom/top
    1, -1); // near/far

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glColor3f(1.0, 0.0, 0.0);
    glBegin(GL_LINE_LOOP);
    glVertex2d(0, 0);
    glVertex2d(599, 0);
    glVertex2d(599, 399);
    glVertex2d(0, 399);
    glEnd();
    Unfortunately the frame has a y-offset by 1 pixel, that mean the upper line is outside the window and the bottom line is 1 pixel above the lower window bottom.
    Where does this offset come from?
    Did I a mistake and what must I that the coordinates of the win32-window matches the OpenGL-coordinates (of course the top of OpenGL is the bottom of the Win32-window)

    Thanks again for your help

  2. #2
    Senior Member Regular Contributor imported_tksuoran's Avatar
    Join Date
    Mar 2008
    Location
    Cambridge, UK
    Posts
    223

    Re: Offset for 2D-paintings

    You should draw lines from/to pixel centers, eg. glVertex2d(0.5, 0.5) instead of 0, 0. Have a look at figure 3.4:

    http://www.opengl.org/documentation/....1/node47.html

    A diamond shaped region of height 1 is placed around each fragment center; those regions that the line segment exits cause rasterization to produce corresponding fragments.

Similar Threads

  1. VBO and offset
    By V-man in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 04-17-2008, 03:51 AM
  2. Line offset?
    By imported_Groovounet in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 04-14-2008, 05:28 PM
  3. POLYGON offset
    By KeSh in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-30-2004, 10:58 PM
  4. Polygon offset
    By Suf in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-07-2003, 05:39 AM
  5. What's polygon offset?
    By KRONOS in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-24-2000, 06:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean