# OpenGL How To Draw Converging Parallel Lines?

This topic is 4914 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi All Thanks in advance for your time. I am new to this forum and new to OpenGL programming. I am trying to draw a converging parallel line. Here is the code which writes the lines in windows environment: void drawOutline(void) { glBegin(GL_LINES); glVertex3f(-0.7f, -0.1f,0.9f); glVertex3f(-0.7f, -0.1f,-0.9f); glEnd(); glBegin(GL_LINES); glVertex3f(0.7f, -0.1f,0.9f); glVertex3f(0.7f, -0.1f,-0.9f); glEnd(); } Now as you can see this is a set of parallel lines along Z-axiz. Now how do I render these something like two rail lines (using projection)? Any help is appreciated. george

##### Share on other sites
I would just make the lines longer

void drawOutline(void){glBegin(GL_LINES);glVertex3f(-0.7f, -0.1f,1000.0f);glVertex3f(-0.7f, -0.1f,-1000.0f);glEnd();glBegin(GL_LINES);glVertex3f(0.7f, -0.1f,1000.0f);glVertex3f(0.7f, -0.1f,-1000.0f);glEnd();}

I made them longer on both sides because I didn't know how you set your coordinate system was set up. And to set up the coordinate system you can do:

glMatrixMode(GL_PROJECTION);gluPerspective(45,1.333,0.1,500);glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt(0,0,0,   0,0,1,   0,1,0);

The arguments for gluPerspective are the field of view (in degrees), the aspect ratio (adjust this with screen resolution), and the near and far clipping planes. (Any closer than 0.1 units to the camera or further than 500m will be cut off.)

gluLookAt is the quick way to set up the view. The first three coordinates are the position of the camera, the next three are the direction that it's looking at (the positive z-axis) and the last three are the camera's up vector (positive y-axis in most cases, you would change this to roll the camera).

##### Share on other sites
Thanks for the post! Well I am a newbie and am trying things. I thought in wondows the maximum co-ordinate value is 1. Am i wrong?

##### Share on other sites
windows and opengl doesnt use the same "distance" when drawing...
in theory, drawing is only limited by the Far Clipping Plane in Opengl... but windows coordinates are within 0-1 I think...

##### Share on other sites
I want to thank "dyerseve" for helping me with the code which does what I wanted. It works! But i am not sure how it works. I have a question about the Code line :

gluPerspective(45,1.333,0.1,500);

Now from what I understand, the 3rd parameter is the "near" value and fourth is the "far" value. Also I think they both are values on the Z axis which increases away from the monitor plane. So a near and far values of 0.1 and 500 means that its an inverted cone (top towards the monitor). Am i right?

##### Share on other sites
That's what would be known as the view frustrum. Also its more like a pyramid with the top lopped off. The base would be the far plane and the top would be the near plane.

Some images here:

http://astronomy.swin.edu.au/~pbourke/stereographics/HET409_2003/frustum.html

-=[ Megahertz ]=-

##### Share on other sites
thanks everyone who is trying to help me out here!!

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 9
• 13
• 9
• 9
• 15
• ### Forum Statistics

• Total Topics
634078
• Total Posts
3015362
×