ofImage - image doesn't appear - probably dumb mistake

Hi,

I’m getting back into openFrameworks after attempts to make progress (re my game project) with cocos2d failed disastrously, mostly due to lack of motivation.

I’m stumbling almost at the first hurdle - what I have in mind is likely to use a lot of sprites, yet I can’t get a simple image to display for basic learning purposes.

Relevant extracts from my current .cpp (the .h is valid):

  
void appName::setup()  
{  
  // ...  
  bg = new ofImage();  
  bg.loadImage("media/bg.png");  
}  
  
void appName::draw()  
{  
  bg.draw(0,0);  
}  

I checked the documentation and loadImage() says it looks for media in a data/ folder, but as one isn’t in my template I’m not sure where it’s supposed to be. I’ve tried putting it in both the project / directory and the src/ dir but media/bg.png isn’t displaying.

Developing in Xcode on Snow Leopard by the way.

Thanks

1 Like

Hey,

Drop the data folder inside the bin folder, also check the imageLoaderExample project it will give you a hint on how to structure your files, and how to load the resources

Hope that helps
rS

Hey, thanks for replying already. I checked out the imageLoader example (should have done that in the first place) but I’m still having trouble.

I adapted my script to give feedback when loading the image:

  
if( ! bg.loadImage("media/bg.png")) printf("Media loading failed");  

The debug application prints “Media loading failed” when I build and run it. Read permissions are correct, as far as I can tell, on the PNG image file found at /data/media/bg.png relative to the bin directory. I’m not sure what I’m doing wrong as everything seems to be set up exactly the same as in the example.

maybe try posting the png? there is a possibility that it has some strange properties not recognized by free image (the library used by OF for loading images).

PNG-image

It’s not the most exciting image I know, it’s just for demo purposes so I can see it scrolling vertically (when I get to that stage anyway…)

OF won’t load images that aren’t exciting.

:wink:

but really, i just opened this in photoshop and the image has no alpha component. perhaps you forgot to check ‘use transparency’ when saving the image?

It’s not meant to be transparent, does freeImage require an alpha layer for PNGs?

oh wow, sorry – i was confusing this post with another one.

try getting rid of this line:

  
  
bg = new ofImage();  
  

if you were using java/processing before, you’re probably used to saying “new” whenever you make an object. in c++, an object is automatically created for you when you declare it.

so if you say this in your header:

  
  
ofImage bg;  
  

that’s (something like) the equivalent of saying this in processing:

  
  
PImage bg = new PImage();  
  

with OF you can imagine every “new” being replaced by a “setup” of some sort. with ofImage, the setup is loadImage().

maybe that’s more confusing than helpful. so the key thing is just: don’t say “new” until you start working with pointers, and you’ll be fine :slight_smile:

I actually already cottoned onto that. Thanks for pointing it out anyway.

.h

  
class appName : public ofBaseApp  
{  
  //...  
  private:  
    ofImage bg;  
};  
  

.cpp

  
void appName::setup()  
{  
  //...  
  if( ! bg.loadImage("media/bg.png")) printf("Media loading failed");  
}  

i just made the smallest modifications to the emptyExample and it seems to work, i’m not sure what’s different?

try the attached project and let me know if it works for you.

bg-loader.zip

For some reason that won’t compile at my end - throws a bunch of errors.

I trashed my original project and rewrote the basic ofImage lines by hand (project based on a tidied-up version of emptyExample), with the PNG placed in the same location as before. I’ve attached the final project to this one.

[attachment=0:20wo00lr]bs_demo_1a.zip[/attachment:20wo00lr]

