b2dJson C++ - image appears as white square

General discussion about the R.U.B.E editor
Post Reply
TheodoreMichels
Posts: 2
Joined: Fri Oct 11, 2013 5:45 pm

b2dJson C++ - image appears as white square

Post by TheodoreMichels »

I just started playing around with the RUBE editor and I'm loving it - so far everything has been really fun and intuitive - and the tutorials are great as well. However, I ran into a problem when I tried to load one of my .json files in the sample loader.

In the source code for the b2dJson C++ sample loader, I changed the "loadrube.h" test to load "C:/TestLevel.json".
The file seems to load fine - all the bodies and fixtures are visible as expected.
However, the .png image I had attached to a dynamic body appears as a white square.

I'm assuming that loaded images need to be placed somewhere specific?
In the .json file it is listed as:
"file" : "../../Pictures/My Pictures/myImage.png",

Any help is much appreciated - and of course let me know if more info would be helpful.

- Theo
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: b2dJson C++ - image appears as white square

Post by iforce2d »

Do you mean the example that uses the Box2D testbed? That only knows how to load .bmp files, because they are simple to load and did not require including the whole of libpng into the example source code.

If you have added support for loading png files yourself and still get this problem, it can happen if you load a texture before the OpenGL context is set up. Some platforms require that you already have a window open and showing as well. It's a good idea to check the value of glGetError regularly throughout your program to see if something has gone wrong.

Presuming you are indeed using the b2dJsonImage_OpenGL class as-is, another thing to keep in mind is that the image file will be searched for relative to the location of the executable that is running.
TheodoreMichels
Posts: 2
Joined: Fri Oct 11, 2013 5:45 pm

Re: b2dJson C++ - image appears as white square

Post by TheodoreMichels »

Yes it's the Box2D Testbed - that all makes perfect sense - I see now that I shouldn't have assumed that it would support several different image types.

So the problem was that I was using a .png image, and I didn't have the appropriate path in the .json file.
So I put "driverhead.bmp" in the same folder as Testbed.vcxproj
Then in the .json file I was loading I edited the line in "image:" to "file" : "driverhead.bmp", and that did the trick.

I knew it had to be something simple -
Thanks so much for your help - and the prompt reply.
Post Reply