Index: branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.cc
===================================================================
--- branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.cc	(revision 7760)
+++ branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.cc	(revision 7768)
@@ -1,14 +1,14 @@
 /*
-   orxonox - the future of 3D-vertical-scrollers
-
-   Copyright (C) 2004 orx
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2, or (at your option)
-   any later version.
+	orxonox - the future of 3D-vertical-scrollers
+
+	Copyright (C) 2004 orx
+
+	This program is free software; you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation; either version 2, or (at your option)
+	any later version.
 
 ### File Specific:
-   main-programmer: hdavid, amaechler
+	main-programmer: hdavid, amaechler
 */
 
@@ -19,4 +19,6 @@
 
 #include "glincl.h"
+#include "graphics_engine.h"
+
 
 #include "parser/tinyxml/tinyxml.h"
@@ -52,9 +54,43 @@
 {
 	//Default values
+
+	CloudEffect::setNoise(map32);
+
 }
 
 bool CloudEffect::activate()
 {
-	PRINTF(0)( "Activating CloudEffect ");
+	PRINTF(0)( "Activating CloudEffect\n");
+
+	//Our cloud function  
+	CloudEffect::overlapOctaves(map32, map256);
+	CloudEffect::expFilter(map256);
+
+	for(int i=0; i<256; i++)         //Set cloud color value to temporary array
+		for(int j=0; j<256; j++) 
+		{
+			float color = map256[i*256+j]; 
+			texture[i][j][0] = color;
+			texture[i][j][1] = color;
+			texture[i][j][2] = color;
+		}
+
+		/* for(int n=0; n<256; n++) {
+			for(int i=0; i<256; i++)
+				PRINTF(0)("%f ", map256[n*i]);
+			PRINTF(0)("\n");
+		} */
+
+	unsigned int ID;                 //Generate an ID for texture binding
+	glGenTextures(1, &ID);           //Texture binding 
+	glBindTexture(GL_TEXTURE_2D, ID);
+
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+	
+	gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, 256, 256, GL_RGB, GL_UNSIGNED_BYTE, texture);
+
 }
 
@@ -65,6 +101,150 @@
 }
 
