I have written a screen saver using visual c++ 6 and opengl. i am using 2 .tga textures and i am wondering if anyone knows of a way to embed the textures within the .scr file (possibly as a resource?) to enable it to function as a standalone file.
I am quite aware that this question may be more a visual c++ or straight forward c programming question rather than one relating to opengl but i have searched msdn till i am blue in the face and wondered if anyone had done it before - or knew of a way to do so.
thanks in advance.
I did this with resources, you just have to add your files as resources. For non Bitmaps you can define your own resource type. (I did not do this with visual C, but it must be very simple to add a binary resource there just by hitting the right Button). I added the resource in the .rc File like this :
NAME_OF_RESOURCE YOUR_RESOURCE_TYPE “image.tga”
After that you can load the resource in your Programm. For this you have to use “FindResource” to get a handle to resource, then Load it with “LoadResource”. After that you lock the resource with “LockResource” which gives you an pointer to the memory where your resource, in your case a tga image is.
You can now easily work with this data.
For details just look up the functions in the MSDN.
There may be an MFC way, but i don’t use it so i don’t know it.
I have added the files as resources successfully under the custom resource type “TGA”. I’ve looked up the resource loading functions on MSDN and found an obscure example. However I am having trouble getting the handle to the resource with FindResource. Please could you give sample code if possible as I would greatly appreciate the help. I could send you a copy of the screensaver + source in return (it’s quite impressive).
thanks for the advice.
search in MSDN
Find the handle to the resource.
Lock the resource for using it.
Gets the pointer to the resource data.
As you get the pointer to the resource data, u will handle it as a file loaded in memory.
If you don’t wanna play with that functions try to look at the LoadBitmap too, it directly loads a bitmap from resources.