# Thread: OpenGL depth problem/question

1. ## OpenGL depth problem/question

Hello,

I keep running into a problem with depth in the viewport (i assume) when trying to draw just simple lines. I want to draw a set of lines parallel to each other and I am using a loop to do that. The problem that arises though, is when I use glRotatef() function to rotate my "camera", which is technically just rotating everything drawn, the lines that I drew are only appearing to be extended to a certain value, I assume it's 1 but I have no idea if that's what's happening... So basically, what is happening, I think, is the lines just stop being drawn at that point, and when I rotate the view, I get an unpleasant effect of the lines just cut-off there, when I would like to see them go further down, hence creating an effect of further depth.. unfortunately this is not happening. As you can see from the piece of code, all I am doing is drawing a bunch of horizontal lines parallel to each other..

I would greatly appreciate if somebody could explain why this is happening and even more if there is a solution to this and how I should fix it

I assume this has to do something with the viewport and the min and max depth ranges but I am really not sure

I also hope I explained this enough and clearly enough I realize the explanation might be confusing
Code :
```glBegin(GL_LINES);

glColor3f(0.5, 0.5, 0.5);
for(float i = -100; i < 100; i+=0.005){
glVertex3f(i, 0, 1);
glVertex3f(i, 0, -1);
}

glEnd();```

Thank you very much in advance

2. Seems like you have just discovered that the cameras in computer graphics have a far clipping plane against which all the geometry is clipped (not drawn). Check your projection matrix. Here are the functions used to construct such matrices:
http://www.opengl.org/sdk/docs/man2/...erspective.xml
http://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml
The legacy OpenGL maintains two matrices, modelview and projection, so ensure you switch between them depending which one you want to modify (see glMatrixMode).

3. Thanks for your reply. I read over even more tutorials and documentation on the two matrices and the two modes. I tried to modify my code to construct such matrices but all I keep getting is a black screen every time... I think I may be missing something important here. As I mentioned before, my graphics are "destroyed" / "hidden" when I rotate using glRotatef() and I would like them to display appropriately. I would appreciate if you could post a code snippet of the order of method calls that I need to do to properly set up my matrices so that my geometry is clipped the right way.

Thanks a lot

4. You first.
Do not take away from us a nice opportunity to laugh at the nooby code!
Whoops, I mean, show the codes, we will help you to correct it to make it work.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•