Jump to content
  • Advertisement
Sign in to follow this  
ljbade

OpenGL Infinite sky/terrain with horizon

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!