3.8 3D Graphics and OpenGL

This chapter describes the different libraries and plugins available to do 3D hardware accelerated graphics.

If you really want to know about most available 3D graphics frameworks for Smalltalk, you should read the related work section of this paper.

Next sections describe the ones available (as I know them), and loading instructions and first tips are at the bottom.

In 3D graphics there is support for the well known OpenGL, and also there are some higher level frameworks.


Let's start with the simplest one. I'll assume you already know what OpenGL is and that you just want to use it from Pharo. There are many bindings for OpenGL one for each kind of C communication path: one that uses FFI, one for Alien and other for NativeBoost. I think that you should first try the FFI one because it works on all mainstream platforms (Unix, Windows and Mac) and with all standard VMs.


Lumiere is a high level framework which provides better abstractions than OpenGL. It is described as a novel lightweight framework for rendering 3D graphics using OpenGL based on a stage metaphor.


Balloon3D is a renderer for Squeak written entirely in Smalltalk that provides many features in an OO way, but seems to be outdated and not maintained any more.

Loading OpenGL

With FFI

In a short future there should be a ConfigurationOfFFIOpenGL, meanwhile you'll have to do it by hand, which isn't very difficult any way.

This instructions are for Pharo 1.2 but should work in 1.0 and 1.1 without many quirks. In monticello browser click add Package and name it Balloon3D (I know, this is OpenGL FFI, but has a small dependency on Balloon). Then, click add Repository and enter

	location: 'http://www.squeaksource.com/Balloon3D'
	user: ''
	password: ''

Open it and load the latests of: Balloon3D-constants, Balloon3D-math, Balloon3D-kernel, in that order.

Now open a workspace and load FFI with this:

Gofer new
  squeaksource: 'MetacelloRepository';
  package: 'ConfigurationOfFFI';
(Smalltalk at: #ConfigurationOfFFI) project lastVersion load

One last step: go to main menu->System->Preferences. Select compiler and check "Allow underscore as assignment".

Finally, go back to the monticello browser and click add Package again. This time call it OpenGL. Click add Repository and put

	location: 'http://www.squeaksource.com/OpenGL'
	user: ''
	password: ''

Open it and load the latest version. That's all.

To see if it's working open a workspace and do this (you may get some deprecation warning depending on your Pharo version):

| ogl green canvas fade |
ogl := OpenGL newIn: (0@0 extent: 300@300).
canvas := OGLCanvas new initialize: ogl.
fade:= 0.

1000 timesRepeat: [
	ogl glClearColor:0 with: fade with: 0 with: 1.
	ogl glClear: 16r4000.
	ogl swapBuffers.
	fade := fade \+ 0.001.

With Alien

config := Gofer new
	url: 'http://www.squeaksource.com/AlienOpenGL'; 
	package: 'ConfigurationOfAlienOpenGL';
config	load.
(Smalltalk at: #ConfigurationOfAlienOpenGL) perform:#loadDefault  .

(Smalltalk at: #AlienOpenGLLibraryExamples) new perform:#testRenderingAndRotatingColoredCubes. 

Add a Note
