View Full Version : OpenGL : Problem with display
12-27-2007, 03:49 PM
I thing I have a very weird problem...(actually 2) :p
I try to make the solar system. I have created the planets and I put rotations to each planet around the sun.I have draw all the planets at 0,0,0 and then translate them. My last planet is at Xmax=4900,(xmin=-4900) the highest y is at 200 and my z because of the rotation around y is again (near=-5000) and (far=5000). My problem is that if I try to use
when I run my program I see that all my planets have inside them many black points that are turn on and off every time.Now if I put it like this:
I can see normal(clean) spheres.
My other problem is that during the rotation, they rotate normal but while they are rotating at the front of the sun they are getting smaller size and when they are going back of the sun normal size.
I would appreciate any help.
12-27-2007, 04:47 PM
Never set znear to 0. Instead, set it to a largest number that still suits your needs. Soemthing like gluPerspective(90,1.0,1,5000)
12-27-2007, 04:50 PM
having zNear = 0 is not a good idea. this is explained in detail in hundreds of math chapters about perspective projection.
setting zNear to, say 0.1 and zFar to 5000 troubles your z-buffer precision. after your projection transformation, your viewing frustrum is mapped into the unit cube, depth-values ranging from 0.0 (near) to 1.0 (far). So, this may (better: will) give you some nice z-buffer aliasing/fighting problems.
this seems to be the problem that you describe when you say
when I run my program I see that all my planets have inside them many black points that are turn on and off every time.
having gluPerspective(90,1.0,5000,0); set like this (which doesn't make much sense in common) you flip signs in the mathematical calculations (you should get more familiar with matrix maths and how and what the functions like gluPerspective DO, before you randomly change parameters) which may cause the trouble that Spheres further away are bigger.
btw: our solar system doesn't fit well in a viewing frustrum (means, see all 9 planetes at once) when keeping relations between planetary diameter and distance to the sun.
hope this helps.
12-28-2007, 06:09 AM
Ok first I have put gluPerspective(90,1.0,0.1,5000)but now when the planets are going to rotate behind the sun are vanish and then appear at the front. This problem I think maybe has to do with my
gluLookAt(0,1000,5000, 0,0,0, 0,1,0).
I cannot understand what I have to do to solve my problem with the black spots into my spheres...
12-28-2007, 07:16 AM
You did enable depth testing right? If you don't, the object that is drawn last will be on top, regardless of the depth it is drawn at. It could explain the spots, maybe there's some funky depth fighting going on.
12-29-2007, 02:09 PM
I have put glEnable(GL_DEPTH_TEST)
12-30-2007, 04:34 AM
If I put gluPerspective(40.0,(GLdouble)x/(GLdouble)y,0.1,5000.0) my spheres are all normal without any black spots (I don't know why) but my problem is that when my spheres are rotating behind the sun (180-360 degrees) are vanish and then appear at front...
12-30-2007, 04:38 AM
Ok I think I solve my problem...
If I put
everything working find without any problem....
but I don't know why....
12-31-2007, 02:17 AM
Well, apparently the objects are in the 5000-10000 depth range for 180-360 degrees if it's working correctly now...
12-31-2007, 08:25 AM
Panayiotis, znear shoud refer to the smallest z-coordinate you still need to be visible, while zfar refers to the largest z-coordinate you still need to be visible. You shoudl try to keep the ratio zfar/znear as big as possible. So if you still need to see your planets at the distance of 10000, then set zfar to 10000. Probably you won't get very near to your planets though, so set znear to largest possible value.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.