TwSetCurrentWindow (function)

int TwSetCurrentWindow(int windowID)


This function is intended to be used by applications with multiple graphical windows. It tells AntTweakBar to switch its current context to the context associated to the identifier windowID. All AntTweakBar functions (except TwTerminate) called after the switch would be executed in this context. If the context does not exist (ie., if this is the first time that TwSetCurrentWindow is called for this windowID), it is created.

Function TwInit must be called once before any call to TwSetCurrentWindow, it should not be called for each new window context. TwTerminate is also context insensitive and must be called once at the end of the program, it will destroy all the created contexts.

Window contexts are separated. A tweak bar created in one context cannot be modified or displayed within an other context. Thus two tweak bars with the same name can live in different contexts. Same for enum and structure definitions.

To display the tweak bars TwDraw must be called for each window context.

Event handling must also be set for each window context.



Window context identifier. This identifier could be any integer.

The window context identifier 0 always exist, this is the default context created when AntTweakBar is initialized through TwInit.

Return value

  • 0 if failed (call TwGetLastError to retrieve the error).
  • 1 if succeeded


See TwDualGLUT (file examples/TwDualGLUT.c) for a full working example. In this case the windows are GLUT sub-windows, but the principle is the same for multiple separate windows.

See also