• Create Account

## Texturing a Hemisphere/Skydome

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1blueshogun96  Members

2166
Like
0Likes
Like

Posted 10 November 2012 - 07:35 PM

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:

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();
}
}


So, how would generate the texture coordinates from this? Any ideas? Thanks.
Follow Shogun3D on the official website: http://shogun3d.net

"Yo mama so fat, she can't be frustum culled." - yoshi_lol

"One objection to a “critique of C#” would be that you can’t talk about C# without talking about the whole “.Net experience”. However, one can approach the topic of Hitler without a complete discussion of Nationalist Socialism, so I feel justified." - Steve White.

### #2C0lumbo  Members

4072
Like
1Likes
Like

Posted 11 November 2012 - 07:03 AM

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.

### #3CaptainMurphy  Members

310
Like
0Likes
Like

Posted 12 November 2012 - 01:42 AM

The More OpenGL Game Programming book's source code has an example under Chapter09/SkyDomesWin32. I'm not sure if the book explains it or not.

Edited by andrew111, 12 November 2012 - 01:42 AM.

### #4larspensjo  Members

1561
Like
2Likes
Like

Posted 12 November 2012 - 03:02 AM

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 Legacy OpenGL. Maybe that is by intention. If it is not, look it up and make sure you make a proper decision.
Current project: Ephenation.
Sharing OpenGL experiences: http://ephenationopengl.blogspot.com/

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.