PDA

View Full Version : How to draw a "fine" rectangle using GL_LINES ?



powervr
09-26-2004, 11:48 PM
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! :)

Only Sophoo...
09-27-2004, 02:48 AM
why dont u use
glRectf(100,100,200,200).

Btw, the code u posted should be


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

mikael_aronsson
09-27-2004, 03:49 AM
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

powervr
09-27-2004, 04:09 AM
Originally posted by Only Sophoo...:
why dont u use
glRectf(100,100,200,200).

Btw, the code u posted should be


glVertex2i(100,200);
glVertex2i(100,100);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 :)

powervr
09-27-2004, 04:19 AM
Originally posted by mikael_aronsson:
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.

Mikaelreplaced with GL_LINE_STRIP but the same alignment problem.