Monday, December 12, 2011

QT_FORWARD_DECLARE_CLASS should be used for forward declaration of Qt classes

Using QT_FORWARD_DECLARE_CLASS, the forward declaration will still work if someone configures Qt with -qtnamespace:

For example, if someone configures a MyNamespace, QT_FORWARD_DECLARE_CLASS(QWidget) becomes:

namespace MyNamespace { class QWidget; }
using ::MyNamespace::QWidget;

whereas normal "class QWidget" forward declaration will cause a conflict since the class is declared outside the namespace.

Saturday, August 20, 2011

Building OpenSceneGraph for iOS [In Progress]

After spending a few hours on trying to build OpenSceneGraph 3.0.1 on Xcode 4.2 for iOS 4.3/5.0, I finally gave up ...

The README.txt in the official OSG package describes how to generate an Xcode project using CMake. I tried to use CMake 2.8.5. Following the cmake command line described in README.txt, I got an error about not able to build a test project. Then I tried CMake GUI, but it still didn't work.

I searched the web and found a modified version at git:// This time, CMake GUI generated an Xcode project. However, when I tried to open and build this project in XCode 4.2, I got the following error:

OpenSceneGraph-2.9.10/src/OpenThreads/pthreads/PThread.c++:1: error: -mmacosx-version-min not allowed with -miphoneos-version-min


It seems that CMake always made a mistake in setting the Architectures, Base SDK, Supported Platforms, and Valid Architectures consistently. Then I created a new OpenGL ES game project in XCode and followed the settings:

Architectures: Standard (armv7)
Base SDK: Latest iOS (iOS 5.0)
Supported Platforms: iphonesimulator iphoneos
Valid Architectures: armv6 armv7 armv7f armv7k

I also made sure that i386 did not appear in the CMAKE_CXX_FLAGS since I was building OSG for iOS Device.

The error disappeared, but a lot of new errors showed up:


'*' was not declared in this scope
'glLoadMatrixf' was not declared in this scope

It seems that XCode was not able to find the OpenGL ES library. The XCode project does not contain the OpenGLES.framework. Therefore, I created a new OpenGL ES project and added the OSG project to it. I also set the Header Search Paths to point to the root of the OpenSceneGraph package.

However, I still got the following error at the end:

'vector' file not found in lwo2chunks.h

It seems XCode cannot locate the standard library. I have no clue how that can happen.


I just found a post about how to minimize the size of the osg library for iphone:

we should build the library in arm 7 only for the device, since arm 7 is for 3GS and above. I think there is no point to build the library in arm 6 now, since iPhone 3G or earlier are relatively old now.

We also only need OpenThreads, osg, osgDB, osgGA, osgUtil and osgViewer. We can probably throw away all of the plugins.

We should also build the osg libs with Optimization set to Fastest-Smallest.

BTW, the same post also mentions that display lists are not available in OpenGL ES. Therefore, we should turn off OSG_GL_DISPLAYLISTS_AVAILABLE.


I found another post that mentions Apple loosened the terms on their license agreement to allow for dynamic linking and plug-ins now:

BTW, Thomas Hogarth is a person who successfully built OSG for iOS and also published an iOS game called Alient Attack.

Wednesday, July 27, 2011


If you set the shortcut context to Qt::ApplicationShortcut (or maybe other types too) in a QAction, you have to add the action to a widget by calling QWidget::addAction() before it can be used. This doesn't mean that the action will be visible. Adding the action to the widget will just make the shortcut part of the widget's event loop.

Monday, July 18, 2011

Dictionary: aspire

1. 立志
2. 熱望

GitX doesn't aspire to be a complete interface for the wide variety of git command-line programs with their ever-growing number of options.

Monday, June 6, 2011

osg::ClearNode clears at the start of rendering

From what I read from the mail archive below and what I tried, osg::ClearNode actually clears at the start of rendering and not just when it's reached in the draw traversal.


Saturday, March 5, 2011

Don't retain UIColor, and don't release it

UIColor manages the lifetime of colors it returns. The caller is not supposed to retain it and release it.

Objective-C's protocol's property cannot be inherited

None of the Apple's Objective-C documents or programming guides that I have seen show an example of declaring a property in a protocol and the protocol is inherited. I declared a property in a protocol by Xcode fails to recognize the property.

Friday, February 25, 2011

Using an osg::ref_ptr for 'this' in the constructor is a bad idea

Inside a constructor, the reference count of 'this' is still zero. If you use a local osg::ref_ptr to reference 'this', the reference count will increment to one. However, when the constructor ends, the lifetime of the osg::ref_ptr also ends, and the reference count will become zero again, and 'this' will be destroyed.

Monday, February 21, 2011

Starting a QThread

We must create the QApplication (or QCoreApplication) object before we create a QThread.

Thursday, February 17, 2011

[NSArray objectEnumerator]

NSEnumerator * enumerator = [array objectEnumerator];
id arrayItem;

while (arrayItem = [enumerator nextObject]) {
   // Do something about arrayItem


This is the first blog.

Angus Lau