Followers 0

# Texturing a Hemisphere/Skydome

## 3 posts in this topic

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)
{
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.
0

##### Share on other sites
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.
1

##### Share on other sites
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
0

##### Share on other sites
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.
2

## Create an account

Register a new account