How to draw a "fine" rectangle using GL_LINES ?

Hi guy,

I use the following codes to draw a rectangle:

glBegin(GL_LINES);

glVertex2i(100,100)
glVertex2i(200,100)

glVertex2i(200,100)
glVertex2i(200,200)

glVertex2i(200,200)
glVertex2i(100,200)

glVertex2i(100,200)
glVertex2i(100,200)

glEnd();


The upper left of the rectangle is “losing 1-pixel”, any suggestion for this error?

Thanks! :slight_smile:

why dont u use
glRectf(100,100,200,200).

Btw, the code u posted should be

  
glVertex2i(100,200);
glVertex2i(100,100);

Another alternative is to use GL_LINE_STRIP instead of GL_LINES.

The problem with pixel alignment is probably because of your matrix setup, have a look at the faq on this website about transformations.

Mikael

Originally posted by Only Sophoo…:
[b]why dont u use
glRectf(100,100,200,200).

Btw, the code u posted should be

  
glVertex2i(100,200);
glVertex2i(100,100);

[/b]
yes, i know glrecti() do the trick for me.

but the requirement is to draw rectangle from line segments.

i just want to find out the reason.

thanks anyway :slight_smile:

Originally posted by mikael_aronsson:
[b]Another alternative is to use GL_LINE_STRIP instead of GL_LINES.

The problem with pixel alignment is probably because of your matrix setup, have a look at the faq on this website about transformations.

Mikael[/b]
replaced with GL_LINE_STRIP but the same alignment problem.