# Texturing a Hemisphere/Skydome

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

## Recommended Posts

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

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

##### 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.

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

##### 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 Legacy OpenGL. Maybe that is by intention. If it is not, look it up and make sure you make a proper decision.

1. 1
2. 2
Rutin
21
3. 3
A4L
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633740
• Total Posts
3013621
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!