## lizhiyuan

dear all

any one know howt to use openGL with vc++? i encountered some problem.thanks a lot.

why glRectf(x1,y1,x2,y2) can draw a rectangle, here (x1,y1),(x2,y2),just two points,anone can exsplain to me? thanks. sorry to ask such question.no choice!

## Nick Evan 4,005

Time for some ASCII art

``````(x1,y1)
|----------------------|
|                      |
|                      |
|                      |
|----------------------|
(x2,y2)``````

You see how 2 points can make a rect?

## lizhiyuan

Time for some ASCII art

``````(x1,y1)
|----------------------|
|                      |
|                      |
|                      |
|----------------------|
(x2,y2)``````

You see how 2 points can make a rect?

dear freind, thanks a lot. i read the tutortial of openGL now,but i really don't understand well,just explain to me how does this function work? that means how to draw a rectangle. thanks again.

## Nick Evan 4,005

What part don't you understand then?

## lizhiyuan

What part don't you understand then?

i mean in openGL how to draw this rectangle use function glRectf(); how does this glRect() work..thanks

## Nick Evan 4,005

Nice tutorial (just find glRect in the file)

After initialising OpenGL you can draw a rectangle with glRect like:

``glRect(10,20,40,50)``

This would draw a 30x30 (40-10=30 and 50-20=30) rectangle with the left-top-corner on 10,20.

You could also use glVertex to draw a rectangle:

``````glBegin(GL_POLYGON);
glVertex2(x1, y1);
glVertex2(x2,y1);
glVertex2(x2, y2);
glVertex2(x1, y2);
glEnd();``````

## lizhiyuan

Nice tutorial (just find glRect in the file)

After initialising OpenGL you can draw a rectangle with glRect like:

``glRect(10,20,40,50)``

This would draw a 30x30 (40-10=30 and 50-20=30) rectangle with the left-top-corner on 10,20.

You could also use glVertex to draw a rectangle:

``````glBegin(GL_POLYGON);
glVertex2(x1, y1);
glVertex2(x2,y1);
glVertex2(x2, y2);
glVertex2(x1, y2);
glEnd();``````

thanks a lot friend. actually i would lik to draw cube and cylinder. just want to how to draw a rectangle first. after i have read openGL tutorial once, couldn't understand well. so ask you.

could you give me explain how to draw a cube and cylinder? thanks.

2d or 3d?

2d or 3d?

3d

## Nick Evan 4,005

That can't be done with glRect()
I could write you some samplecode, but someone else has already done that, so why re-invent the wheel?
Here's a link with everything you need.