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

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>/

Related

loading textured obj with PCL c++

I am trying to load a textured .obj file using the predefined PCL (Point Cloud Library) functions like so:
pcl::TextureMesh texture_mesh;
int loaded = pcl::io::loadOBJFile(<path to obj>,texture_mesh);
boost::shared_ptr<pcl::visualization::PCLVisualizer> result_view(new pcl::visualization::PCLVisualizer("Viewer"));
result_view->addTextureMesh(texture_mesh, "texture mesh", 0);
while (!result_view->wasStopped())
{
//---{ update the viewer }
result_view->spinOnce(100);
boost::this_thread::sleep(boost::posix_time::microseconds(100000));
}
However, the texture is not loaded correctly and the model remains colourless. I have tried to save the "texture_mesh" to a new .obj to see the result but it appears the texture coords are being jumbled up.
My questions are:
1) Are the files in the correct format?
2) Is the obj loading and veiwing correct?
3) Has anyone had success loading textured .obj files with PCL?
To demonstrate the issue, I have initialized a test repo here loadOBJ
paths supplied in src are relative so set cmake source=loadOBJ, build=loadOBJ/build.
Due to the relative path I had to edit the output of saving the obj with pcl, this is noted in the READMEs.
Due to issue with not knowing enough about git, I had to manually upload the .obj files haha
This is only an issue on windows machines, it has been tested on unix and runs fine.

64bit OpenCV with Visual Studio 2013 - bizarre behaviour for cv::namedWindow()

Currently trying to display a stream from an uEye camera using OpenCV. For this purpose I have Visual Studio 2013 and OpenCV 2.4.9 (64bit) at my disposal. Since things are not yet close to a release I'm using the debug libraries that are shipped with OpenCV (compiled with Visual Studio 2012).
I was trying to memcpy the image data that is returned by the camera to a cv::Mat object. After getting some weird error about a NULL pointer (string name of cvNamedWindow) I decide to check if I can actually run a very basic piece of code - read a PNG image and show it in a window. Well, it's not working... My mistake is probably still in the memcpy that I use but if you read below you will see that I have also tested a case where no camera is involved.
No matter if I give the absolute path of my image or simply point at the file where the EXE is I get an assertion failure from cv::imshow that either the height and/or width are not > 0. One other thing struck me here - the window name was all messed up - weird symbols, blank spaces etc. Nothing to do with what I have assigned as a name: "camOutput"
Further I decided to test things by manually creating a matrix of type CV_8U3 and filling it with black pixels. OpenCV showed the image yet the name of the window was again messed up. This time I was able to read the following, which seems to be some part of a command:
n in DOS mode.$
O_o I have never ever seen such weird behaviour especially when it comes to imshow, imread or namedWindow. Futher I can also not explain why imread returns an empty matrix no matter what I feed it. Tried PNG, JPEG and BMP - always the same crash.
EDIT: I have created an empty C++ project and transferred all my settings from the previous one. Now it's working. Even the memcpy for my uEye camera is fine and I can display the output in an OpenCV window. I have no idea what the problem was with my previous project. Will have to analyze further since the issue might reoccur. I will however leave this questioned opened because of that.

Load An Image From A Relative Path in SFML

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")

SOIL OpenGL Library crashes inside classes

I'm working on a simple 3D model loader using OpenGL and I wanted to add texture support. However, not wanting to needlessly rewrite an image library, I downloaded SOIL (Simple OpenGL Image Library) that I learned about in the NeHe tutorial on texture mapping. It has a few very useful functions that take care of loading images of many times and passing them to OpenGL.
The problem is this: In the NeHe tutorial code, the SOIL function
SOIL_load_OGL_texture(char *, param,param,param)
exactly as promised and the polygons are mapped with the correct picture. However, I've made a class that loads OBJ and MTL files (3D model files). When I try to use the SOIL function to load a texture inside this class, my program crashes.
I am using GNU C++ with Code::Blocks (I also tried this code in Dev-C++)
I receive no errors or warnings from the compiler with -g -Wall.
I have linked and included everything properly in my project (if I copy/paste the NeHe code, it runs properly).
The SOIL command does not work inside any class (I tried making another class that only executed the SOIL function and I got the same problem).
The file paths passed to the function are all correct. I have tried relative and absolute, with all formats of forward and back slashes. I copied and pasted absolute paths that worked in the NeHe code to my code and it does not work.
The rest of my code works fine - I can get my shape rendered with its ambient/diffuse/etc. colors and other settings applied properly.
Sounds almost like you don't have a valid OpenGL context at the time when you're calling that function.
Are you certain that SOIL is called only after your opengl context is initialized? (e.g. no static construction of objects that are constructed at program initialization). A quick way to check this is to put a breakpoint on your opengl initialization and see if you hit the BP or if your program crashes first.
Also, make sure that SOIL call is on the same thread as your opengl context.

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.