Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to render perfect wireframed rectangle in 2D mode with OpenGL?
    primarykey
    data
    text
    <p><strong>Edit:</strong> just so you know: I have not solved this problem perfectly yet, currently I am using 0.5px offset, it <em>seems</em> to work, but as others have said, it is not the "proper" solution. So I am looking for the real deal, the diamond exit rule solution didn't work at all.</p> <p>I believe it is a bug in the graphics card perhaps, but if so, then any professional programmer should have their bullet-proof solutions for this, right?</p> <p><strong>Edit:</strong> I have now bought a new nvidia card (had ATI card before), and i still experience this problem. I also see the same bug in many, many games. So i guess it is impossible to fix in a clean way?</p> <p>Here is image of the bug:</p> <p><img src="https://i.stack.imgur.com/LBFXn.png" alt="enter image description here"></p> <p>How do you overcome this problem? Preferrably a non-shader solution, if possible. I tried to set offset for the first line when i drew 4 individual lines myself instead of using wireframe mode, but that didnt work out very well: if the rectangle size changed, it sometimes looked perfect rectangle, but sometimes even worse than before my fix.</p> <p>This is how i render the quad:</p> <pre><code>glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glBegin(GL_QUADS); glVertex2f(...); glVertex2f(...); glVertex2f(...); glVertex2f(...); glEnd(); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); </code></pre> <p>Yes, I know I can use vertex arrays or VBO's, but that isn't the point here.</p> <p>I also tried <code>GL_LINE_LOOP</code>, but it didn't fix the bug.</p> <p><strong>Edit:</strong> One solution is at, which works so far: <a href="https://stackoverflow.com/questions/10040961/opengl-pixel-perfect-2d-drawing">Opengl pixel perfect 2D drawing</a> by Lie Ryan: </p> <blockquote> <p>Note that OpenGL coordinate space has no notion of integers, everything is a float and the "centre" of an OpenGL pixel is really at the 0.5,0.5 instead of its top-left corner. Therefore, if you want a 1px wide line from 0,0 to 10,10 inclusive, <strong>you really had to draw a line from 0.5,0.5 to 10.5,10.5.</strong></p> <p>This will be especially apparent if you turn on anti-aliasing, if you have anti-aliasing and you try to draw from 50,0 to 50,100 you may see a blurry 2px wide line because the line fell in-between two pixels.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload