Textures
From Leadwerks Developer Wiki
Contents |
Introduction
Leadwerks Engine uses the .dds file format for textures, and can load uncompressed, DXTC1, DXTC3 and DXTC5 formats. Mipmaps and cubemaps are also supported.
The materials system is designed to pack as much information into as few textures as possible. Consequently, you will not have separate textures for alpha masks or specular levels. Instead, the engine usually stores information in the alpha channel of the base texture and bumpmap.
Several texture tools can be downloaded in the Other Tools section.
Cubemaps
A cubemap is a texture with 6 images corresponding to the faces of a cube surrounding the viewer. These are used to render skies and reflections. The DDS texture format can store all six faces of a cubemap in one file.
Creating a Cubemap with NVidia DDS Utilities
Download NVidia DDS Utilities and place nvdxt.exe in the same directory as your 6 cube textures. All 6 textures must be the same dimensions in pixels. Create a new text file, open it in Windows Notepad, and add this text:
day_rt.png
day_lf.png
day_up.png
day_dn.png
day_ft.png
day_bk.png
Save the file and rename it "cubefaces.txt".
Now Create a second text file and open it in Notepad. Add this text:
nvdxt.exe -cubeMap -list "cubefaces.txt" -output "day.dds"
pause
Save the file and rename it "cubegen.bat". Double-click on this file and a console window will appear. A new DDS texture will be created containing your 6 textures.
Tutorials
Texture Slots
The first 10 texture slots are available to use. Texture slots 10-15 should not be used. Texture slots 16-32 may not be supported on all hardware.
0. User
1. User
2. User
3. User
4. User
5. User
6. User
7. User
8. User
9. User
10. Instance matrix texture
11. Reserved
12. Reserved
13. Terrain color texture
14. Terrain normal map
15. Terrain heightmap
Commands
Texture Commands
CreateTexture
- C: TTexture CreateTexture( int width, int height, int format=TEXTURE_RGBA )
- Creates a new texture. The following formats can be created:
- TEXTURE_ALPHA,TEXTURE_ALPHA8 - 8-bit Alpha
- TEXTURE_LUMINANCE,TEXTURE_LUMINANCE8 - 8-bit Luminance
- TEXTURE_RGB, TEXTURE_RGB8 - 24-bit RGB
- TEXTURE_RGBA, TEXTURE_RGBA8 - 32-bit RGBA
- TEXTURE_DEPTH, TEXTURE_DEPTH24 - Depth texture
- TEXTURE_RGBA16 - 64-bit RGBA (use for high-quality normal buffer)
- TEXTURE_FLOAT - Float texture (16-32 bit depending on hardware) (can be used for displacement mapping)
- TEXTURE_RGBA32 - 128-bit RGBA. It is unlikely this format is needed for any purpose
- TEXTURE_RG11B10 - 32-bit RGBA float texture. This allows you to use high-resolution RGB images, though it may not be supported on all hardware
- Only the following formats can be bound to a buffer and rendered to on all hardware:
- TEXTURE_RGB, TEXTURE_RGB8
- TEXTURE_RGBA, TEXTURE_RGBA8
- TEXTURE_DEPTH, TEXTURE_DEPTH24
- TEXTURE_RGBA16
- TEXTURE_RGBA32
- TEXTURE_FLOAT
- For vertex texture lookups, TEXTURE_FLOAT or TEXTURE_RGBA32 should be used. In addition, NVidia Shader Model 4 graphics cards may use the TEXTURE_RGBA16 format.
- [Examples]
LoadTexture
- C: TTexture LoadTexture( str filepath )
- C++:
- Texture::Texture( const_str filepath )
- void Texture::Load( str filepath )
- BlitzMax: LoadTexture:TTexture( filepath:String )
- Pascal: function LoadTexture ( filepath:PAnsiChar ): THandle;
- Loads a texture from a texture file.
- This command increments the texture reference count. To allow memory management to delete the resource, the reference count must be decremented by calling FreeTexture(texture). Textures can be loaded from .dds and .raw (16-bit) formats. If a texture with the specified filename has already been loaded, it'll return a reference to that to avoid loading assets twice.
- [Examples]
TextureFilter
- C: void TextureFilter( TTexture texture, int filter )
- C++: void Texture::SetFilter( const TextureFilters& filter ) Where filter is one of Pixel, Smooth or MipMap
- BlitzMax: TextureFilter( texture:TTexture, filter:Int )
- Pascal: procedure TextureFilter ( texture:THandle; filter:Integer );
- Sets the texture filter for the specified texture. Texture filter modes are below.
- TEXFILTER_PIXEL
- TEXFILTER_SMOOTH
- TEXFILTER_MIPMAP
- [Examples]
ClampTexture
- C: void ClampTexture(TTexture texture, int x=1, int y=1, int z=1)
- Sets clamping for the axis of a texture (this does the same as the material setting "clampn=x,y,z" but on a per texture, in-code base). See Materials->Syntax->clampn
- [Examples]
TextureWidth
- C: int TextureWidth( TTexture texture )
- C++: int Texture::GetWidth( void ) const
- BlitzMax: TextureWidth:Int( texture:TTexture )
- Pascal: function TextureWidth ( texture:THandle ): Integer;
- Returns the width of the specified texture.
- [Examples]
TextureHeight
- C: int TextureHeight( TTexture texture )
- C++: int Texture::GetHeight( void ) const
- BlitzMax: TextureHeight:Int( texture:TTexture )
- Pascal: function TextureHeight ( texture:THandle ): Integer;
- Returns the height of the specified texture.
- [Examples]
TextureName
- C: str TextureName( TTexture texture )
- C++: std::string Texture::GetName( void ) const
- BlitzMax: TextureName:Byte Ptr( texture:TTexture )
- Pascal: function TextureName ( texture:THandle ): PAnsiChar;
- Returns the name of the specified texture.
- [Examples]
FreeTexture
- C: void FreeTexture( TTexture texture )
- C++: void Texture::Free( void ) Note: Also called from destructor
- BlitzMax: n/a
- Pascal: procedure FreeTexture ( texture:THandle );
- Releases the handle of a texture from memory. The texture will be deleted when it is no longer in use.
- [Examples]
Rendering Commands
BindTexture
- C: void BindTexture( TTexture texture, int texunit )
- C++: void Texture::Bind( int texunit )
- BlitzMax: BindTexture( texture:TTexture, texunit:Int )
- Pascal: procedure BindTexture ( texture:THandle; texunit:Integer=0 );
- Binds the specified texture to the specified texunit of the current shader (i.e., texunit 0 is texture0 in a shader).
- [Examples]
Global Settings
TFilter
- C: void TFilter( int mode=1 )
- C++: void Engine::SetTFilter( int value = 1 )
- BlitzMax: TFilter( mode:Int )
- Pascal: procedure TFilter ( mode:Integer=1 );
- Sets trilinear filtering mode. 1 enables trilinear filtering and 0 disables it.
- [Examples]
AFilter
- C: void AFilter( int mode=4 )
- C++: void Engine::SetAFilter( int value = 4 )
- BlitzMax: AFilter( mode:Int )
- Pascal: procedure AFilter ( mode:Integer=4 );
- Sets the anisotropic filter. The mode can be from 1 to the value returned by MaxAFilter().
- [Examples]
MaxAFilter
- C: int MaxAFilter( void )
- C++: int Engine::GetMaxAFilter( void )
- BlitzMax: MaxAFilter:Int()
- Pascal: function MaxAFilter: Integer;
- Returns the maximum supported anisotropic filter on the user's machine.
- [Examples]
MaxTextureUnits
- C: int MaxTextureUnits( void )
- Returns the maximum supported texture units on the user's machine.
- [Examples]
SetTextureQuality
- C: void SetTextureQuality( int quality )
- C++: void Engine::SetTextureQuality( int quality )
- BlitzMax: SetTextureQuality( quality:Int )
- Sets the quality of loaded textures. If quality is one, textures will be loaded at full resolution. If quality is two, textures will be loaded at half resolution. If quality is three, textures will be loaded at one-fourth resolution. .dds files must contain mipmaps for this setting to have an effect.
- [Examples]
