Index: include/ITexture.h
===================================================================
--- include/ITexture.h	(revision 3536)
+++ include/ITexture.h	(working copy)
@@ -65,6 +65,12 @@
 	/** BurningVideo can handle Non-Power-2 Textures in 2D (GUI), but not in 3D. */
 	ETCF_ALLOW_NON_POWER_2 = 0x00000040,
 
+
+	//Ludvigs added CubeMap flag
+
+	ETCF_CUBEMAP = 0x00000080,
+
+
 	/** This flag is never used, it only forces the compiler to compile
 	these enumeration values to 32 bit. */
 	ETCF_FORCE_32_BIT_DO_NOT_USE = 0x7fffffff
Index: source/Irrlicht/CD3D9Texture.cpp
===================================================================
--- source/Irrlicht/CD3D9Texture.cpp	(revision 3536)
+++ source/Irrlicht/CD3D9Texture.cpp	(working copy)
@@ -9,6 +9,7 @@
 #include "CD3D9Texture.h"
 #include "CD3D9Driver.h"
 #include "os.h"
+#include "CImage.h"
 
 #include <d3dx9tex.h>
 
@@ -32,9 +33,9 @@
 //! rendertarget constructor
 CD3D9Texture::CD3D9Texture(CD3D9Driver* driver, const core::dimension2d<u32>& size,
 						   const io::path& name, const ECOLOR_FORMAT format)
-: ITexture(name), Texture(0), RTTSurface(0), Driver(driver), DepthSurface(0),
+: ITexture(name), Texture(0), CubeTexture(0), RTTSurface(0), Driver(driver), DepthSurface(0),
 	TextureSize(size), ImageSize(size), Pitch(0), ColorFormat(ECF_UNKNOWN),
-	HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(true)
+	HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(true), IsCubeMap(false)
 {
 	#ifdef _DEBUG
 	setDebugName("CD3D9Texture");
@@ -51,9 +52,9 @@
 //! constructor
 CD3D9Texture::CD3D9Texture(IImage* image, CD3D9Driver* driver,
 			   u32 flags, const io::path& name, void* mipmapData)
-: ITexture(name), Texture(0), RTTSurface(0), Driver(driver), DepthSurface(0),
+: ITexture(name), Texture(0), CubeTexture(0), RTTSurface(0), Driver(driver), DepthSurface(0),
 	TextureSize(0,0), ImageSize(0,0), Pitch(0), ColorFormat(ECF_UNKNOWN),
-	HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(false)
+	HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(false), IsCubeMap(false)
 {
 	#ifdef _DEBUG
 	setDebugName("CD3D9Texture");
@@ -321,27 +322,40 @@
 		}
 	}
 
-	HRESULT hr = Device->CreateTexture(optSize.Width, optSize.Height,
-		mipmaps ? 0 : 1, // number of mipmaplevels (0 = automatic all)
-		usage, // usage
-		format, D3DPOOL_MANAGED , &Texture, NULL);
+	HRESULT hr;
 
-	if (FAILED(hr))
+	//Ludvig
+	if(flags & ETCF_CUBEMAP)
 	{
-		// try brute force 16 bit
-		HardwareMipMaps = false;
-		if (format == D3DFMT_A8R8G8B8)
-			format = D3DFMT_A1R5G5B5;
-		else if (format == D3DFMT_R8G8B8)
-			format = D3DFMT_R5G6B5;
-		else
-			return false;
+		//a 6x1 cubemap is expected (up, 4 x around, down)
+		hr = Device->CreateCubeTexture(image->getDimension().Height,mipmaps ? 0 : 1,usage,format,D3DPOOL_MANAGED,&CubeTexture, NULL);
+		//  STDMETHOD(CreateCubeTexture)(THIS_ UINT EdgeLength,UINT Levels,DWORD Usage,D3DFORMAT Format,D3DPOOL Pool,IDirect3DCubeTexture9** ppCubeTexture,HANDLE* pSharedHandle) PURE;
 
+		IsCubeMap=true;
+	}
+	else
+	{
 		hr = Device->CreateTexture(optSize.Width, optSize.Height,
 			mipmaps ? 0 : 1, // number of mipmaplevels (0 = automatic all)
-			0, format, D3DPOOL_MANAGED, &Texture, NULL);
+			usage, // usage
+			format, D3DPOOL_MANAGED , &Texture, NULL);
+
+		if (FAILED(hr))
+		{
+			// try brute force 16 bit
+			HardwareMipMaps = false;
+			if (format == D3DFMT_A8R8G8B8)
+				format = D3DFMT_A1R5G5B5;
+			else if (format == D3DFMT_R8G8B8)
+				format = D3DFMT_R5G6B5;
+			else
+				return false;
+
+			hr = Device->CreateTexture(optSize.Width, optSize.Height,
+				mipmaps ? 0 : 1, // number of mipmaplevels (0 = automatic all)
+				0, format, D3DPOOL_MANAGED, &Texture, NULL);
+		}
 	}
