DevNote Nov-26-2009

Clouds and lights got back to normal


Since some time around 1.9.1 release, I haven't seen 2D clouds. 3D clouds were there but the edges are too dark and these look much more like smokes of anti-air cannons...

And things went worse. Since some time in the last month, I haven't seen 3D clouds... 

png-alpha-grayscale-noclouds.png SIZE:800x600(?KB)
No 2D/3D clouds comes up (with FG/SG/OSG as of 2009/11/24)

What's going on here? I've asked some FG developers (Linux users) but they said they could see 2D/3D clouds properly. 

I thought that 2D clouds didn't show up because of my graphic chip issue. However, I found the following error messages in fgfs log:

<Error>: CGBitmapContextCreate: unsupported parameter combination: 
           8 integer bits/component; 16 bits/pixel; 
           1-component colorspace; kCGImageAlphaLast; 512 bytes/row.
<Error>: CGContextDrawImage: invalid context

I've seen these since some time ago... Maybe some time around 2D clouds went disappear. "This might be it," I thought, so I googled the error message and found that this is caused since you're designating a wrong combination of colorspace, pixel format, bpp, etc for an image. The function CGLBitmapContextCreate is called only from ReaderWriterImageIO.cpp (imageio plugin for Mac OS X), so I added a debug print for dumping the filenames that generate the errors. 

All the files with errors are cloud texture png images like cl_cumulus.png, which are 16-bit grayscale images with alpha channel. I thought "If this is the case, I can fix it." I made a simple workaround patch for creating a 32bit RGBA context instead of 8-bit grayscale for such grayscale images, hoping that CGLBitmapContextCreate automatially converts the pixel format from Grayscale-Alpha to RGBA. And it worked! Both 2D and 3D clouds came up and the errors were gone.

png-alpha-grayscale-imageio.png SIZE:800x600(?KB)
3D clouds came up, but with darker edges...

Okay, one problem solved. Another problem is the "dark edges." I have a similar problem that transparency in png files aren't drawn properly, so it might has something to do with the dark edged clouds (c172p's tail light has wide black edge. You can see the c172p's tail light around the rudder in the image above is rather black than red).

To make sure this is a png problem, I converted one 16-bit grayscale cloud texture (cl_cumulus.png) into rgba (SGI' RGBA file) and then edited cloudlayers.xml to use the rgba file instead of png. Running FG with the rgba texture gave me a result that I expected. The cloud edges went much brighter. Therefore, I edited osgDB/Registry.cpp for not letting imageio handle png images. I also built for handling png files instead of imageio (of course I reverted cloudlayers.xml). I launched FG again with, and the result was perfect. I finally got brigher clouds and the red tail light without weird black edge.

png-alpha-grayscale-osgdb_png.png SIZE:800x600(?KB)
3D clouds and the tail light with my patch.  


You can get the patch that I made for this experiment from: here.

To build (or .dylib), you need to modify CMakefile and/or OpenSceneGraph.xcodeproj file yourself. You also need /usr/X11/lib/libpng.dylib and /usr/X11/include/libpng/png.h to build osgdb_png plugin.

Further note on Dec-03-2009

I made further more investigations (DevNote Dec-02-2009, and DevNote Dec-03-2009) on this issue, and I made the workaround patch for

You can get the patch for OpenSceneGraph/src/osgPlugins/imageio/ReaderWriterImageio.cpp.

FYI, This patch is applied to osg/svn on Dec-05-2009. If you use osg earlier than 2.9.6 (or 2.9.7?) and have this issue, you need this patch.