XPLMGraphics
Coordinate conversion (world ↔ local OpenGL) and basic 2-D text and number drawing utilities.
Enumerations
XPLMFontID
X-Plane features some fixed-character fonts. Each font may have its own metrics. WARNING: Some of these fonts are no longer supported or may have changed geometries. For maximum copmatibility, see the comments below. Note: X-Plane 7 supports proportional-spaced fonts. Since no measuring routine is available yet, the SDK will normally draw using a fixed-width font. You can use a dataref to enable proportional font drawing on XP7 if you want to.
| Constant | Value | Description |
|---|---|---|
xplmFont_Basic |
0 |
Mono-spaced font for user interface. Available in all versions of the SDK. |
xplmFont_Proportional |
18 |
Proportional UI font. |
Functions
XLuaWorldToLocal(latitude, longitude, altitude)
Returns: {k} with keys: x, y, z
This routine translates coordinates from latitude, longitude, and altitude to local scene coordinates. Latitude and longitude are in decimal degrees, and altitude is in meters MSL (mean sea level). The XYZ coordinates are in meters in the local OpenGL coordinate system.
| Argument | Type | Notes |
|---|---|---|
latitude |
number |
|
longitude |
number |
|
altitude |
number |
Output table keys:
| Key | Type |
|---|---|
x |
number |
y |
number |
z |
number |
XLuaLocalToWorld(x, y, z)
Returns: {k} with keys: latitude, longitude, altitude
This routine translates a local coordinate triplet back into latitude, longitude, and altitude. Latitude and longitude are in decimal degrees, and altitude is in meters MSL (mean sea level). The XYZ coordinates are in meters in the local OpenGL coordinate system. NOTE: world coordinates are less precise than local coordinates; you should try to avoid round tripping from local to world and back.
| Argument | Type | Notes |
|---|---|---|
x |
number |
|
y |
number |
|
z |
number |
Output table keys:
| Key | Type |
|---|---|
latitude |
number |
longitude |
number |
altitude |
number |
XLuaDrawString({ i }, xOffset, yOffset, char, wordWrapWidth, fontID)
Returns: (returns nothing)
This routine draws a NULL terminated string in a given font. Pass in the lower left pixel that the character is to be drawn onto. Also pass the character and font ID. This function returns the x offset plus the width of all drawn characters. The color to draw in is specified as a pointer to an array of three floating point colors, representing RGB intensities from 0.0 to 1.0.
| Argument | Type | Notes |
|---|---|---|
colorRGB |
{ i } |
Array table — { val1, val2, ... } |
xOffset |
integer |
|
yOffset |
integer |
|
char |
string |
|
wordWrapWidth |
number |
|
fontID |
XPLMFontID |
Enum — use a constant from XPLMFontID |
XLuaDrawNumber({ i }, xOffset, yOffset, value, digits, decimals, showSign, fontID)
Returns: (returns nothing)
This routine draws a number similar to the digit editing fields in PlaneMaker and data output display in X-Plane. Pass in a color, a position, a floating point value, and formatting info. Specify how many integer and how many decimal digits to show and whether to show a sign, as well as a character set. This routine returns the xOffset plus width of the string drawn.
| Argument | Type | Notes |
|---|---|---|
colorRGB |
{ i } |
Array table — { val1, val2, ... } |
xOffset |
integer |
|
yOffset |
integer |
|
value |
number |
|
digits |
integer |
|
decimals |
integer |
|
showSign |
boolean |
|
fontID |
XPLMFontID |
Enum — use a constant from XPLMFontID |
XLuaGetFontDimensions(fontID)
Returns: {k} with keys: charWidth, charHeight, digitsOnly
This routine returns the width and height of a character in a given font. It also tells you if the font only supports numeric digits. Pass NULL if you don't need a given field. Note that for a proportional font the width will be an arbitrary, hopefully average width.
| Argument | Type | Notes |
|---|---|---|
fontID |
XPLMFontID |
Enum — use a constant from XPLMFontID |
Output table keys:
| Key | Type |
|---|---|
charWidth |
number |
charHeight |
number |
digitsOnly |
number |
XLuaMeasureString(fontID, char, numChars)
Returns: number
This routine returns the width in pixels of a string using a given font. The string is passed as a pointer plus length (and does not need to be null terminated); this is used to allow for measuring substrings. The return value is floating point; it is possible that future font drawing may allow for fractional pixels.
| Argument | Type | Notes |
|---|---|---|
fontID |
XPLMFontID |
Enum — use a constant from XPLMFontID |
char |
string |
|
numChars |
integer |
Examples
Examples coming soon.