These instructions are for Ubuntu 13.04 running under VirtualBox 4.2.12 on Window 7 with SP1.
The instructions are probably the same or similar for other version combinations but no guarantee is made.
1) Install VirtualBox Guest Additions. Full instructions can be found here.
2) Shut down the virtual machine.
It is not possible to change the VirtualBox video settings while the virtual machine is running.
3) Right-click the VirtualBox machine you want to enable 3D hardware acceleration on and select Settings…:
Right-clicking will simultaneously select the VirtualBox machine and bring up a context menu.
Alternately, you can select the VirtualBox machine and press Ctrl+S
to bring up the Settings… dialog.
4) Click on Display:
5) Slide the Video Memory slider all the way to the right and give yourself 128MB of video memory; check the Enable 3D Acceleration checkbox; click on OK:
6) Start your VirtualBox machine and 3D hardware acceleration should be enabled.
I have noticed that with VirtualBox 4.2.12 running on Windows 7, with Ubuntu 13.04 as a guest OS, that 3D hardware acceleration does not work unless the virtual machine is configured to have 2 or more CPUs. I am not sure what the problem is. It works fine with Ubuntu 12.04.
I have also noticed that I sometimes need to restart the VirtualBox application for the changes to take effect.