-
 	ColorFormat = Driver->getColorFormatFromD3DFormat(format);
 	setPitch(format);
 	return (SUCCEEDED(hr));
@@ -378,6 +392,69 @@
 		}
 	}
 
+
+
+	if(CubeTexture && image)
+	{
+		D3DSURFACE_DESC desc;
+		CubeTexture->GetLevelDesc(0, &desc);
+
+		TextureSize.Width = desc.Width;
+		TextureSize.Height = desc.Height;
+
+		D3DLOCKED_RECT rect;
+		HRESULT hr;
+
+		//LUD: todo: copy the right rectangles and not just the whole texture to each "face"
+
+		//LPDIRECT3DSURFACE9 pFace;
+
+
+
+
+		//order faces so indata can have its faces like this:
+		//UP, the 4 middle ones interconnected, DOWN
+		//D3DCUBEMAP_FACES FaceOrder[6]={D3DCUBEMAP_FACE_POSITIVE_X,D3DCUBEMAP_FACE_NEGATIVE_X,D3DCUBEMAP_FACE_POSITIVE_Y,D3DCUBEMAP_FACE_NEGATIVE_Y,D3DCUBEMAP_FACE_POSITIVE_Z,D3DCUBEMAP_FACE_NEGATIVE_Z};
+		D3DCUBEMAP_FACES FaceOrder[6]={D3DCUBEMAP_FACE_POSITIVE_Y,  //the UP side
+			D3DCUBEMAP_FACE_NEGATIVE_X,D3DCUBEMAP_FACE_POSITIVE_Z,D3DCUBEMAP_FACE_POSITIVE_X,D3DCUBEMAP_FACE_NEGATIVE_Z //the sides
+			,D3DCUBEMAP_FACE_NEGATIVE_Y}; // the DOWN side
+		for(int i=0;i<6;i++)
+		{
+			int face=(int)FaceOrder[i];
+
+			hr = CubeTexture->LockRect((D3DCUBEMAP_FACES)face, 0, &rect, 0, 0);
+			if (FAILED(hr))
+			{
+				os::Printer::log("Texture data not copied", "Could not LockRect D3D9 Cube Texture.", ELL_ERROR);
+				return false;
+			}
+
+			char *p=(char*)rect.pBits;
+			
+			int *idata=(int*)p;
+			int side=image->getDimension().Height;
+			for(int y=0;y<side;y++)
+			{
+				int pos=i*side;
+				for(int x=0;x<side;x++)
+				{
+					//memcpy / blit?
+					video::SColor col=image->getPixel(pos++,y);
+					idata[x]=col.color;
+				}
+				idata+=rect.Pitch/sizeof(int);
+			}
+
+			hr = CubeTexture->UnlockRect((D3DCUBEMAP_FACES)face,0);
+			if (FAILED(hr))
+			{
+				os::Printer::log("Texture data not copied", "Could not UnlockRect D3D9 Cube Texture.", ELL_ERROR);
+				return false;
+			}
+		}
+		//SAFE_RELEASE(pFace);
+	}
+
 	return true;
 }
 
@@ -491,6 +568,8 @@
 //! returns the DIRECT3D9 Texture
 IDirect3DBaseTexture9* CD3D9Texture::getDX9Texture() const
 {
+	if(IsCubeMap)
+		return(CubeTexture);
 	return Texture;
 }
 
Index: source/Irrlicht/CD3D9Texture.h
===================================================================
--- source/Irrlicht/CD3D9Texture.h	(revision 3536)
+++ source/Irrlicht/CD3D9Texture.h	(working copy)
@@ -102,6 +102,7 @@
 
 	IDirect3DDevice9* Device;
 	IDirect3DTexture9* Texture;
+	IDirect3DCubeTexture9* CubeTexture;
 	IDirect3DSurface9* RTTSurface;
 	CD3D9Driver* Driver;
 	SDepthSurface* DepthSurface;
@@ -114,6 +115,7 @@
 	bool HasMipMaps;
 	bool HardwareMipMaps;
 	bool IsRenderTarget;
+	bool IsCubeMap;
 };
 
 
