Implementing custom drawing logic
Factor handbook » UI framework » Implementing new gadgets » Customizing gadget appearance

Prev:UI pen protocol

The UI uses OpenGL to render gadgets. Custom rendering logic can be plugged in with the UI pen protocol, or by implementing a generic word:
draw-gadget* ( gadget -- )

Custom drawing code has access to the full OpenGL API in the opengl vocabulary.

Gadgets which need to allocate and deallocate OpenGL resources such as textures, display lists, and so on, should perform the allocation in the graft* method, and the deallocation in the ungraft* method. Since those words are not necessarily called with the gadget's OpenGL context active, a utility word can be used to find and make the correct OpenGL context current:
find-gl-context ( gadget -- )

OpenGL state must not be altered as a result of drawing a gadget, so any flags which were enabled should be disabled, and vice versa. To take full control of the OpenGL context, see Subclassing worlds.
The UI coordinate system
Subclassing worlds
OpenGL utility words
Rendering text