OpenGL custom drawing

There are two ways for custom drawing:

Drawing within paintWidget(UGraphics*)

This is very easy:

paintWidget(UGraphics * g) {
  // UFO drawing if desired, e.g. g->drawString
  g->end();
  
  // your drawing here
  
  g->begin(this);
  // UFO drawing if desired
}

Otherwise you could also push all attributes and matrix and restore them after you have completed your drawing.

Drawing outside of the libUFO hierarchy.

Most of the time this means that you have already created your OpenGL context and you want to use "inline UFO" (see Integrating UFO in existing applications).

Example 5.1. How to do custom OpenGL drawing

// you may make the root pane transparent so that UFO does not overwrite
// your own drawing
// context.getRootPane()->setOpaque(false);

// main event loop
bool done = false;
while (!done) {
  // pumps events from the system event queue
  display.pumpEvents();
  // dispatchEvents returns true when a quit event was processed.
  done = display.dispatchEvents();

  if (!done) {
    // draw your own stuff
    draw();
    
    // mark the whole UFO context to be repainted
    frame->getRootPane()->repaint();
    // repaint the frame
    frame->repaint();
    // give other processes a chance
    tk.sleep(1);
  }
}

A full example is given in test/sdl.cpp and test/glut.cpp