Environment Background With OpenGL

Apprentice
Posts: 10
Joined: 2006.10
Post: #1
I am programming up a basic driving game and don't know how to do a background image (like the sky).

It doesn't have to be great, how is best?

Thanks

Spinner
Quote this message in a reply
Moderator
Posts: 1,562
Joined: 2003.10
Post: #2
A relatively large textured cube that remains centered on the viewer?
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #3
Don't even bother having it large: you can make it just big enough to have it completely in the view, but turn off the depth buffer. (be sure to draw it first)
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #4
What akb825 said, except, I'd like to add that it's easy enough to make a dynamic one using layers of textured spheres.
Quote this message in a reply
Member
Posts: 254
Joined: 2005.10
Post: #5
TomorrowPlusX Wrote:What akb825 said, except, I'd like to add that it's easy enough to make a dynamic one using layers of textured spheres.
Don't you mean 'relatively easy'? Huh
Quote this message in a reply
Member
Posts: 33
Joined: 2005.08
Post: #6
so the spheres mesh together, but then rotate so it looks like the clouds are moving? or what do you mean?
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #7
He means you can have a series of spheres that have different textures on them. That way you can add different layers to the sky, or, as you said, you can also move one sphere to create movement.
Quote this message in a reply
Apprentice
Posts: 10
Joined: 2006.10
Post: #8
So I need to call
Code:
    glDisable(GL_DEPTH_TEST);
    background();
    glEnable(GL_DEPTH_TEST);

But then how do I create and texture the sphere?

I don't really care about a realistic sky, I just want to apply a sky texture panorama something like

[Image: urban_sky.jpg93fe09bc-a4ce-40a8-907b-a83...dLarge.jpg]

I am not sure how to (or even if I need to) use gluNewQuadric

Thanks

Spinner
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #9
Code:
//global or class variable
GLUquadric *sphere;

//in initialization
sphere  = gluNewQuadric();
gluQuadricTexture(sphere, GL_TRUE);

//in draw function
//bind and enable textures
//all numbers are arbitrary
gluSphere(sphere, radius, numSlices, numStacks);

//in quit function
gluDeleteQuadric(sphere);
You may need to experiment and need to rotate the sphere 90 degrees one way or another, but it really is that simple. Or you could also draw a cube. (but the sphere will give you less distortion) Just to be sure to disable the depth test and lighting before drawing. Oh, and for your texture: be careful, since you will need textures that are a power of 2. There is GL_TEXTURE_RECTANGLE_ARB, but then the generated texture coordinates wouldn't work. (since they go from 0-1, and GL_TEXTURE_RECTANGLE_ARB go from 0-width and 0-height.

For what numbers to choose, you can choose a smallish number, like 10, for the radius. (it doesn't really matter due to the perspective, as long as it isn't cut off by the view frustum) You can also pick smallish numbers for the number of slices and stacks, since you don't need a perfect sphere. Something like 10 each should do fine. You can also put the sphere itself in a display list to speed up the drawing.
Quote this message in a reply
Moderator
Posts: 1,562
Joined: 2003.10
Post: #10
Rather than glDisable(GL_DEPTH_TEST) / glEnable(GL_DEPTH_TEST), you'll probably want glDepthMask(GL_FALSE) / glDepthMask(GL_TRUE). That way your background won't be written to the depth buffer when you draw it.
Quote this message in a reply
Apprentice
Posts: 10
Joined: 2006.10
Post: #11
Thanks, that was just what I was after. Looks pretty good, even with a really low res texture.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #12
I was under the impression that disabling depth testing also disabled depth writing, although this may only apply to OpenGL ES.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #13
Disabling depth testing does indeed disable writing. If you want writing but no testing, you need to enable it, but set the DepthFunc to ALWAYS. Testing with no writing uses a DepthMask of FALSE, as has been said.
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #14
akb825 Wrote:He means you can have a series of spheres that have different textures on them. That way you can add different layers to the sky, or, as you said, you can also move one sphere to create movement.

Exactly. Also, I render my stars and planets and sun as tangential textured quads. This way they can be much higher resolution than the clouds. Further, I can do per-vertex colors on the outermost sphere to create atmospheric effects, such as a horizon color biased by proximity to bright objects like the sun, so you can have a reddish tint near a sunset.
Quote this message in a reply
Moderator
Posts: 1,562
Joined: 2003.10
Post: #15
OneSadCookie Wrote:Disabling depth testing does indeed disable writing.
Interesting. I had no idea.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Environment mapping MACnus 6 3,889 Jul 13, 2005 08:43 AM
Last Post: MACnus
  dynamic environment mapping orange144 6 4,234 Jul 7, 2004 06:13 PM
Last Post: tod_baudais
  Character Environment Collision Detection NYGhost 1 2,609 Sep 30, 2003 09:05 AM
Last Post: MacFiend
  Cube Environment PowerMacX 3 3,080 Aug 7, 2003 09:36 PM
Last Post: MattDiamond