-
Notifications
You must be signed in to change notification settings - Fork 165
Loading textures from image files
Please see our wiki page about compressed textures for more info.
If you wish to load images from formats such as JPEG or PNG into ANGLE, then you have several options:
- Cross-platform solutions such as libJPEG or libPNG
- Microsoft technologies such as Windows Imaging Component (WIC)
Libraries such as libJPEG and libPNG have been successfully used in many Windows Store applications and frameworks, and provide a cross-platform solution to image loading. However, you may wish to consider using WIC in your application, which can have many benefits (for example: better performance, reduced app download size).
WIC is a powerful image decoding library distributed with Windows. It supports many standard image formats (for example: TIFF, JPEG, PNG, GIF, BMP), and is used by most in-box and many out-of-box components to decode images on Microsoft platforms.
The DirectX Tool Kit (DirectXTK) includes WICTextureLoader, which is an easy-to-use helper for developers wanting to load images into DirectX textures using WIC. We have created a version of this helper for Windows Store apps to use with ANGLE.
A sample demonstrating how to use WICTextureLoader can be found in our GitHub samples directory.
To use WICTextureLoader in your own project, simply copy WICTextureLoader.h and WICTextureLoader.cpp from the samples directory and use it like this:
// Load the texture
glGenTextures(1, &mTexture);
glBindTexture(GL_TEXTURE_2D, mTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
HRESULT hr = WICTexImage2DFromFile(GL_TEXTURE_2D, 0, L"sample.ext");
if (FAILED(hr))
{
// Error
}
Due to coordinate system differences, the 'WICTexImage2DFromFile' helper usually has to vertically flip the contents of image files at runtime before passing their data to ANGLE. This is an unnecessary overhead which you can avoid by manually flipping the contents of your image files and setting WICTexImage2DFromFile's optional 'verticalFlip' parameter to false.