It is common for Windows applications to use external files either to load images, play audio or video, or to load or save settings on XML files.
Resources are external files to your application that are embedded in the application's executable file. Resource files are hidden from the user to avoid alterations.
Resources should be stored in a folder named resources
in your project folder. If this folder does not exist, create it.
Resources on Windows must be referenced in a file called Resources.rc
. This file should be placed next to the Visual C++ solution in the vc10
folder. If this file does not exist, you must create it as an empty file. If the resources.rs
file is not included already in your project solution, you must add it by right-clicking on the Resources filter and choosing Add and then ExistingItem. Navigate to the file and select it. As a convention, this file should be kept in the same folder as the project solution.
We will use Visual C++ 2010 to add resources to our applications on Windows. Perform the following steps to do so:
resources.h
file inside the Header Files filter.#pragma once
macro to your file to prevent it from being included more than once in your project and include the CinderResources.h
file.#pragma once #include "cinder/CinderResources.h"
IMAGE
may be used when declaring image resources, VIDEO
for declaring video resources, and so on.For example, to declare the resource of an image file named image.png
, we would type in the following line of code:
#define RES_IMAGE CINDER_RESOURCE(../resources/, image.png, 128, IMAGE)
The first parameter of the CINDER_RESOURCE
macro is the relative path to the folder where the resource file is, in this case the default resources
folder.
The second parameter is the name of the file, and after that comes the unique ID of this resource, and finally its type string.
resources
macro to the resources.rs
file, as follows:#include "..includeResources.h" RES_IMAGE
ci::gl::Texture
we simply include the Texture.h
file in our application's source code:#include "cinder/gl/Texture.h"
gl::Texture mImage;
mImage = gl::Texture( loadImage( loadResource( RES_IMAGE ) );
draw
method:gl::draw( mImage, Vec2f( 20.0f, 20.0f ) );
The resources.rc
file is used by a resource compiler to embed resources into the executable file as binary data.
3.145.178.151