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!

Recommended Answers

All 9 Replies

Time for some ASCII art

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

You see how 2 points can make a rect?

Learn more about OpenGl and C++ by visiting some links here

Time for some ASCII art

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

You see how 2 points can make a rect?

Learn more about OpenGl and C++ by visiting some links here

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.

What part don't you understand then?

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

Some links:

glRect / glRectf

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();

Some links:

glRect / glRectf

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.