[DirectX9] Working 3D textures / Cube Maps

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

OK, the HDR file is loading, binding and rendering. But... it's screwy at the moment. Will fix that bug ASAP.

Image
Image
Steel Style
Posts: 168
Joined: Sun Feb 04, 2007 3:30 pm
Location: France

Post by Steel Style »

Cool dlangdev. Also do you think that you can make another room (same size same structure but prettier ? I think it's will give to this irrlicht example a new fresh look.
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

I was thinking of setting up a room taking design cues from Frank Lloyd Wright. They'd look pretty cool rendered in Irrlicht.

http://flickr.com/search/?q=robie%20hou ... 1308%40N00

http://www.peterbeers.net/interests/flw ... lus_03.htm


Image

Image
Image
fmx

Post by fmx »

can't deny you've been making (neat) progress dlangdev :P

maybe its time you made another thread somewhere and leave this topic for questions and such?
MasterD
Posts: 153
Joined: Sun Feb 15, 2004 4:17 pm
Location: Lübeck, Germany
Contact:

Irrlicht 1.5 patch

Post by MasterD »

I've never done a patch before, but I hope that this is all correct:

This patches Irrlicht 1.5 with Cubetextures support (not: Volumetextures), as described in the first and a following post.

Note: This patch disables Dx8 support.

A detailed Note:
For some reasons, the call to loadTextureFromFile from NullDriver::getTexture(char) removed the passing of the filename as hashname (Irr 1.5). This has been reinserted and I'm currently not fully aware of possible side-effects, but it works afaik.

Code: Select all

Index: include/IrrCompileConfig.h
===================================================================
--- include/IrrCompileConfig.h	(revision 24)
+++ include/IrrCompileConfig.h	(working copy)
@@ -85,7 +85,8 @@
 and this to the linker settings: -ld3dx9 -ld3dx8 **/
 #if defined(_IRR_WINDOWS_API_) && (!defined(__GNUC__) || defined(IRR_COMPILE_WITH_DX9_DEV_PACK))
 
-#define _IRR_COMPILE_WITH_DIRECT3D_8_
+// Cubetextures are used and D3DX.. is used, which is only available without DX8.
+//#define _IRR_COMPILE_WITH_DIRECT3D_8_
 #define _IRR_COMPILE_WITH_DIRECT3D_9_
 
 #endif
Index: source/Irrlicht/CD3D9Driver.cpp
===================================================================
--- source/Irrlicht/CD3D9Driver.cpp	(revision 24)
+++ source/Irrlicht/CD3D9Driver.cpp	(working copy)
@@ -713,6 +713,10 @@
 	return new CD3D9Texture(surface, this, TextureCreationFlags, name);
 }
 
+video::ITexture* CD3D9Driver::createDeviceDependentTextureFromFile(const char* filename)
+{
+	return new CD3D9Texture(filename, this, TextureCreationFlags, filename);
+} 
 
 //! Enables or disables a texture creation flag.
 void CD3D9Driver::setTextureCreationFlag(E_TEXTURE_CREATION_FLAG flag,
Index: source/Irrlicht/CD3D9Driver.h
===================================================================
--- source/Irrlicht/CD3D9Driver.h	(revision 24)
+++ source/Irrlicht/CD3D9Driver.h	(working copy)
@@ -288,6 +288,10 @@
 		//! THIS METHOD HAS TO BE OVERRIDDEN BY DERIVED DRIVERS WITH OWN TEXTURES
 		virtual video::ITexture* createDeviceDependentTexture(IImage* surface, const char* name);
 
+		//! returns a device dependent texture from a file
+		//! THIS METHOD HAS TO BE OVERRIDDEN BY DERIVED DRIVERS WITH OWN TEXTURES
+		virtual video::ITexture* createDeviceDependentTextureFromFile(const char* filename); 
+
 		//! returns the current size of the screen or rendertarget
 		virtual const core::dimension2d<s32>& getCurrentRenderTargetSize() const;
 
Index: source/Irrlicht/CD3D9Texture.cpp
===================================================================
--- source/Irrlicht/CD3D9Texture.cpp	(revision 24)
+++ source/Irrlicht/CD3D9Texture.cpp	(working copy)
@@ -17,7 +17,8 @@
 // compiling with both D3D8 and 9, causing it not to work in the D3D9 device.
 // So mipmapgeneration is replaced with my own bad generation in d3d 8 when
 // compiling with both D3D 8 and 9.
-// #define _IRR_USE_D3DXFilterTexture_
+// For usage of Cubetextures, D3DX9 is needed.
+#define _IRR_USE_D3DXFilterTexture_
 #endif // _IRR_COMPILE_WITH_DIRECT3D_8_
 
 #ifdef _IRR_USE_D3DXFilterTexture_
@@ -31,7 +32,7 @@
 
 //! rendertarget constructor
 CD3D9Texture::CD3D9Texture(CD3D9Driver* driver, const core::dimension2d<s32>& size, const char* name)
-: 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),
 	HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(true)
 {
@@ -50,7 +51,7 @@
 //! constructor
 CD3D9Texture::CD3D9Texture(IImage* image, CD3D9Driver* driver,
 					   u32 flags, const char* name)
-: 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),
 HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(false)
 {
@@ -91,13 +92,43 @@
 	}
 }
 
