Sign in to follow this  
blueshogun96

Texturing a Hemisphere/Skydome

Recommended Posts

blueshogun96    2264
I'm having a bit of trouble figuring out how to add a texture to this half sphere generation code. As the title says, I'm trying to create a simple skydome, but I'm attempting to use a horizontal texture @ 512x128, so it has to wrap around. I've searched the net for days, but have never found a single ounce of code that does what I need to do here. This is what I have so far:

[CODE]
void RenderDome()
{
#define PI 3.1415926535897932384626433832795
#define K1 PI/20.f
#define K2 PI/20.f
#define R 100
GLfloat i,j;
GLfloat x,y,z;
static int t1,t2;
for (u=0;u<=PI;u+=K1)
{
glBegin(GL_QUAD_STRIP);
for (v=0;v<=PI+K2;v+=K2)
{
x=R*cos(i)*sin(i);
y=R*sin(i)*sin(i);
z=R*cos(j);
glVertex3f(x,y,z);
x=R*cos(i+K1)*sin(j);
y=R*sin(i+K1)*sin(j);
glVertex3f(x,y,z);
}
glEnd();
}
}
[/CODE]

So, how would generate the texture coordinates from this? Any ideas? Thanks.

Share this post


Link to post
Share on other sites
C0lumbo    4411
Your code doesn't seem to initialise i or j, so it's a little confusing and definitely won't work, also why would both loops go through 180 degrees, surely one should be going up only 90 degrees for a hemisphere? I'd concentrate on getting all that working before you add texturing.

But when you get around to texturing, then assuming u is representing the horizontal (and ranges from 0 to pi) and v is representing the vertical (and ranges from 0 to half pi), I'd imagine you want something like this.

float fU = u / PI;
float fV = v / (PI * 0.5f);

Or, if you want to waste a bit less of your texture resolution at the singularity at the top of the dome, then you could use:

float fV = cosf(v);

Note that using this sort of texture mapping might mean an ugly singularity at the top of your skydome, which can only really be hidden by using a flat colour at the top of your texture. That might not be a problem for you. However, it might be a better idea to use a skybox instead of a skydome for this reason - it makes generating the textures a little more complicated though, but there are tools out there.

Share this post


Link to post
Share on other sites
andrew111    310
The [i]More OpenGL Game Programming[/i] book's [url="http://glbook.gamedev.net/GLBOOK/glbook.gamedev.net/moglgp/code.html"]source code[/url] has an example under [i]Chapter09/SkyDomesWin32[/i]. I'm not sure if the book explains it or not. Edited by andrew111

Share this post


Link to post
Share on other sites
larspensjo    1561
One common way to make a skydome is to use a cube map. That is, using 6 quads instead. That means the textures will get distorted near the edges and corners, but the trick is to use textures that are compensated for this. If you are using predefined textures, then you can use special programs that generate nice-looking skies, adapted for cube maps.

Note also that you are using [url="http://www.opengl.org/wiki/Legacy_OpenGL"]Legacy OpenGL[/url]. Maybe that is by intention. If it is not, look it up and make sure you make a proper decision.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this