Load An Image From A Relative Path in SFML - c++

Im playing around with SFML and C++ and have one question, when loading a texture, you must specify its directory like so:
sf::Texture myTexture;
if(!(myTexture.loadFromFile("C:\\Folder\\image.png")));
But when distributing my game how will i be sure that the user will download the game onto the same drive, and image.png may be on the E: drive instead of the C: drive. I want to know a way to locate an image file in C++ without having to specif its directory. Here is theoretical code
if(!(myTexture.loadFromFile(#"image.png")));
so now no matter where this image is located my game can find the image. My only concern is that someone might already have a file called image.png on there computer so for this i would give the image files very abstract and unique names, to prevent duplication.

Loading images (and sounds, fonts etc) from a relative path works as well.
If you are concerned about potential filename collisions, distribute your game with a folder containing all your assets. For example yourGame_resources, placed at the same level as your executable. Load by
myTexture.loadFromFile("yourGame_resources/image.png")

Related

Sort files in a QDir by exif data in QT (Cross platform)

I need to sort the contents of a QDir using the exif date (The time the picture was taken).
Now since most cameras name the photos sequentially I can achieve the sorting I want with myQDir.setSorting(QDir::Name), but if the camera resets it's count or I have images from two or more cameras in the same folder, I can't.
QDir::Time does not work either, because it's the time the picture was copied from the camera to the PC.
My program will run on windows and linux so I need a cross platform solution.
I've found easyexif from here but I don't know how to achieve what I want with it.
Any suggestions?

Serialization vs File loading

So now i'm working in ogre, trying to make a game.
But my question is quite simple.
When Ogre loads a file, it then puts it in an so called Entity objects.
I had an idea where i would load all my resources in Ogre, and then serialise them,
and store it all in one file, so i could later just load them as binary code in the
actual game.
My question is if this method would be faster than always loading
the actual files.
I do mention that i work in scenes, so that not ALL of the resources are
loaded in at once ofcourse.
Thanks for your help.
Games often have own resource system. Instead of loading individual files (jpg textures, png images, mp3 files, ogg files, meshes) they pack all of those data into some "smart" file. It is a middle layer.
1. orginal files (models, textures, entities) -> pack into "game_resource_file"
2. load "game_resource_file" in game
Answer to the question: yes it should make loading faster.
But there are some flaws: as you see you need at least two steps to have a resource in your game. When you change one texture (out of 100) it can take long time before you can see it on the screen. You have to take that texture, rebuild your resource file and then load in the game. Without that you simply load a changed texture in the game directly.
This resource pipeline problem is very important and can save (or add) large amount of development time.

Can't open any files in Code::Blocks application during runtime

I am using Code::Blocks to make an OpenGL program in C++. The program compiles and runs, but the texture is never displayed. I just get an empty grey rectangle against a white background, when there should have been a picture in the grey rectangle.
I first noticed problems when trying to load the images for textures using the Simple OpenGL Image Library (SOIL). I did some digging around in the code of SOIL and found that the program was not opening any files at all. I tried changing image format, creating some random text files to test, and more, but it would not open any files of any type.
I think I may have the files in the wrong directory, but if so, where are they supposed to go? Right now, I have them saved in the same directory as the code.
Somewhere, you are giving paths to the files. These should be relative to the location of the executable. So examples could be this:
someFunction("file.jpg");
Here, the file.jpg should be somewhere like: <project_dir>/bin/Debug/
someFunction("../../file.jpg");
Now the correct location will be: <project_dir>/

Loading meshes from .obj (or any other) File into DirectX9/C++ project

Currently I have a 3D Cube that I drew by writing coordinates, that can rotate and move on a black screen.
Now I have a Model that I created in "3Ds Max"(It's a little backyard with high stonewalls, so I'm trying to use it as my world object.) and I want to load this model into my DirectX9/C++ project.
As far as I see in DirectX SDK examples this code is for loading .X model (which needs a plugin for "3Ds Max" to export that kind of extension. I'm not sure of this.)
Code for loading .X files into DX9/C++:
D3DXLoadMeshFromX( "Tiger.x", D3DXMESH_SYSTEMMEM,
g_pd3dDevice, NULL, &pD3DXMtrlBuffer, NULL,
&g_dwNumMaterials, &g_pMesh )
Is there a function like "D3DXLoadMeshFromOBJ(.....)" to load an Object? How do I load and render .OBJ files? 8(
Another question of mine is what is the difference between an .X file and an .OBJ file and which of them should I use?
AFAIK, DirectX does not support wavefront object files out of the box. You will need an external mesh loader for that purpose.
I can remember, that in the DX 10 SDK is a sample of how to load an .obj file, I think the sample is called MeshFromOBJ10. I don't know if it is of any use in DirectX 9.
As far as I know, the standard .x just supports basic meshes with no enhancements such as animation. If you want to try out graphical programming it is not bad, but if you are aiming for higher concepts you can later switch. I guess you can look up the advantages of the .obj files here.
It is always a good idea to create an abstraction for the input data you are using. For example, you could create a class AbstractMesh and an implementation XMesh deriving from it. Later on, you can than add other implementations like OBJMesh or anything similar.
I hope I could help you a bit :) Happy Coding!
Animation is full supported in x file format, and furthermore, it support fx files when you want to use shaders. A exporter plugin and samples you can download from this page:
http://www.cgdev.net/download.php

want to load an image, process it and save it back in file?

I am creating a photo editor app in webos using its hybrid app. I am new to c++.
I don't want to display image on the screen using C++, because on the front end I am using javascript as ui.because javascript UI is better thn PDK... But on the backend I have to use c++ just to process it and save image to the file. I can't save it using javascript because webOS doesn't have support for canvas.toDataURL() method.
So I have to pick an image file from a relative path in the local directory, get its rgb values, process on the rgb values and then saving image back to the directory. Saving as new and replacing the previous.
Ok, now I want assistance from u developers. Also if this is all possibe using the SDL library ?? Also can I crop image in c+|+ as well given x,y coordinates of all of its edges to be cropped from?
I don't know the SDL library well (I suppose it can load and save images) but for loading and saving images you can use the OpenIL/DevIL library, it is quite simple and supports many formats. You could also take a look at OpenCV, but that could be a bit heavy-weight for your purpose. To your second question, You can do everything with the image when it's loaded, just program it. With the right libraries and programmer, C++ can do nearly everything. Sorry for this stupid sentence, but you asked if you can do that in C++ and the answer is nearly always Yes.