+void CloudEffect::draw() const
+{
+	glPushAttrib(GL_ENABLE_BIT);
+	glEnable(GL_TEXTURE_2D);
+	glMatrixMode(GL_MODELVIEW);
+	glPushMatrix();
+
+	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+	glEnable(GL_TEXTURE_2D);
+
+	//glLoadIdentity();
+
+	//glMatrixMode(GL_TEXTURE);        //Let's move the clouds from left to right
+	//static float x;    
+	//x+=0.01f;
+	//glTranslatef(x,0,0);
+
+	glBegin(GL_QUADS);
+		// Front Face
+		glTexCoord2f(0.0f, 0.0f); glVertex3f(-100.0f, -100.0f,  100.0f);	// Bottom Left Of The Texture and Quad
+		glTexCoord2f(1.0f, 0.0f); glVertex3f( 100.0f, -100.0f,  100.0f);	// Bottom Right Of The Texture and Quad
+		glTexCoord2f(1.0f, 1.0f); glVertex3f( 100.0f,  100.0f,  100.0f);	// Top Right Of The Texture and Quad
+		glTexCoord2f(0.0f, 1.0f); glVertex3f(-100.0f,  100.0f,  100.0f);	// Top Left Of The Texture and Quad
+	glEnd(); 
+
+	glPopMatrix();
+	glPopAttrib();
+
+}
+
 void CloudEffect::tick (float dt)
 {
-
-}
+}
+
+/* 
+	Random noise generator
+*/
+float CloudEffect::noise(int x, int y, int random)
+{
+		int n = x + y * 57 + random * 131;
+		n = (n<<13) ^ n;
+		return (1.0f - ( (n * (n * n * 15731 + 789221) +
+						1376312589)&0x7fffffff)* 0.000000000931322574615478515625f);
+}
+
+/*
+	Set noise for the 32*32 noise map:
+*/
+void CloudEffect::setNoise(float  *map)
+{
+	float temp[34][34];
+
+/* We declare a temporary array to make our function cleaner. Why does the array hold 34*34 elements instead of 32*32? This is because we will need extra elements for side and corner mirroring, as we shall see soon. */
+
+	int random = rand() % 5000;
+
+	for (int y = 1; y < 33; y++)
+		for (int x = 1; x < 33; x++)
+			temp[x][y] = 128.0f + CloudEffect::noise(x,  y,  random) * 128.0f;
+
+	// Seamless cloud
+	for (int x=1; x<33; x++)
+	{
+		temp[0][x] = temp[32][x];
+		temp[33][x] = temp[1][x];
+		temp[x][0] = temp[x][32];
+		temp[x][33] = temp[x][1];
+	}
+	temp[0][0] = temp[32][32];
+	temp[33][33] = temp[1][1];
+	temp[0][33] = temp[32][1];
+	temp[33][0] = temp[1][32];
+
+	// We mirror the side and corner elements so our final cloud will be seamless without any ugly borders showing.
+	for (int y=1; y<33; y++)
+		for (int x=1; x<33; x++)
+		{
+			float center = temp[x][y]/4.0f;
+			float sides = (temp[x+1][y] + temp[x-1][y] + temp[x][y+1] + temp[x][y-1])/8.0f;
+			float corners = (temp[x+1][y+1] + temp[x+1][y-1] + temp[x-1][y+1] + temp[x-1][y-1])/16.0f;
+
+			map32[((x-1)*32) + (y-1)] = center + sides + corners;
+		}
+}
+
+/*
+	Interpolation - average the value of each pixel value with that of its neighbors' values.
+*/
+float CloudEffect::interpolate(float x, float y, float  *map)
+{
+	int Xint = (int)x;
+	int Yint = (int)y;
+
+	float Xfrac = x - Xint;
+	float Yfrac = y - Yint;
+
+	int X0 = Xint % 32;
+	int Y0 = Yint % 32;
+	int X1 = (Xint + 1) % 32;
+	int Y1 = (Yint + 1) % 32;
+
+	float bot = map[X0*32 + Y0] + Xfrac * (map[X1*32 + Y0] - map[X0*32 + Y0]);
+	float top = map[X0*32 + Y1] + Xfrac * (map[X1*32 +  Y1] - map[X0*32 + Y1]);
+
+	return (bot + Yfrac * (top - bot));
+}
+
+
+/*
+	Octaves are overlapped together to give cloud more turbulence. We will use four octaves for our cloud.
+*/
+void CloudEffect::overlapOctaves(float  *map32, float  *map256)
+{
+	for (int x=0; x<256*256; x++)
+	{
+		map256[x] = 0;
+	}
+
+	for (int octave=0; octave<4; octave++)
+		for (int x=0; x<256; x++)
+			for (int y=0; y<256; y++)
+			{
+				float scale = 1 / pow(2, 3-octave);
+				float noise = CloudEffect::interpolate(x*scale, y*scale , map32);
+
+				//The octaves are added together with the proper weight factors.
+				//You could replace pow(2, i) with 1<<i for faster computation
+				map256[(y*256) + x] += noise / pow(2, octave);
+			}
+}
+
+
+/*
+	Filter the noise with exponential function
+*/
+void CloudEffect::expFilter(float  *map)
+{
+	float cover = 20.0f;
+	float sharpness = 0.95f;
+
+	for (int x=0; x<256*256; x++)
+	{
+		float c = map[x] - (255.0f-cover);
+		if (c<0)     c = 0;
+		map[x] = 255.0f - ((float)(pow(sharpness, c))*255.0f);
+	}
+}
Index: branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.h
===================================================================
--- branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.h	(revision 7760)
+++ branches/atmospheric_engine/src/lib/graphics/effects/cloud_effect.h	(revision 7768)
@@ -27,9 +27,21 @@
 		virtual bool deactivate();
 
+		virtual void draw() const;
 		virtual void tick(float dt);
 
-		
 	private:
-		
+		// Basic noise map 32x32
+		float map32[32 * 32];
+
+		// The cloud map
+		float map256[256 * 256];
+
+		char texture[256][256][3];       //Temporary array to hold texture RGB values 
+
+		float noise(int x, int y, int random);
+		void setNoise(float  *map);
+		float interpolate(float x, float y, float  *map);
+		void overlapOctaves(float  *map32, float  *map256);
+		void expFilter(float  *map);
 };
 
Index: branches/atmospheric_engine/src/lib/graphics/effects/volfog_effect.cc
===================================================================
--- branches/atmospheric_engine/src/lib/graphics/effects/volfog_effect.cc	(revision 7760)
+++ branches/atmospheric_engine/src/lib/graphics/effects/volfog_effect.cc	(revision 7768)
@@ -33,5 +33,4 @@
 #ifndef GL_EXT_fog_coord
 #define GL_EXT_fog_coord 1
-
 typedef void (APIENTRY * PFNGLFOGCOORDFEXTPROC) (GLfloat coord);
 typedef void (APIENTRY * PFNGLFOGCOORDFVEXTPROC) (const GLfloat *coord);
@@ -163,5 +162,5 @@
 	
 	int i;
-	//glLoadIdentity();
+	glLoadIdentity();
 
 	
