Index: sky.c
===================================================================
--- sky.c	(revision 87)
+++ sky.c	(revision 88)
@@ -10,6 +10,14 @@
 #include "headers/sky.h"
 #endif
 
+#define SPHERE_MAX_DETAIL 30
+#define SPHERE_DEFAULT_DETAIL 25
+//when the function goes to stable, i'll put the next 3 in common.h
+static char raydium_atmosphere_enable_tag;
+static GLfloat angle1;
+static GLfloat angle2;
+static char sphere_generated;
+
 void raydium_sky_box_cache(void)
 {
 raydium_texture_current_set_name("BOXfront.tga");
@@ -120,3 +128,120 @@
 glDepthMask(GL_TRUE);
 
 }
+
+void raydium_sky_sphere_render(GLfloat x, GLfloat y, GLfloat z,int detail)
+{	
+	int i, j;
+	GLfloat currentradious,z1,z2,ang1;
+	//static cause this will be used to store the vertices of the sphere
+	static GLfloat p[SPHERE_MAX_DETAIL][SPHERE_MAX_DETAIL][3];	
+
+	//keeping safe the current matrix
+	glPushMatrix();	
+	//increasing angles to simulate orbit
+	angle1	+=	0.2;
+	angle2	+=	0.02;
+	//turning off "specials" for render
+	glDisable(GL_LIGHTING);
+	glDisable(GL_FOG);
+	glDisable(GL_TEXTURE_2D);
+	glColor4fv(raydium_background_color);
+	glDepthMask(GL_FALSE);
+	glEnable(GL_BLEND);
+	glBlendFunc(GL_DST_COLOR,GL_SRC_COLOR);
+	//MAKING THE SPHERE
+	
+	//check if the points are already calculated.
+	//there is no reason to enter constantly.
+	if(sphere_generated!=1)
+	{
+		//getting the points of the sphere, but no drawing
+		for(i=0;i<=detail;i++)
+		{
+			//getting the radious for each section of the sphere
+			currentradious		=	raydium_trigo_sin(180*((float)i/(float)detail));
+			//getting the heights for each section of the sphere
+			z1					=	raydium_trigo_cos(180*((float)i/(float)detail));		
+			for(j=0;j<=detail;j++)
+			{
+				ang1		=	360*((float)j/(float)detail);
+				p[i][j][0]	=	currentradious * raydium_trigo_cos(ang1);
+				p[i][j][1]	=	currentradious * raydium_trigo_sin(ang1);
+				p[i][j][2]	=	z1;
+			}
+		}
+		sphere_generated	=	1;
+	}
+
+	//locating the modelview in the pos of the camera
+	glTranslatef(x,y,z);
+	//rotating according the orbit angles(ugly)
+	glRotatef(angle2,0,0,1);
+	glRotatef(angle1,1,0,0);
+	//now drawing with the obtained values
+	for(i=0;i<detail;i++)
+	{
+		for(j=0;j<detail;j++)
+		{
+			//calculating colors
+			z1	=	1-(float)i/detail;
+			z2	=	1-(float)(i+1)/detail;
+			
+			glBegin(GL_TRIANGLES);
+			
+			glColor4f(z1,z1,z1,1);
+			glVertex3f(p[i][j][0],p[i][j][1],p[i][j][2]);
+			
+			glColor4f(z1,z1,z1,1);
+			glVertex3f(p[i][j+1][0],p[i][j+1][1],p[i][j+1][2]);
+			
+			glColor4f(z2,z2,z2,1);
+			glVertex3f(p[i+1][j][0],p[i+1][j][1],p[i+1][j][2]);
+			
+			glColor4f(z2,z2,z2,1);
+			glVertex3f(p[i+1][j][0],p[i+1][j][1],p[i+1][j][2]);
+			
+			glColor4f(z2,z2,z2,1);
+			glVertex3f(p[i+1][j+1][0],p[i+1][j+1][1],p[i+1][j+1][2]);
+			
+			glColor4f(z1,z1,z1,z1);
+			glVertex3f(p[i][j+1][0],p[i][j+1][1],p[i][j+1][2]);
+			
+			glEnd();
+		}
+	}
+
+	//restoring previus states
+	glDisable(GL_BLEND);
+	glEnable(GL_TEXTURE_2D);
+	if(raydium_fog_enabled_tag) glEnable(GL_FOG);
+	if(raydium_light_enabled_tag) glEnable(GL_LIGHTING);
+	glDepthMask(GL_TRUE);
+	glPopMatrix();
+}
+
+void raydium_atmosphere_enable(void)
+{
+	raydium_atmosphere_enable_tag	=	1;
+	//this will force to recalculate the sphere once
+	sphere_generated				=	0;
+	raydium_log("atmosphere created");
+}
+
+void raydium_atmosphere_disable(void)
+{
+	raydium_atmosphere_enable_tag=0;
+}
+
+void raydium_atmosphere_render( GLfloat x, GLfloat y, GLfloat z,int detail)
+{
+	if(raydium_atmosphere_enable_tag)
+	{	
+		raydium_sky_sphere_render(x,y,z,detail);
+	}
+}
+
+char raydium_atmosphere_check()
+{
+	return raydium_atmosphere_enable_tag;
+}