PDA

View Full Version : how to draw lines?



10-16-2000, 08:52 AM
to draw lines moving from left to right and vice versa, up to down and vice versa?
please help with the code?
http://www.opengl.org/discussion_boards/ubb/confused.gif

BK
10-16-2000, 03:44 PM
You can do it the same way you draw any primitive in OpenGL :

glBegin(...) and glEnd().

For lines you can use





glBegin(GL_LINES);
glVertex2f(x1,y1);
glVertex2f(x2,y2);
glEnd();



x1,y1 are the start position and x2,y2 are the end, assuming you are only doing 2D drawing.

Find the redbook examples somewhere they have all of this stuff and more in it.

Antonio
10-17-2000, 06:39 AM
If you want to move the lines just define a delta for each coordinate that will be added each frame. For instance:

delta = 1.0;
...
void renderScene(){

x1 += delta;
x2 += delta;

...
Then just use the code form the previous reply.
}

In this case the line will move from the left ot the right. The variable delta controls the speed, the higher the value the faster the line moves.

Antonio www.fatech.com/tech (http://www.fatech.com/tech)