Hi!
I'm trying to create a simple skydome for my game.
I am going to use vertex coloring to create a nice sky color that can be changed in realtime. My problem is that I don't get a smooth color transition between the vertices(not animation, ahven't come to that yet). Here's a screenshot to illustrate my problem:
http://img82.exs.cx/my.php?loc=img82ℑ=DOME.jpg
I use OpenGL and obviously have GL_SMOOTH set as shade model.
The dome is drawn as a triangle strip from top to bottom in horisontal circles, not as vertical stripes. Maybe that has something to do with it? I don't know...
Anyways, here's the code that I use and found at www.spheregames.com:
void CSky::CreateSkyDome()
{
int theta, phi;
//Allocate memory for the vertices
m_nrVertices = (int)((360/m_dTheta)*(90/m_dPhi)*4);
m_vertices = new Vector3D[m_nrVertices];
//Calculate and store the vertices
int n = 0;
for (phi=0; phi <= 90 - m_dPhi; phi += (int)m_dPhi)
{
for (theta=0; theta <= 360 - m_dTheta; theta += (int)m_dTheta)
{
m_vertices[n].x = m_radius * sinf(DEGTORAD(phi)) * cosf(DEGTORAD(theta));
m_vertices[n].y = m_radius * sinf(DEGTORAD(phi)) * sinf(DEGTORAD(theta));
m_vertices[n].z = m_radius * cosf(DEGTORAD(phi));
n++;
m_vertices[n].x = m_radius * sinf(DEGTORAD((phi+m_dPhi))) * cosf(DEGTORAD(theta));
m_vertices[n].y = m_radius * sinf(DEGTORAD((phi+m_dPhi))) * sinf(DEGTORAD(theta));
m_vertices[n].z = m_radius * cosf(DEGTORAD((phi+m_dPhi)));
n++;
m_vertices[n].x = m_radius * sinf(DEGTORAD(phi)) * cosf(DEGTORAD((theta+m_dTheta)));
m_vertices[n].y = m_radius * sinf(DEGTORAD(phi)) * sinf(DEGTORAD((theta+m_dTheta)));
m_vertices[n].z = m_radius * cosf(DEGTORAD(phi));
n++;
if (phi > -90 && phi < 90)
{
m_vertices[n].x = m_radius * sinf(DEGTORAD((phi+m_dPhi))) * cosf(DEGTORAD((theta+m_dTheta)));
m_vertices[n].y = m_radius * sinf(DEGTORAD((phi+m_dPhi))) * sinf(DEGTORAD((theta+m_dTheta)));
m_vertices[n].z = m_radius * cosf(DEGTORAD((phi+m_dPhi)));
n++;
}
}
}
}
phi is the latitude of the sphere and theta is the longitude(m_dPhi and m_dTheta between each "segment")
And here's my code to draw the dome. I change the color of the vertices according to the y coordinate of each vertex. But as mentioned, I get the problem you see in the screenshot above.
void CSky::RenderSkyDome()
{
//Used to change the color
Vector3D tempVert(m_vertices[0]);
float color = 0;
//Draw the dome as a triangle strip
glBegin(GL_TRIANGLE_STRIP);
for (int i = 0; i < m_nrVertices; i++)
{
//Check to see if we should change the color
if (tempVert.y < m_vertices.y)
{
vert = m_vertices;
glColor3f(color, color, 1.0f);
color += 0.05f;
}
glVertex3f(m_vertices.x, m_vertices.y, m_vertices.z);
}
glEnd();
}
As I said, I found the code to generate the dome on the internet, and I don't fully understand it. But I would be glad if somebody could point out the problem and a solution.
Thanks in advance
William