TwAddVarRO (function)

int TwAddVarRO(TwBar *bar, const char *name, TwType type, const void *var, const char *def)


This function adds a new variable to a tweak bar by specifying the variable’s pointer. The variable is declared Read-Only (RO), so it could not be modified interactively by the user.



The tweak bar to which adding a new variable.


The name of the variable. It will be displayed in the tweak bar if no label is specified for this variable. It will also be used to refer to this variable in other functions, so choose a unique, simple and short name and avoid special characters like spaces or punctuation marks.


Type of the variable. It must be one of the TwType constants or a user defined type created with TwDefineStruct or TwDefineEnum*.


Pointer to the C/C++ variable linked to this entry.


An optional definition string used to modify the behavior of this new entry. This string must follow the variable parameters syntax, or set to NULL to get the default behavior. It could be set or modified later by calling the TwDefine or TwSetParam functions.

Return value

  • 1 if the variable was successfully added to the tweak bar.
  • 0 if an error occurred (call TwGetLastError to retrieve the error).


unsigned int NumberOfTexUnits = ...; // query the hardware to get the number of available texture units
// ...
TwAddVarRO(bar, "NumTexUnits", TW_TYPE_UINT32, &NumberOfTexUnits, " label='# of texture units' ");

See also