On my system this compiles with 9 warnings, and the image does not load:

  
ld: warning: __gnu_cxx::new_allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::allocate(unsigned long, void const*)has different visibility (hidden) in /Users/Anny/openFrameworks/apps/anny/bs_demo_1a/../../../libs/FreeImage/lib/osx/freeimage.a(IPTC.o-i386) and (default) in /Users/Anny/openFrameworks/libs/openFrameworksCompiled/lib/osx/openFrameworksDebug.a(ofUtils.o)  
  
  
ld: warning: std::_Vector_base<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::~_Vector_base()has different visibility (hidden) in /Users/Anny/openFrameworks/apps/anny/bs_demo_1a/../../../libs/FreeImage/lib/osx/freeimage.a(IPTC.o-i386) and (default) in /Users/Anny/openFrameworks/libs/openFrameworksCompiled/lib/osx/openFrameworksDebug.a(ofUtils.o)  
  
  
ld: warning: std::basic_string<char, std::char_traits<char>, std::allocator<char> >* std::__copy_backward<false, std::random_access_iterator_tag>::copy_b<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*>(std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)has different visibility (hidden) in /Users/Anny/openFrameworks/apps/anny/bs_demo_1a/../../../libs/FreeImage/lib/osx/freeimage.a(IPTC.o-i386) and (default) in /Users/Anny/openFrameworks/libs/openFrameworksCompiled/lib/osx/openFrameworksDebug.a(ofUtils.o)  
  
  
ld: warning: std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::~vector()has different visibility (hidden) in /Users/Anny/openFrameworks/apps/anny/bs_demo_1a/../../../libs/FreeImage/lib/osx/freeimage.a(IPTC.o-i386) and (default) in /Users/Anny/openFrameworks/libs/openFrameworksCompiled/lib/osx/openFrameworksDebug.a(ofUtils.o)  
  
  
ld: warning: __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > std::__uninitialized_copy_aux<__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > >(__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, __false_type)has different visibility (hidden) in /Users/Anny/openFrameworks/apps/anny/bs_demo_1a/../../../libs/FreeImage/lib/osx/freeimage.a(IPTC.o-i386) and (default) in /Users/Anny/openFrameworks/libs/openFrameworksCompiled/lib/osx/openFrameworksDebug.a(ofUtils.o)  
  
  
ld: warning: std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::_M_insert_aux(__gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)has different visibility (hidden) in /Users/Anny/openFrameworks/apps/anny/bs_demo_1a/../../../libs/FreeImage/lib/osx/freeimage.a(IPTC.o-i386) and (default) in /Users/Anny/openFrameworks/libs/openFrameworksCompiled/lib/osx/openFrameworksDebug.a(ofUtils.o)  
  
  
ld: warning: std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::push_back(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)has different visibility (hidden) in /Users/Anny/openFrameworks/apps/anny/bs_demo_1a/../../../libs/FreeImage/lib/osx/freeimage.a(IPTC.o-i386) and (default) in /Users/Anny/openFrameworks/libs/openFrameworksCompiled/lib/osx/openFrameworksDebug.a(ofUtils.o)  
  
  
ld: warning: std::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const*)has different visibility (hidden) in /Users/Anny/openFrameworks/apps/anny/bs_demo_1a/../../../libs/FreeImage/lib/osx/freeimage.a(PluginEXR.o-i386) and (default) in /Users/Anny/openFrameworks/libs/openFrameworksCompiled/lib/osx/openFrameworksDebug.a(ofUtils.o)  
  
  
ld: warning: std::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)has different visibility (hidden) in /Users/Anny/openFrameworks/apps/anny/bs_demo_1a/../../../libs/FreeImage/lib/osx/freeimage.a(PluginEXR.o-i386) and (default) in /Users/Anny/openFrameworks/libs/openFrameworksCompiled/lib/osx/openFrameworksDebug.a(ofUtils.o)  

Beginning to think something is off with my oF setup… latest version btw.

bs_demo_1a.zip

i think those warnings are ‘normal’ (which frustrates me, but i always see them and have never been able to identify their origin).

if the example i just sent doesn’t compile, i’m really not sure what’s wrong.

does your emptyExample compile?

what i recommend is starting with someone that does compile (like emptyExample) then adding in a couple lines that load the bg image correctly. make sure that works. then rename the class to appName instead of testApp if that’s important to you. then do any more tidying up. all along the way, keep recompiling to make sure it always works.

i’m guessing it’s either your OF install (in which case the apps shouldn’t compile) or you’re running a weird version of xcode. i’m fairly new to osx so i can’t provide very much more help :frowning:

Yes, emptyExample compiles just fine without warnings (once I remove openFrameworks-Info.plist from the build phase). My tweaked project template is the same, it’s just a tidied up version of the exact same code to suit my taste (putting function handlers onto new lines, etc). It’s when I try to add ofImage based functionality that I get the problems - nothing happens when I use ofImage. Your example didn’t compile for me either, as I said before — I just tried again and it came up with these errors:

  
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:0 /Developer/SDKs/MacOSX10.4u.sdk/usr/include/stdarg.h:4:25: error: stdarg.h: No such file or directory  
  
  
/Developer/SDKs/MacOSX10.4u.sdk/usr/include/float.h:8:0 /Developer/SDKs/MacOSX10.4u.sdk/usr/include/float.h:8:24: error: float.h: No such file or directory  
  
  
/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/MachineExceptions.h:29:0 /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/MachineExceptions.h:29:23: error: xmmintrin.h: No such file or directory  
  
  
/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/MachineExceptions.h:254:0 /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/MachineExceptions.h:254: error: '__m128' does not name a type  
  
  
/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/MachineExceptions.h:255:0 /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/MachineExceptions.h:255: error: '__m128i' does not name a type  
  
  
/Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/MachineExceptions.h:256:0 /Developer/SDKs/MacOSX10.4u.sdk/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/Headers/MachineExceptions.h:256: error: '__m128d' does not name a type  

I’m beginning to remember why I changed over from openFrameworks to cocos2d in the first place…

aha! this explains everything.

don’t do that.

i know it’s really, really annoying to have warnings (at least for me) but this is actually supposed to happen.

including the .plist in the build phase is a hack so that the data folder can be used without having to manually add every item to your project. so it’s actually not ofImage causing problems, but loading things from data/. there are some techniques for circumventing this that might be integrated into the next release of OF…

regarding the 10.4 errors, this can be easily fixed by going into the project settings and changing the “Base SDK” to “Current Mac OS” and “Architecture” to “Native Architecture of Build Machine”. you should also do this in the target application info. i did this for you in the testApp i sent above.

re cocos2d: neat, i haven’t seen this before. lots of cheesy effects, but the live coding environment is great for making development intuitive.

Ooooooooooooooh

:3

In my frustration I actually went and installed Unity, but I didn’t really want to get into that whole integrated environment… it’s not my bag.

I used cocos2diphone before when I was targeting the iPhone for this game I’m working on, but I decided eventually that I need the physicality of a USB drum set otherwise it doesn’t really make sense.

Thanks for pointing me straight. It’s annoying having warnings - but Xcode is pretty customisable that way, I’m sure I can tweak the project to ignore that warning.

Thanks dude, I can hardly believe it was such a simple fix.