# Texture coords for a dome function

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

## Recommended Posts

i have a mdae a dome function for use in a game i am making, the only problme is im unsure of how to generate texture coords for it so one texture covers the whole thing, possilby even making itso i could make it a sweeping dphere instead (with a sweep angle for how much of a sphere to create) any help would be appreciated. here is the code
void glDome(unsigned int LAYERS, unsigned int SLICES, float RADIOUSX, float RADIOUSY, float RADIOUSZ) {
unsigned int l;
unsigned int s;
long double x, y, z, w;
long double PI = 3.1415926535897932384;
long double PI2 = PI * 2;
long double HALFPI = PI / 2;
long double vx[LAYERS][SLICES];
long double vy[LAYERS][SLICES];
long double vz[LAYERS][SLICES];

// Generate Verticies
for (l = 0; l < LAYERS; l++) {
y = sin(l * HALFPI / LAYERS);
w = cos(l * HALFPI / LAYERS);

for(s = 0; s < SLICES; s++) {
x = sin(PI + s * PI2 / SLICES) * w;
z = cos(PI + s * PI2 / SLICES) * w;
vx[LAYERS - (l + 1)][s] = x * RADIOUSX;
vy[LAYERS - (l + 1)][s] = y * RADIOUSY;
vz[LAYERS - (l + 1)][s] = z * RADIOUSZ;
}
}

// Generate the triangle fan for the top
glBegin(GL_TRIANGLE_FAN);
glVertex3f(vx[0][0],vy[0][0],vz[0][0]);
for (s = 0; s <= SLICES; s++) {
glNormal3f(vx[0][s],vy[0][s],vz[0][s]);
glVertex3f(vx[0][s],vy[0][s],vz[0][s]);
}
glEnd();

// Generate the sides
for (l = 1; l < LAYERS; l++) {
glBegin(GL_TRIANGLE_STRIP);
for (s = 0; s <= SLICES; s++) {
glNormal3f(vx[l][s],vy[l][s],vz[l][s]);
glVertex3f(vx[l-1][s],vy[l-1][s],vz[l-1][s]);
glVertex3f(vx[l][s],vy[l][s],vz[l][s]);
}
glEnd();
}
}


##### Share on other sites
I use the following function for my skybox (which is a textured sphere), and it works just fine. Hope it helps

n is the resolution

void RenderSphere( float c_x, float c_y, float c_z, float r, int n )
{
int i = 0;
int j = 0;

float theta1 = 0.0;
float theta2 = 0.0;
float theta3 = 0.0;

float e_x = 0.0f;
float e_y = 0.0f;
float e_z = 0.0f;

float p_x = 0.0f;
float p_y = 0.0f;
float p_z = 0.0f;

if( r < 0 )
r = -r;

if( n < 0 )
n = -n;

if( n < 4 || r <= 0 )
{
glBegin(GL_POINTS);
glVertex3f( c_x, c_y, c_z );
glEnd();
return;
}

for( j = 0; j < n/2; ++j )
{
theta1 = j * TWOPI / n - PIDIV2;
theta2 = (j + 1) * TWOPI / n - PIDIV2;

for( i = 0; i <= n; i++ )
{
theta3 = i * TWOPI / n;

e_x = cosf(theta2) * cosf(theta3);
e_y = sinf(theta2);
e_z = cosf(theta2) * sinf(theta3);
p_x = c_x + r * e_x;
p_y = c_y + r * e_y;
p_z = c_z + r * e_z;

glNormal3f( e_x, e_y, e_z );
glTexCoord2f( i/(float)n,2*(j+1)/(float)n );
glVertex3f( p_x, p_y, p_z );

e_x = cosf(theta1) * cosf(theta3);
e_y = sinf(theta1);
e_z = cosf(theta1) * sinf(theta3);
p_x = c_x + r * e_x;
p_y = c_y + r * e_y;
p_z = c_z + r * e_z;

glNormal3f( e_x, e_y, e_z );
glTexCoord2f( i/(float)n,2*j/(float)n );
glVertex3f( p_x, p_y, p_z );
}
glEnd();
}
}

##### Share on other sites
the only thing is that my radius and resolution are more than one variable, making you method of generating the correct texure coods unable to generate the correct coords for mine...

##### Share on other sites
Projecting a rectangular texture onto a sphere will always result in distortion. Is there a specific reason why you don't use a sky box with a cube map instead?

• 21
• 15
• 9
• 17
• 13