+//! constructor for volumetric textures
+CD3D9Texture::CD3D9Texture(const char * fileName, CD3D9Driver* driver,
+                     u32 flags, const char* name) 
+: ITexture(name), Texture(0), CubeTexture(0), RTTSurface(0), Driver(driver), DepthSurface(0),
+TextureSize(0,0), ImageSize(0,0), Pitch(0),
+HasMipMaps(false), HardwareMipMaps(false), IsRenderTarget(false)
+{
+	#ifdef _DEBUG
+	setDebugName("CD3D9Texture");
+	#endif
 
+	const bool generateMipLevels = Driver->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS);
+
+	Device=driver->getExposedVideoData().D3D9.D3DDev9;
+	if (Device)
+		Device->AddRef();
+
+	HRESULT hr = D3DXCreateCubeTextureFromFile(
+		Device,
+		fileName,
+		&CubeTexture);
+
+	if(FAILED(hr))
+	{
+		os::Printer::log("D3D9Texture: Failed to load volume texture from file", fileName, ELL_ERROR);
+	}
+} 
+
 //! destructor
 CD3D9Texture::~CD3D9Texture()
 {
 	if (Texture)
 		Texture->Release();
 
+	if (CubeTexture)
+		CubeTexture->Release(); 
+
 	if (RTTSurface)
 		RTTSurface->Release();
 
@@ -509,7 +540,10 @@
 //! returns the DIRECT3D9 Texture
 IDirect3DBaseTexture9* CD3D9Texture::getDX9Texture() const
 {
-	return Texture;
+	if(!Texture && CubeTexture)
+		return CubeTexture;
+	else
+		return Texture; 
 }
 
 
Index: source/Irrlicht/CD3D9Texture.h
===================================================================
--- source/Irrlicht/CD3D9Texture.h	(revision 24)
+++ source/Irrlicht/CD3D9Texture.h	(working copy)
@@ -34,6 +34,10 @@
 	//! rendertarget constructor
 	CD3D9Texture(CD3D9Driver* driver, const core::dimension2d<s32>& size, const char* name);
 
+	//! constructor for cube textures
+	CD3D9Texture(const char* filename, CD3D9Driver* driver,
+		u32 flags, const char* name); 
+
 	//! destructor
 	virtual ~CD3D9Texture();
 
@@ -104,6 +108,7 @@
 
 	IDirect3DDevice9* Device;
 	IDirect3DTexture9* Texture;
+	IDirect3DCubeTexture9* CubeTexture; 
 	IDirect3DSurface9* RTTSurface;
 	CD3D9Driver* Driver;
 	SDepthSurface* DepthSurface;
Index: source/Irrlicht/CNullDriver.cpp
===================================================================
--- source/Irrlicht/CNullDriver.cpp	(revision 24)
+++ source/Irrlicht/CNullDriver.cpp	(working copy)
@@ -402,7 +402,18 @@
 		os::Printer::log("Loaded texture", file->getFileName());
 		image->drop();
 	}
+	else
+	{
+		if(!hashName && file->getFileName() == "")
+			os::Printer::log("Loading texture from filename failed.");
+		else
+		{
+			// hashName == filename
+			texture = createDeviceDependentTextureFromFile(hashName ? hashName : file->getFileName());
+		}
+	}
 
+
 	return texture;
 }
 
@@ -497,8 +508,13 @@
 	#endif
 }
 
+//! returns a device dependent texture from a loaded file
+//! THIS METHOD HAS TO BE OVERRIDDEN BY DERIVED DRIVERS WITH OWN TEXTURES
+video::ITexture* CNullDriver::createDeviceDependentTextureFromFile(const char* fileName)
+{
+	return 0;
+}
 
-
 //! sets a render target
 bool CNullDriver::setRenderTarget(video::ITexture* texture, bool clearBackBuffer,
 					bool clearZBuffer, SColor color)
Index: source/Irrlicht/CNullDriver.h
===================================================================
--- source/Irrlicht/CNullDriver.h	(revision 24)
+++ source/Irrlicht/CNullDriver.h	(working copy)
@@ -534,6 +534,10 @@
 		//! THIS METHOD HAS TO BE OVERRIDDEN BY DERIVED DRIVERS WITH OWN TEXTURES
 		virtual video::ITexture* createDeviceDependentTexture(IImage* surface, const char* name);
 
+		//! returns a device dependent texture from a file
+		//! THIS METHOD HAS TO BE OVERRIDDEN BY DERIVED DRIVERS WITH OWN TEXTURES
+		virtual video::ITexture* createDeviceDependentTextureFromFile(const char* filename); 
+
 		//! checks triangle count and print warning if wrong
 		bool checkPrimitiveCount(u32 prmcnt) const;
 
Edit: As Irrlicht is in our own repository, the revision numbers are quite useless, but I hope the this patch is applicable nonetheless.
YASS - Yet another Space Shooter
under Devolpment, see http://yass-engine.de
sjb
Posts: 19
Joined: Tue Dec 23, 2008 10:35 pm
Location: Sweden

Post by sjb »

I applied your patch to my project just now MasterD. Works just fine with latest rev. :)
dlangdev
Posts: 1324
Joined: Tue Aug 07, 2007 7:28 pm
Location: Beaverton OR
Contact:

Post by dlangdev »

I will patch mine later.

For those interested to patch theirs, I found a webpage explaining the process on Windows machines.

http://www.linuxtutorialblog.com/post/i ... h-tutorial
Image
Post Reply