Infinite sky/terrain with horizon

Started by
4 comments, last by ljbade 15 years, 11 months ago
I would like to find out the best way to render an infinite sky/terrain (or floor/ceiling) that meets at a horizon. I have tried using two quads, blue and green, but when using the gluPerspective matrix I am left with a black band where the two should meet. If I make the quads extreemly large ie from -10,000,000 to +10,000,00 they meet up, but OpenGL glitches when I rotate the camera. (Turn counterclockwise, I loose the terrain, turn clockwise I loose the sky) I also tried to see if I could use fog to fill in the black gap, but it only applies the fog to the bits rendered, still leaving a black gap. I hope to map textures to these quads later on so I can simulate the old school raycasting games (ie. Wolf 3d)
Advertisement
Did you notice that far parameter in gluPerspective? That sets the distance to the far clipping plane. Anything beyond it doesn't get rendered, so you'll never see the horizon the way you're trying to do it.

The right way to do it is to 'cheat'. Just render walls sufficiently far that give an appearance of horizon.
Alternatively, given the application that you describe, you might be able to get away with having the two planes be angled such that they actually do meet, and then, instead of translating and rotating them according to the player's position and direction, you could alter the texture coordinates. If you intend on allowing the player to look up and down, then I imagine that you would want to rotate the planes about the x-axis, at least.

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

size is not important, whats important is making sure that the sky is drawn 'behind' everything else

one method
draw non tranlucent scene
glDepthRange(1.0,1.0) // depthmask(0) also
draw sky
glDepthRange(0.0,1.0)
draw blended stuff

normally the sky etc is drawn with a skybox (google it for info)
Depending on what level of realism and/or quality you want, a skydome (i.e. a half-sphere) may do you better than a skybox.

Other than that, hearken to zedz.
Thanks for that. I was able to 'fake' a horizon by drawing a skybox with top and sides blue, and bottom green.

Here is how I did it:

glPushMatrix();
glScalef(99, 1, 99);

glDepthRange(1.0,1.0);
glBegin(GL_QUADS);

glColor3f(0, 0, 1);
glVertex3f(1, 1, 1);
glVertex3f(-1, 1, 1);
glVertex3f(-1, 1, -1);
glVertex3f(1, 1, -1);

glVertex3f(-1, 1, 1);
glVertex3f(1, 1, 1);
glVertex3f(1, -1, 1);
glVertex3f(-1, -1, 1);

glVertex3f(1, 1, -1);
glVertex3f(-1, 1, -1);
glVertex3f(-1, -1, -1);
glVertex3f(1, -1, -1);

glColor3f(0, 1, 0);
glVertex3f(1, -1, -1);
glVertex3f(-1, -1, -1);
glVertex3f(-1, -1, 1);
glVertex3f(1, -1, 1);

glEnd();
glDepthRange(0.0,1.0);

glPopMatrix();

Also this is drawn before the camera transform is applied so the player will never 'escape'.

Next thing to do is get some form of lighting.

This topic is closed to new replies.

Advertisement