image not loading and displaying

Hi everybody. First post here. Coming from Processing and trying to regain my old C++ chops. I’m trying to load and display an image to screen but I’m just getting a white rectangle instead of the actual image. Is there a fill value I have to set or something before I draw the image?

In my testApp header I’ve got:

ofImage img;  

In my testApp setup() function I’ve got:

img.loadImage("Tree.jpg"); //and my jpg is in my project's root folder  

Then in my draw() method I’ve got:

img.draw(width/2, height/2, 100, 100); //I have width and height predefined  

Did I miss something? I tried going off of the imageLoaderExample that comes with the library, but that example doesn’t work either. I just get a blank white screen. Any help would be appreciated.

hmm… the code looks fine… sounds like your image file isn’t in the right place… it should be in the data directory, which should be in the same directory as your binary/executable…


bin/ (or myApp.exe)

Try making your draw statement just img.draw(0, 0); to see if it’s drawing the image at all.

I’ve tried all of that. Just to make sure I didn’t do something screwy I even tried doing it with emptyExample. All I did was stick the jpg in the bin/data/ folder, then just entered in the three lines of code mentioned above (with the added path to loadImage()). Nothing. Blank screen. I don’t get any compile errors, it just doesn’t display. That’s why I was sure I was missing something. Everything is behaving, but it’s almost as if I forgot to switch something on, you know? Any other ideas? :expressionless:

Have you tried a different image file? Maybe there is something bugged with that particular jpg?

You should be able to do something simple like…

ofImage myImage;  
myImage.draw(0, 0);  

and have it draw to the screen in the top-left corner.

Doesn’t look like you’re missing any steps…

I finally got it working on one of my projects, but it won’t work on any others! Even if I copy and paste the exact same code into another emptyExample, and put the jpg in the same exact place, I get a bunch of weird errors. I cannot figure this out. Is there a special way I should be copying the emptyExample to use as a new project? I’m on a Vista machine with MSVC 2008. I’ve just been copying the entire contents of emptyExample and pasting it into a new file folder within the apps/examples/ folder. Then I load up the solution and save as something else. This doesn’t seem to work.

Now I remember why I love Processing/Java so much. :roll:

OK I think I’ve found a solution that’s giving me consistent results. When I copy emptyExample to use for a new project, I’ve found I have to go into the project properties and include my new project’s folder path in the “Additional Include Directories” field of the General C/C++ properties. I’m not sure why I have to do that, but it works.

If anyone cares to shed some light on the glorious joy that is Visual Studio, by all means, enlighten. All the little settings can be really annoying, especially coming from the drag-and-drop ease of Processing. Heck, even Eclipse is more fun than this (don’t we have a build coming for that soon?).

Either way, I’m loving openFrameworks and can’t wait to get some real work going!

Thanks for your solution, Nochin, I was having the same problem a couple nights ago with MS Visual Studio 2008, with images not loading but no errors.

That’s what I get for crawling out of my Mac cave :¬)