Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: What does GL_FILL mean, -exactly-

  1. #1
    Guest

    What does GL_FILL mean, -exactly-

    Alright, I'm working on a game, and I'm writing an overlay. My overlay loads the identity matrix for projection and modelview, then sets the projection matrix to an Ortho2D mode (0, 0, width, height) where width and height are equal to the pixel size of my viewport.

    Now in modelview, logic assumes that:

    glBegin(GL_POINTS);
    glVertex2i(50, 50);
    glend();

    will place draw a pixel and coordinate 50, 50. No problem, this works fine.

    Now I have a 'window'. A window is defined as (x1, y1),(x2, y2). No brainer. So I do a

    glBegin(GL_POLYGON);
    vertexes..
    glEnd();

    or, better yet, use the glRecti() command.

    That's great. Now here's my problem. I draw my 'window' twice. Once, I draw it filled, and it gets rendered as such:

    111111
    111111
    111111

    Then, the second draw, I render it in glPolygonMode(GL_LINE). And now it looks like:

    222222
    2111112
    2111112
    2222222

    New pixels were drawn above and to the left of the window, and pixels within the window were overwritten on the right and bottom sides. In addition, the top-left pixel is NOT drawn.

    So, I guess my question is, is this behavior defined? Where? Am I going about this wrongly? I want pixel-exact drawing, can I do this with OGL? Is this behavior the same on ALL OGL implementations/hardware? If so, that means I can just work around how it is working here, and expect my 'hacked' code to work fine on all implementations?

    Any help would be appreciated.

    Keith Jackson

  2. #2
    Guest

    Re: What does GL_FILL mean, -exactly-

    Crap, my fancy ASCII art did not work right on this board. It should be:

    Code :
     
      111111
      111111
      111111
     
      222222
     2111112
     2111112
     2222222

  3. #3
    Senior Member Regular Contributor
    Join Date
    Sep 2001
    Location
    Eastern USA
    Posts
    218

    Re: What does GL_FILL mean, -exactly-

    How the actual rasterization is done is implementation specific, and there's no dictation that any given call MUST produce a given result.

    So, maybe on someone else's system the bottom right pixel will be gone, or there will be no corners, or all corners.

    In conclusion, you'll need to do some code modifications (perhaps drawing four lines, but that still might not be exact in all instances) or live with it.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: What does GL_FILL mean, -exactly-

    Can be a pixel center problem. Remember that the lower left corner of the window, coordinate (0, 0), is the corner of the lower left pixel. The center of lower left pixel is located at 0.5 offser along both the X and Y axes. If you want to map integer coordinates to pixel coordinates, you must offset the projection matrix by one half.
    Code :
    glOrtho(-0.5, width-0.5, 0.5, height-0.5, -1, 1);
    [This message has been edited by Bob (edited 12-07-2002).]

  5. #5
    Guest

    Re: What does GL_FILL mean, -exactly-

    So then I guess my question is, how can I get pixel-exact results with OpenGL? Can i simply not do it? Are there are libraries or extensions or anything for it? Can I use DirectDraw and OGL together? WHat do I do? I need to draw pixels in exact pixels, and it to be same on all systems.

    Keith

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: What does GL_FILL mean, -exactly-

    Sure you can. Using the projection matrix I gave you, and the modelview matirx set to identity, you can have exact control over which pixels are drawn or not.

  7. #7
    Guest

    Re: What does GL_FILL mean, -exactly-

    So where can I find more information about this 0.5 offset, pixels being defined by their lower left corner, etc? I have the red and blue books but I'm not finding it..

    Keith

  8. #8
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: What does GL_FILL mean, -exactly-

    The Red book (I'm assuming the 1.2 version), appendix G, OpenGL Correcness Tips. It uses 0.375 instead of 0.5 as I did though.

    It will help if you take a look at picture 2-1 (p. 37) also. To make it easier to see, forget about the thin lines and imagine the values in the upper right corner says (5, 5) instead. You now have a picture of a 5x5 pixel area with lines (the thick ones) separating each pixel. If you call gluOrtho2D(0, 5, 0, 5), coordinate (0, 0) will map to the lower left corner, and (5, 5) to the upper left corner. Each line has it's own integer coordinate value.

    Now, note than coordinate (1, 1) is in the exact corner of where four pixels meet. If you draw a point there, which pixel is actually drawn? If you want exact control over what pixel is drawn, you have to specify half integers values. (0.5, 0.5) for example is the center of the lower left pixel, and (4.5, 1.5) is the center of the pixel one up from the bottom right corner.

  9. #9
    Junior Member Newbie
    Join Date
    Dec 2002
    Posts
    9

    Re: What does GL_FILL mean, -exactly-

    Alright, so, the offset makes sense, but still does not fix my problem.

    What I'm trying to do is draw a 'window'. A rectangle that is alpha blended over whatever is there. Then, if it's the 'current' window, I want it to have a border. So I draw each window with GL_FILL mode, and then draw them with GL_LINE mode. The outline on some edges are 'inside' the drawn window, and some edges have a new pixel added.

    So, given this problem, needing a window where I can have borders like this, how should I do it? I don't think it's this pixel offset thing like we've been discussing. It's always offset on one or more edges, offset by 0.375, 0.5, or whatever.

    Keith

  10. #10
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: What does GL_FILL mean, -exactly-

    Post some code so we can see what you do.

Page 1 of 2 12 LastLast

Similar Threads

  1. How to draw a polygon with GL_FILL and GL_LINE
    By glSpider in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-05-2009, 03:44 AM
  2. nothing appear using GL_FILL
    By coda in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 01-15-2004, 06:15 PM
  3. screen shows nothign when using GL_FILL for evaluators
    By coda in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 01-14-2004, 04:36 PM
  4. GL_FILL and GL_LINE at once?
    By cunny in forum OpenGL: Advanced Coding
    Replies: 8
    Last Post: 08-02-2002, 05:50 AM
  5. GL_LINE and GL_FILL at once??
    By cunny in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-01-2002, 02:07 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