< GeeXLab Reference Guide />

> Back to Reference Guide Index


gh_utils library

Description

gh_utils is the module that provides various utility functions.


Number of functions: 205

  1. gh_utils.box_create ()
  2. gh_utils.box_update_size ()
  3. gh_utils.buffer_copy ()
  4. gh_utils.buffer_crc32 ()
  5. gh_utils.buffer_create ()
  6. gh_utils.buffer_kill ()
  7. gh_utils.buffer_md5 ()
  8. gh_utils.buffer_read_1f ()
  9. gh_utils.buffer_read_2f ()
  10. gh_utils.buffer_read_3f ()
  11. gh_utils.buffer_read_4f ()
  12. gh_utils.buffer_read_byte ()
  13. gh_utils.buffer_read_line ()
  14. gh_utils.buffer_sha1 ()
  15. gh_utils.buffer_sha256 ()
  16. gh_utils.buffer_to_file ()
  17. gh_utils.buffer_write_1f ()
  18. gh_utils.buffer_write_2f ()
  19. gh_utils.buffer_write_3f ()
  20. gh_utils.buffer_write_4f ()
  21. gh_utils.buffer_write_byte ()
  22. gh_utils.circle_create ()
  23. gh_utils.circle_create_v2 ()
  24. gh_utils.circle_update_radius ()
  25. gh_utils.clipboard_get_text ()
  26. gh_utils.clipboard_set_text ()
  27. gh_utils.cpu_get_mem_available_size_mb ()
  28. gh_utils.cpu_get_mem_size_mb ()
  29. gh_utils.cpu_get_name ()
  30. gh_utils.cpu_get_speed_mhz ()
  31. gh_utils.cpu_usage_cleanup ()
  32. gh_utils.cpu_usage_get_core_count ()
  33. gh_utils.cpu_usage_get_core_usage ()
  34. gh_utils.cpu_usage_init ()
  35. gh_utils.cpu_usage_update ()
  36. gh_utils.do_file_from_sqlite3_blob ()
  37. gh_utils.do_file_from_zip ()
  38. gh_utils.do_screenshot ()
  39. gh_utils.do_screenshot_v2 ()
  40. gh_utils.do_screenshot_v3 ()
  41. gh_utils.do_screenshot_v4 ()
  42. gh_utils.do_screenshot_v5 ()
  43. gh_utils.do_screenshot_v6 ()
  44. gh_utils.screenshot_threaded_get_stats ()
  45. gh_utils.screenshot_kill_image_saving_thread ()
  46. gh_utils.drop_files_get_file_by_index ()
  47. gh_utils.drop_files_get_num_files ()
  48. gh_utils.dylib_frame ()
  49. gh_utils.dylib_get_message ()
  50. gh_utils.dylib_load ()
  51. gh_utils.dylib_resize ()
  52. gh_utils.dylib_set_message ()
  53. gh_utils.dylib_start ()
  54. gh_utils.dylib_stop ()
  55. gh_utils.dylib_unload ()
  56. gh_utils.exe_from_buffer ()
  57. gh_utils.exe_script ()
  58. gh_utils.exe_script_v2 ()
  59. gh_utils.exe_script_v3 ()
  60. gh_utils.exe_string ()
  61. gh_utils.extract_dir_from_filename ()
  62. gh_utils.file_buffer_create ()
  63. gh_utils.file_crc32 ()
  64. gh_utils.file_md5 ()
  65. gh_utils.file_sha1 ()
  66. gh_utils.file_sha256 ()
  67. gh_utils.file_size ()
  68. gh_utils.font_create ()
  69. gh_utils.font_render ()
  70. gh_utils.font_render3d ()
  71. gh_utils.font_set_viewport_info ()
  72. gh_utils.ftgl_font_add_text2d ()
  73. gh_utils.ftgl_font_add_text3d ()
  74. gh_utils.ftgl_font_clear ()
  75. gh_utils.ftgl_font_create ()
  76. gh_utils.ftgl_font_kill ()
  77. gh_utils.ftgl_font_render ()
  78. gh_utils.ftgl_font_texture_kill ()
  79. gh_utils.ftgl_font_texture_load ()
  80. gh_utils.get_app_dir ()
  81. gh_utils.get_app_version ()
  82. gh_utils.get_command_line ()
  83. gh_utils.get_date_str ()
  84. gh_utils.get_demo_dir ()
  85. gh_utils.get_demo_zip_filename ()
  86. gh_utils.get_elapsed_time ()
  87. gh_utils.get_lib_dir ()
  88. gh_utils.get_desktop_resolution ()
  89. gh_utils.get_os_info ()
  90. gh_utils.get_platform ()
  91. gh_utils.get_platform_name ()
  92. gh_utils.get_time_step ()
  93. gh_utils.get_uptime ()
  94. gh_utils.global_array_char_alloc ()
  95. gh_utils.global_array_char_get ()
  96. gh_utils.global_array_char_set ()
  97. gh_utils.global_array_float_alloc ()
  98. gh_utils.global_array_float_get ()
  99. gh_utils.global_array_float_set ()
  100. gh_utils.global_array_int_alloc ()
  101. gh_utils.global_array_int_get ()
  102. gh_utils.global_array_int_set ()
  103. gh_utils.grid_create ()
  104. gh_utils.grid_set_display_lines_options ()
  105. gh_utils.grid_set_geometry_params ()
  106. gh_utils.grid_set_lines_color ()
  107. gh_utils.grid_set_main_lines_color ()
  108. gh_utils.grid_set_main_x_axis_color ()
  109. gh_utils.grid_set_main_z_axis_color ()
  110. gh_utils.hex_color_to_rgb ()
  111. gh_utils.is_64bit ()
  112. gh_utils.is_luajit ()
  113. gh_utils.is_rpi ()
  114. gh_utils.line_create ()
  115. gh_utils.line_set_end_color ()
  116. gh_utils.line_set_end_position ()
  117. gh_utils.line_set_start_color ()
  118. gh_utils.line_set_start_position ()
  119. gh_utils.math_length_vec3 ()
  120. gh_utils.math_normalize_vec3 ()
  121. gh_utils.math_quat_from_lookat ()
  122. gh_utils.math_quat_from_vectors_rotation ()
  123. gh_utils.math_quat_from_euler_angles ()
  124. gh_utils.nfd_open_dialog ()
  125. gh_utils.nfd_pick_folder ()
  126. gh_utils.nfd_save_dialog ()
  127. gh_utils.open_url ()
  128. gh_utils.printc ()
  129. gh_utils.progress_bar_inc ()
  130. gh_utils.progress_bar_set ()
  131. gh_utils.project_3d_to_2d_v1 ()
  132. gh_utils.project_3d_to_2d_v2 ()
  133. gh_utils.random ()
  134. gh_utils.srandom ()
  135. gh_utils.random16 ()
  136. gh_utils.random32 ()
  137. gh_utils.raycast_cast_ray ()
  138. gh_utils.raycast_cast_ray_v2 ()
  139. gh_utils.raycast_get_ray ()
  140. gh_utils.raycast_get_ray_ortho_cam ()
  141. gh_utils.sanitize_string ()
  142. gh_utils.shared_variable_create ()
  143. gh_utils.shared_variable_create_array ()
  144. gh_utils.shared_variable_get_array_value_1f ()
  145. gh_utils.shared_variable_get_array_value_1i ()
  146. gh_utils.shared_variable_get_array_value_str ()
  147. gh_utils.shared_variable_get_value_4f ()
  148. gh_utils.shared_variable_get_value_str ()
  149. gh_utils.shared_variable_is_exist ()
  150. gh_utils.shared_variable_kill ()
  151. gh_utils.shared_variable_set_array_value_1f ()
  152. gh_utils.shared_variable_set_array_value_1i ()
  153. gh_utils.shared_variable_set_array_value_str ()
  154. gh_utils.shared_variable_set_value_4f ()
  155. gh_utils.shared_variable_set_value_str ()
  156. gh_utils.sphere_create ()
  157. gh_utils.sphere_update_radius ()
  158. gh_utils.stop_demo ()
  159. gh_utils.sys_exec ()
  160. gh_utils.thread_sleep ()
  161. gh_utils.thread_lock_create ()
  162. gh_utils.thread_lock_kill_all ()
  163. gh_utils.thread_lock_acquire ()
  164. gh_utils.thread_lock_release ()
  165. gh_utils.trace ()
  166. gh_utils.trackball_get_orientation ()
  167. gh_utils.trackball_init ()
  168. gh_utils.tripod_visualizer_camera_render ()
  169. gh_utils.vendor_name_from_vendor_id ()
  170. gh_utils.webcam_create ()
  171. gh_utils.webcam_get_frame_size ()
  172. gh_utils.webcam_get_name ()
  173. gh_utils.webcam_get_num ()
  174. gh_utils.webcam_grab_frame ()
  175. gh_utils.webcam_kill ()
  176. gh_utils.webcam_start ()
  177. gh_utils.webcam_stop ()
  178. gh_utils.webcam_update_texture ()
  179. gh_utils.zip_buffer_create ()
  180. gh_utils.zip_to_file ()
  181. gh_utils.win_registry_read_value_dword ()
  182. gh_utils.win_registry_write_value_dword ()
  183. gh_utils.win_registry_read_value_string ()
  184. gh_utils.win_registry_write_value_string ()
  185. gh_utils.win_registry_create_key ()
  186. gh_utils.win_registry_delete_key ()
  187. gh_utils.pack_rgba_u8 ()
  188. gh_utils.unpack_rgba_u8 ()
  189. gh_utils.set_new_scene_data ()
  190. gh_utils.temp_directory_path ()
  191. gh_utils.get_app_name ()
  192. gh_utils.spirv_to_smolv ()
  193. gh_utils.smolv_to_spirv ()
  194. gh_utils.math_from_to_rotation_matrix3x3 ()
  195. gh_utils.file_read ()
  196. gh_utils.file_write ()
  197. gh_utils.file_size ()
  198. gh_utils.shmem_create ()
  199. gh_utils.shmem_kill ()
  200. gh_utils.shmem_is_available ()
  201. gh_utils.shmem_map ()
  202. gh_utils.shmem_unmap ()
  203. gh_utils.win32_audio_volume_control ()
  204. gh_utils.qr_code_scan ()
  205. gh_utils.qr_code_gen ()



box_create

Description

Creates a simple box.


Syntax

box_id = gh_utils.box_create(
 w, h, d,
 r, g, b, a
)

Languages


Parameters


Return Values


Code sample


box_id = gh_utils.box_create(10.0, 10.0, 10.0,  1.0, 1.0, 0.0, 1.0)
			


box_update_size

Description

Updates the size of a box.


Syntax

gh_utils.box_update_size(
 box_id,
 w, h, d
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.box_update_size(box_id, 12.0, 12.0, 12.0)
			


buffer_copy

Description

Copies a source memory buffer to a destination memory buffer.


Syntax

gh_utils.buffer_copy(
 src_buff_ptr,
 src_offset,
 dst_buff_ptr,
 dst_offset,
 num_bytes
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


src_ptr, size = gh_utils.buffer_create(1024)
dst_ptr, size = gh_utils.buffer_create(1024)

...
gh_utils.buffer_create(src_ptr, 0, dst_ptr, 0, 1024)
...
			


buffer_crc32

Description

Helper function to get the CRC32 hash code of a memory buffer.


Syntax

hashcode = gh_utils.buffer_crc32(
 buff_ptr,
 offset
)

Languages


Parameters


Return Values


Code sample


filename = gh_utils.get_demo_dir() .. "assets/image01.jpg"

buffer_ptr, buffer_size = gh_utils.file_buffer_create(filename)

hashcode = gh_utils.buffer_crc32(buffer_ptr, buffer_size)

gh_utils.file_buffer_kill(buffer_ptr)
			


buffer_create

Description

Creates an empty memory buffer.


Syntax

buff_ptr, buff_size = gh_utils.buffer_create(
 size
)

Languages


Parameters


Return Values


Code sample


buffer_ptr, buffer_size = gh_utils.buffer_create(1024)
...
gh_utils.buffer_kill(buffer_ptr)
			


buffer_kill

Description

Frees the pointer returned by buffer_create(), file_buffer_create() or zip_buffer_create.


Syntax

gh_utils.buffer_kill(
 buff_ptr
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


buffer_ptr, buffer_size = gh_utils.buffer_create(1024)
...
gh_utils.buffer_kill(buffer_ptr)
			


buffer_md5

Description

Helper function to get the MD5 hash code of a memory buffer.


Syntax

hashcode = gh_utils.buffer_md5(
 buff_ptr,
 offset
)

Languages


Parameters


Return Values


Code sample


filename = gh_utils.get_demo_dir() .. "assets/image01.jpg"

buffer_ptr, buffer_size = gh_utils.file_buffer_create(filename)

hashcode = gh_utils.buffer_md5(buffer_ptr, buffer_size)

gh_utils.file_buffer_kill(buffer_ptr)
			


buffer_read_1f

Description

Reads a float from a memory buffer via a pointer. The pointer must have been created by buffer_create(), zip_buffer_create() or file_buffer_create().


Syntax

x, y = gh_utils.buffer_read_1f(
 buff_ptr,
 offset
)

Languages


Parameters


Return Values


Code sample


filename = gh_utils.get_demo_dir() .. "data.txt"

buffer_ptr, buffer_size = gh_utils.file_buffer_create(filename)

offset = 0
x = gh_utils.buffer_read_1f(buffer_ptr, offset)
...
gh_utils.file_buffer_kill(buffer_ptr)
			


buffer_read_2f

Description

Reads a vec2 from a memory buffer via a pointer. The pointer must have been created by buffer_create(), zip_buffer_create() or file_buffer_create().


Syntax

x, y = gh_utils.buffer_read_2f(
 buff_ptr,
 offset
)

Languages


Parameters


Return Values


Code sample


filename = gh_utils.get_demo_dir() .. "data.txt"

buffer_ptr, buffer_size = gh_utils.file_buffer_create(filename)

offset = 0
x, y = gh_utils.buffer_read_2f(buffer_ptr, offset)
...
gh_utils.file_buffer_kill(buffer_ptr)
			


buffer_read_3f

Description

Reads a vec3 from a memory buffer via a pointer. The pointer must have been created by buffer_create(), zip_buffer_create() or file_buffer_create().


Syntax

x, y, z = gh_utils.buffer_read_3f(
 buff_ptr,
 offset
)

Languages


Parameters


Return Values


Code sample


filename = gh_utils.get_demo_dir() .. "data.txt"

buffer_ptr, buffer_size = gh_utils.file_buffer_create(filename)

offset = 0
x, y, z = gh_utils.buffer_read_3f(buffer_ptr, offset)
...
gh_utils.file_buffer_kill(buffer_ptr)
			


buffer_read_4f

Description

Reads a vec4 from a memory buffer via a pointer. The pointer must have been created by buffer_create(), zip_buffer_create() or file_buffer_create().


Syntax

x, y, z, w = gh_utils.buffer_read_4f(
 buff_ptr,
 offset
)

Languages


Parameters


Return Values


Code sample


filename = gh_utils.get_demo_dir() .. "data.txt"

buffer_ptr, buffer_size = gh_utils.file_buffer_create(filename)

offset = 0
x, y, z, w = gh_utils.buffer_read_4f(buffer_ptr, offset)
...
gh_utils.file_buffer_kill(buffer_ptr)
			


buffer_read_byte

Description

Reads a byte from a memory buffer via a pointer. The pointer must have been created by zip_buffer_create() or file_buffer_create().


Syntax

x = gh_utils.buffer_read_byte(
 buff_ptr,
 offset
)

Languages


Parameters


Return Values


Code sample


filename = gh_utils.get_demo_dir() .. "config.txt"

buffer_ptr, buffer_size = gh_utils.file_buffer_create(filename)

-- read the first byte:
x = gh_utils.buffer_read_byte(buffer_ptr, 0)

-- read the second byte:
x = gh_utils.buffer_read_byte(buffer_ptr, 1)

...
...
...

gh_utils.file_buffer_kill(buffer_ptr)
			


buffer_read_line

Description

Reads a line from a memory buffer via a pointer. The pointer must have created by zip_buffer_create() or file_buffer_create().


Syntax

line, line_size = gh_utils.buffer_read_line(
 buff_ptr,
 buff_size,
 offset
)

Languages


Parameters


Return Values


Code sample


filename = gh_utils.get_demo_dir() .. "config.txt"

buffer_ptr, buffer_size = gh_utils.file_buffer_create(filename)

line_offset = 0
-- read the first line:
line, line_size = gh_utils.buffer_read_line(buffer_ptr, buffer_size, line_offset)

line_offset = line_offset + line_size
-- read the second line:
line, line_size = gh_utils.buffer_read_line(buffer_ptr, buffer_size, line_offset)
...
...
...
gh_utils.file_buffer_kill(buffer_ptr)
			


buffer_sha1

Description

Helper function to get the SHA1 hash code of a memory buffer.


Syntax

hashcode = gh_utils.buffer_sha1(
 buff_ptr,
 offset
)

Languages


Parameters


Return Values


Code sample


filename = gh_utils.get_demo_dir() .. "assets/image01.jpg"

buffer_ptr, buffer_size = gh_utils.file_buffer_create(filename)

hashcode = gh_utils.buffer_sha1(buffer_ptr, buffer_size)
gh_utils.file_buffer_kill(buffer_ptr)
			


buffer_sha256

Description

Helper function to get the SHA256 hash code of a memory buffer.


Syntax

hashcode = gh_utils.buffer_sha256(
 buff_ptr,
 offset
)

Languages


Parameters


Return Values


Code sample


filename = gh_utils.get_demo_dir() .. "assets/image01.jpg"

buffer_ptr, buffer_size = gh_utils.file_buffer_create(filename)

hashcode = gh_utils.buffer_sha256(buffer_ptr, buffer_size)
gh_utils.file_buffer_kill(buffer_ptr)
			


buffer_to_file

Description

Save the content of a memory buffer into a file.


Syntax

ret = gh_utils.buffer_to_file(
 buff_ptr,
 buff_size,
 dst_filename
)

Languages


Parameters


Return Values


Code sample


dst_filename = gh_utils.get_demo_dir() .. "image01.jpg"

if (gh_utils.buffer_to_file(buffer, buffer_size, dst_filename) == 1) then
    -- OK!
end
			


buffer_write_1f

Description

Writes a float to a memory buffer via a pointer. The pointer must have been created by zip_buffer_create() or file_buffer_create().


Syntax

gh_utils.buffer_write_1f(
 buff_ptr,
 offset,
 x
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


buffer_ptr, buffer_size = gh_utils.buffer_create(1024)

x = 3.14
gh_utils.buffer_write_1f(buffer_ptr, 0, x)
...
gh_utils.buffer_to_file(buffer_ptr, buffer_size, dst_filename)

gh_utils.buffer_kill(buffer_ptr)
			


buffer_write_2f

Description

Writes a vec2 to a memory buffer via a pointer. The pointer must have been created by zip_buffer_create() or file_buffer_create().


Syntax

gh_utils.buffer_write_2f(
 buff_ptr,
 offset,
 x, y
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


buffer_ptr, buffer_size = gh_utils.buffer_create(1024)

x = 3.14
y = 1.22
gh_utils.buffer_write_2f(buffer_ptr, 0, x, y)
...
gh_utils.buffer_to_file(buffer_ptr, buffer_size, dst_filename)

gh_utils.buffer_kill(buffer_ptr)
			


buffer_write_3f

Description

Writes a vec3 to a memory buffer via a pointer. The pointer must have been created by zip_buffer_create() or file_buffer_create().


Syntax

gh_utils.buffer_write_3f(
 buff_ptr,
 offset,
 x, y, z
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


buffer_ptr, buffer_size = gh_utils.buffer_create(1024)

x = 3.14
y = 1.22
z = -0.57
gh_utils.buffer_write_3f(buffer_ptr, 0, x, y, z)
...
gh_utils.buffer_to_file(buffer_ptr, buffer_size, dst_filename)

gh_utils.buffer_kill(buffer_ptr)
			


buffer_write_4f

Description

Writes a vec4 to a memory buffer via a pointer. The pointer must have been created by zip_buffer_create() or file_buffer_create().


Syntax

gh_utils.buffer_write_4f(
 buff_ptr,
 offset,
 x, y, z, w
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


buffer_ptr, buffer_size = gh_utils.buffer_create(1024)

x = 3.14
y = 1.22
z = -0.57
w = 1.0
gh_utils.buffer_write_4f(buffer_ptr, 0, x, y, z, w)
...
gh_utils.buffer_to_file(buffer_ptr, buffer_size, dst_filename)

gh_utils.buffer_kill(buffer_ptr)
			


buffer_write_byte

Description

Writes a byte to a memory buffer via a pointer. The pointer must have been created by zip_buffer_create() or file_buffer_create().


Syntax

gh_utils.buffer_write_byte(
 buff_ptr,
 offset,
 x
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


filename = gh_utils.get_demo_dir() .. "config.txt"

buffer_ptr, buffer_size = gh_utils.file_buffer_create(filename)

-- write the first byte:
x = 100
gh_utils.buffer_write_byte(buffer_ptr, 0, x)

-- write the second byte:
x = 112
gh_utils.buffer_write_byte(buffer_ptr, 1, x)

...
...
...

gh_utils.buffer_to_file(buffer_ptr, buffer_size, dst_filename)

gh_utils.file_buffer_kill(buffer_ptr)
			


circle_create

Description

Creates a simple circle in the XZ plane.


Syntax

circle_id = gh_utils.circle_create(
 radius,
 subdivisions,
 r, g, b, a
)

Languages


Parameters


Return Values


Code sample


circle_id = gh_utils.circle_create(10.0, 20, 1.0, 1.0, 0.0, 1.0)
			


circle_create_v2

Description

Creates a simple circle.


Syntax

circle_id = gh_utils.circle_create_v2(
 plane_type,
 radius,
 subdivisions,
 r, g, b, a
)

Languages


Parameters


Return Values


Code sample


plane_type = 1
circle_id = gh_utils.circle_create_v2(plane_type, 10.0, 20, 1.0, 1.0, 0.0, 1.0)
			


circle_update_radius

Description

Updates the radius of a circle.


Syntax

gh_utils.circle_update_radius(
 circle_id,
 radius
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.circle_update_radius(circle_id, 12.0)
			


clipboard_get_text

Description

Allows to get the content (text type) of the clipboard (Windows and Linux only). It's the past operation of 'Copy and Paste'


Syntax

text, text_len = gh_utils.clipboard_get_text()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


text, text_len = gh_utils.clipboard_get_text()
			


clipboard_set_text

Description

Allows to copy a string to the clipboard (Windows only). It's the copy operation of 'Copy and Paste'


Syntax

gh_utils.clipboard_set_text(
 text
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.clipboard_set_text("Hello!")
			


cpu_get_mem_available_size_mb

Description

Returns the size of the available physical system memory in MB.


Syntax

size = gh_utils.cpu_get_mem_available_size_mb()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


mem_size_mb = gh_utils.cpu_get_mem_available_size_mb()
			


cpu_get_mem_size_mb

Description

Returns the size of the physical system memory in MB.


Syntax

size = gh_utils.cpu_get_mem_size_mb()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


mem_size_mb = gh_utils.cpu_get_mem_size_mb()
			


cpu_get_name

Description

Returns the CPU name - This function requires the GPU monitoring plugin (Windows, Linux and macOS).


Syntax

str = gh_utils.cpu_get_name()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


local cpu_name = gh_utils.cpu_get_name()
			


cpu_get_speed_mhz

Description

Returns the CPU speed in MHz - This function requires the GPU monitoring plugin (Windows, Linux and macOS).


Syntax

speed = gh_utils.cpu_get_speed_mhz()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


local cpu_speed = gh_utils.cpu_get_speed_mhz()
			


cpu_usage_cleanup

Description

Cleans up the CPU usage code. Should be called in a TERMINATE script (Windows only).


Syntax

gh_utils.cpu_usage_cleanup()

Languages


Parameters

This function has no input parameter(s).


Return Values

This function has no return value(s).


Code sample


gh_utils.cpu_usage_cleanup()
			


cpu_usage_get_core_count

Description

Returns the number of CPU cores (Windows only).


Syntax

num_cores = gh_utils.cpu_usage_get_core_count()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


local cores = gh_utils.cpu_usage_get_core_count()
			


cpu_usage_get_core_usage

Description

Returns the usage of a particular core (Windows only).


Syntax

usage = gh_utils.cpu_usage_get_core_usage(
 index
)

Languages


Parameters


Return Values


Code sample


local core_index = 0
local usage = gh_utils.cpu_usage_get_core_usage(core_index)
			


cpu_usage_init

Description

Initializes the CPU usage code. Should be called in INIT scripts (Windows only).


Syntax

ret = gh_utils.cpu_usage_init()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


local ret = gh_utils.cpu_usage_init()
			


cpu_usage_update

Description

Updates the CPU usage. Should be called in a FRAME script (Windows only).


Syntax

gh_utils.cpu_usage_update()

Languages


Parameters

This function has no input parameter(s).


Return Values

This function has no return value(s).


Code sample


gh_utils.cpu_usage_update()
			


do_file_from_sqlite3_blob

Description

Executes a script stored in a SQLite3 blob.


Syntax

ret = gh_utils.do_file_from_sqlite3_blob(
 db_id,
 column
)

Languages


Parameters


Return Values


Code sample


gh_utils.do_file_from_sqlite3_blob(db_id, column)
			


do_file_from_zip

Description

Executes a script file stored in a zip archive.


Syntax

ret = gh_utils.do_file_from_zip(
 zip_filename,
 filename
)

Languages


Parameters


Return Values


Code sample


zip_filename = demo_dir .. "data.zip"
gh_utils.do_file_from_zip(zip_filename, "scripts/init02.lua")
			


do_screenshot

Description

Does a screenshot and write it to a file (JPEG file) - OpenGL and Vulkan renderers.


Syntax

gh_utils.do_screenshot(
 filename,
 absolute_path
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.do_screenshot("image.jpg", 0)
			


do_screenshot_v2

Description

Does a screenshot and write it to a file (JPEG file) - OpenGL and Vulkan renderers.


Syntax

gh_utils.do_screenshot_v2(
 filename,
 flip_image
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


local demo_dir = gh_utils.get_demo_dir()
local flip_image = 1

gh_utils.do_screenshot_v2(demo_dir .. "image.jpg", flip_image)
			


do_screenshot_v3

Description

Does a screenshot and write it to a file (JPEG file) - OpenGL and Vulkan renderers.


Syntax

gh_utils.do_screenshot_v3(
 filename,
 x, y, width, height,
 flip_image
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


local demo_dir = gh_utils.get_demo_dir()
local flip_image = 1
local x = 0
local y = 0

gh_utils.do_screenshot_v3(demo_dir .. "image.jpg", x, y, winW, winH, flip_image)
			


do_screenshot_v4

Description

Does a screenshot and write it to a file - OpenGL and Vulkan renderers.


Syntax

gh_utils.do_screenshot_v4(
 filename,
 x, y, width, height,
 flip_image,
 format,
 saving_options
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


local demo_dir = gh_utils.get_demo_dir()
local flip_image = 1
local x = 0
local y = 0
format = "jpg"
saving_options = ""
gh_utils.do_screenshot_v4(demo_dir .. "image.jpg", x, y, winW, winH, flip_image, format, saving_options)
			


do_screenshot_v5

Description

Does a screenshot and write it to a file - OpenGL and Vulkan renderers.


Syntax

gh_utils.do_screenshot_v5(
 filename,
 x, y, width, height,
 flip_image,
 format,
 saving_options,
 image_codec_name
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


local demo_dir = gh_utils.get_demo_dir()
local flip_image = 1
local x = 0
local y = 0
format = "jpg"
saving_options = ""
image_codec_name = "FreeImage" -- default codec: "stb"
gh_utils.do_screenshot_v5(demo_dir .. "image.jpg", x, y, winW, winH, flip_image, format, saving_options, image_codec_name)
			


do_screenshot_v6

Description

Does a screenshot and write it to a file - OpenGL and Vulkan renderers. The image saving is done in a separate system thread, leading to performance gain compared to do_screenshot_v5.


Syntax

gh_utils.do_screenshot_v6(
 filename,
 x, y, width, height,
 flip_image,
 format,
 saving_options,
 image_codec_name
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


local demo_dir = gh_utils.get_demo_dir()
local flip_image = 1
local x = 0
local y = 0
format = "jpg"
saving_options = ""
image_codec_name = "FreeImage" -- default codec: "stb"
gh_utils.do_screenshot_v6(demo_dir .. "image.jpg", x, y, winW, winH, flip_image, format, saving_options, image_codec_name)
			


screenshot_threaded_get_stats

Description

Returns the number of images currently saved and the number of images queued (that are not saved yet). This function works with do_screenshot_v6().


Syntax

num_saved_images, num_queued_images = gh_utils.screenshot_threaded_get_stats()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


gh_utils.do_screenshot_v6(.......)
num_saved_images, num_queued_images = gh_utils.screenshot_threaded_get_stats()
			


screenshot_kill_image_saving_thread

Description

Stops and kills the image saving thread created by do_screenshot_v6().


Syntax

gh_utils.screenshot_kill_image_saving_thread()

Languages


Parameters

This function has no input parameter(s).


Return Values

This function has no return value(s).


Code sample


gh_utils.screenshot_kill_image_saving_thread()
			


drop_files_get_file_by_index

Description

Returns the name of a particular file that has been dropped on the application. This function is useful in a DRAG_N_DROP script (Windows only).


Syntax

filename = gh_utils.drop_files_get_file_by_index(
 index
)

Languages


Parameters


Return Values


Code sample


num_files = gh_utils.drop_files_get_num_files()

if (num_files > 0) then
    -- Gets the first dropped file:
    filename = gh_utils.drop_files_get_file_by_index(0)
end
			


drop_files_get_num_files

Description

Returns the number of files that have been dropped on the application. This function is useful in a DRAG_N_DROP script (Windows only).


Syntax

num_dropped = gh_utils.drop_files_get_num_files()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


num_files = gh_utils.drop_files_get_num_files()
			


dylib_frame

Description

Calls the frame function of a dynamic library.


Syntax

gh_utils.dylib_frame(
 dylib_id,
 elapsed_time,
 data
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.dylib_frame(dylib_id, elapsed_time, "")
			


dylib_get_message

Description

Gets a message. Allows to communicate with the dylib.


Syntax

message = gh_utils.dylib_get_message(
 dylib_id
)

Languages


Parameters


Return Values


Code sample


message = gh_utils.dylib_get_message(dylib_id)
			


dylib_load

Description

Loads a dynamic library. Check the forum for more information about loading dynamic libraries.


Syntax

dylib_id = gh_utils.dylib_load(
 dylib_filename
)

Languages


Parameters


Return Values


Code sample


dylib_id = gh_utils.dylib_load("/Users/toto/my3dcode.dylib")
			


dylib_resize

Description

Calls the frame function of a dynamic library.


Syntax

gh_utils.dylib_resize(
 dylib_id,
 width, height,
 data
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.dylib_resize(dylib_id, width, height, "")
			


dylib_set_message

Description

Sets a message. Allows to communicate with the dylib.


Syntax

gh_utils.dylib_set_message(
 dylib_id,
 message
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


message = "....."

gh_utils.dylib_set_message(dylib_id, message)
			


dylib_start

Description

Calls the start function of a dynamic library.


Syntax

gh_utils.dylib_start(
 dylib_id,
 width, height,
 data
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.dylib_start(dylib_id, width, height, "")
			


dylib_stop

Description

Calls the stop function of a dynamic library.


Syntax

gh_utils.dylib_stop(
 dylib_id,
 data
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.dylib_stop(dylib_id, "")
			


dylib_unload

Description

Unloads a dynamic library.


Syntax

gh_utils.dylib_unload(
 dylib_id
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.dylib_unload(dylib_id)
			


exe_from_buffer

Description

Executes a script from a memory buffer.


Syntax

ret = gh_utils.exe_from_buffer(
 buff_ptr,
 buff_size
)

Languages


Parameters


Return Values


Code sample


local demo_dir = gh_utils.get_demo_dir()
filename = demo_dir .. "assets/init_textures.lua"

buffer, buffer_size = gh_utils.file_buffer_create(filename)

if (gh_utils.exe_from_buffer(buffer, buffer_size) == 1) then
    -- ok
end

gh_utils.file_buffer_kill(buffer)
			


exe_script

Description

Executes a script.


Syntax

gh_utils.exe_script(
 name,
 threaded
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


local threaded = 0
gh_utils.exe_script("init_meshes", threaded)
			


exe_script_v2

Description

Executes a script.


Syntax

gh_utils.exe_script_v2(
 name,
 threaded,
 create_worker_wind3d
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


local threaded = 1
local create_worker_wind3d = 0

gh_utils.exe_script_v2("load_textures_cpu", threaded, create_worker_wind3d)
			


exe_script_v3

Description

Executes a script.


Syntax

gh_utils.exe_script_v3(
 name,
 threaded,
 create_worker_wind3d,
 thread_affinity_mask
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


local threaded = 1
local create_worker_wind3d = 0
local thread_affinity_mask = 0

gh_utils.exe_script_v3("load_textures_cpu", threaded, create_worker_wind3d, thread_affinity_mask)
			


exe_string

Description

Executes a script.


Syntax

ret = gh_utils.exe_string(
 lua_python_commands
)

Languages


Parameters


Return Values


Code sample


gh_utils.exe_string("demo_folder = gh_utils.get_demo_dir()")
print(demo_folder)
			


extract_dir_from_filename

Description

Utility function that extracts a path / folder from a file name.


Syntax

filename = gh_utils.extract_dir_from_filename(
 filename
)

Languages


Parameters


Return Values


Code sample


folder = gh_utils.extract_dir_from_filename(filename)
			


file_buffer_create

Description

Gets a pointer to the memory buffer of a file stored in the file system.


Syntax

buff_ptr, buff_size = gh_utils.file_buffer_create(
 filename
)

Languages


Parameters


Return Values


Code sample


filename = gh_utils.get_demo_dir() .. "config.txt"

buffer_ptr, buffer_size = gh_utils.file_buffer_create(filename)
...
gh_utils.buffer_kill(buffer_ptr)
			


file_crc32

Description

Helper function to get the CRC32 hash code of a file on the disk or in a zip file.


Syntax

crc32, crc32_str = gh_utils.file_crc32(
 zip_filename,
 filename
)

Languages


Parameters


Return Values


Code sample


zip_filename = ""
filename = gh_utils.get_demo_dir() .. "assets/image01.jpg"

crc32, crc32_str = gh_utils.file_crc32(zip_filename, filename)
			


file_md5

Description

Helper function to get the MD5 hash code of a file on the disk or in a zip file.


Syntax

hashcode = gh_utils.file_md5(
 zip_filename,
 filename
)

Languages


Parameters


Return Values


Code sample


zip_filename = ""
filename = gh_utils.get_demo_dir() .. "assets/image01.jpg"

hashcode = gh_utils.file_md5(zip_filename, filename)
			


file_sha1

Description

Helper function to get the SHA1 hash code of a file on the disk or in a zip file.


Syntax

hashcode = gh_utils.file_sha1(
 zip_filename,
 filename
)

Languages


Parameters


Return Values


Code sample


zip_filename = ""
filename = gh_utils.get_demo_dir() .. "assets/image01.jpg"

hashcode = gh_utils.file_sha1(zip_filename, filename)
			


file_sha256

Description

Helper function to get the SHA-256 hash code of a file on the disk or in a zip file.


Syntax

hashcode = gh_utils.file_sha256(
 zip_filename,
 filename
)

Languages


Parameters


Return Values


Code sample


zip_filename = ""
filename = gh_utils.get_demo_dir() .. "assets/image01.jpg"

hashcode = gh_utils.file_sha256(zip_filename, filename)
			


file_size

Description

Helper function to get the size of a file on the disk or in a zip file.


Syntax

size = gh_utils.file_size(
 zip_filename,
 filename
)

Languages


Parameters


Return Values


Code sample


zip_filename = ""
filename = gh_utils.get_demo_dir() .. "assets/image01.jpg"

size = gh_utils.file_size(zip_filename, filename)
			


font_create

Description

Creates a new font.


Syntax

font_id = gh_utils.font_create(
 font_name,
 height
)

Languages


Parameters


Return Values


Code sample


font_id = gh_utils.font_create("Arial", 14)
			


font_render

Description

Renders (draws) a text.


Syntax

gh_utils.font_render(
 font_id,
 x, y,
 r, g, b, a,
 text
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.font_set_viewport_info(font_id, 0, 0, width, height)

gh_utils.font_render(font, 10, 40, 0.2, 1.0, 0.0, 1.0, string.format("Image filename: %s", texture_filename))
			


font_render3d

Description

Renders (draws) a text at a 3D position.


Syntax

gh_utils.font_render3d(
 font_id,
 x, y, z,
 r, g, b, a,
 text
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.font_render3d(font_id, 0, 20.0, -20.0, 0.2, 1.0, 0.0, 1.0, "V1")
			


font_set_viewport_info

Description

Sets the viewport information. You have to call this function when the window is resized.


Syntax

gh_utils.font_set_viewport_info(
 font_id,
 x, y,
 width, height
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.font_set_viewport_info(font_id, 0, 0, width, height)
			


ftgl_font_add_text2d

Description

Adds a 2D text in a font.


Syntax

gh_utils.ftgl_font_add_text2d(
 font_id,
 x, y,
 r, g, b, a,
 text
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.ftgl_font_add_text2d(font_id, 10, 20, 1.0, 0.0, 0.0, 1.0, "GeeXLab - line1")
gh_utils.ftgl_font_add_text2d(font_id, 10, 40, 1.0, 0.0, 0.0, 1.0, "GeeXLab - line2")
			


ftgl_font_add_text3d

Description

Adds a 3D text in a font.


Syntax

gh_utils.ftgl_font_add_text3d(
 font_id,
 x, y, z,
 r, g, b, a,
 text
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.ftgl_font_add_text3d(font_id, x, y, z, 1.0, 0.0, 0.0, 1.0, "GeeXLab - line1")
gh_utils.ftgl_font_add_text2d(font_id, x+20, y-30, z-30, 1.0, 0.0, 0.0, 1.0, "GeeXLab - line2")
			


ftgl_font_clear

Description

Clears all 2D texts in a font. Useful with dynamic texts


Syntax

gh_utils.ftgl_font_clear(
 font_id
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.ftgl_font_clear(font_id)

gh_utils.ftgl_font_add_text2d(font_id, 10, 20, 1.0, 0.0, 0.0, 1.0, string.format("Elapsed time: %.3f sec.", elapsed_time))

gh_utils.ftgl_font_render(font_id)
			


ftgl_font_create

Description

Creates a font object from a font texture.


Syntax

font_id = gh_utils.ftgl_font_create(
 font_tex_id
)

Languages


Parameters


Return Values


Code sample


font_id = gh_utils.ftgl_font_create(font_tex_id)
			


ftgl_font_kill

Description

Kills a font (TERMINATE script).


Syntax

gh_utils.ftgl_font_kill(
 font_id
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.ftgl_font_kill(font_id)
			


ftgl_font_render

Description

Renders a 2D font.


Syntax

gh_utils.ftgl_font_render(
 font_id
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.ftgl_font_clear(font_id)

gh_utils.ftgl_font_add_text2d(font_id, 10, 20, 1.0, 0.0, 0.0, 1.0, string.format("Elapsed time: %.3f sec.", elapsed_time))

gh_utils.ftgl_font_render(font_id)
			


ftgl_font_texture_kill

Description

Kills a font texture (TERMINATE script).


Syntax

gh_utils.ftgl_font_texture_kill(
 font_tex_id
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.ftgl_font_texture_kill(font_tex_id)
			


ftgl_font_texture_load

Description

Loads a font texture from a TrueType (TTF) font file.


Syntax

font_tex_id = gh_utils.ftgl_font_texture_load(
 filename,
 height,
 tex_width, tex_height,
 _5, _6
)

Languages


Parameters


Return Values


Code sample


font_tex_id = gh_utils.ftgl_font_texture_load(filename, 50, 1024, 1024, 0, 0)
			


get_app_dir

Description

Gets the directory of GeeXLab.


Syntax

dir = gh_utils.get_app_dir()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


app_dir = gh_utils.get_app_dir()
			


get_app_version

Description

Returns the four numbers that define the GeeXLab version.


Syntax

major, minor, patch, build = gh_utils.get_app_version()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


major, minor, patch, build = gh_utils.get_app_version()
			


get_command_line

Description

Returns the command line used to lauch GeeXLab.


Syntax

command_line = gh_utils.get_command_line()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


command_line = gh_utils.get_command_line()
			


get_date_str

Description

Gets the date with the following format: Y.M.D.h.m.s. Handy funtion for naming files.


Syntax

date = gh_utils.get_date_str()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


date = gh_utils.get_date_str()
			


get_demo_dir

Description

Gets the directory of the current scene file.


Syntax

dir = gh_utils.get_demo_dir()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


demo_dir = gh_utils.get_demo_dir()
			


get_demo_zip_filename

Description

Gets the file name of the main zip archive (the zip archive that contains the main XML demo).


Syntax

demo_zip_filename = gh_utils.get_demo_zip_filename()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


main_zip_filename = gh_utils.get_demo_zip_filename()
			


get_elapsed_time

Description

Gets the elapsed time since the start of the current scene.


Syntax

elapsed_time = gh_utils.get_elapsed_time()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


local elapsed_time = gh_utils.get_elapsed_time()
			


get_lib_dir

Description

Gets the directory of GeeXLab common librairies (Lua and Python) used by demos. The defaulkt location is {GeeXLab_folder}/libs/.


Syntax

dir = gh_utils.get_lib_dir()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


lib_dir = gh_utils.get_lib_dir()
			


get_desktop_resolution

Description

Gets the default / native resolution of the desktop. For example, with a fullHD monitor, you should get 1920, 1080.


Syntax

width, height = gh_utils.get_desktop_resolution()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


width, height = gh_utils.get_desktop_resolution()
			


get_os_info

Description

Gets some basic information about the host Operating System (OS).


Syntax

major, minor, build, name, codename = gh_utils.get_os_info()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


name, codename, major, minor, build = gh_utils.get_os_info()
			


get_platform

Description

Returns the platform: 1 (Windows), 2 (macOS), 3 (Linux), 4 (Raspberry Pi), 5 (ASUS Tinker Board)


Syntax

platform = gh_utils.get_platform()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


platform = gh_utils.get_platform()
			


get_platform_name

Description

Returns the platform name: Windows xx-bit, macOS 10.x, Linux xx-bit, Raspberry Pi.


Syntax

platform_name = gh_utils.get_platform_name()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


platform_name = gh_utils.get_platform_name()
			


get_time_step

Description

Returns the time step between two consecutive frames.


Syntax

dt = gh_utils.get_time_step()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


local dt = gh_utils.get_time_step()
			


get_uptime

Description

Gets the up time since the launch of GeeXLab.


Syntax

uptime = gh_utils.get_uptime()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


local uptime = gh_utils.get_uptime()
			


global_array_char_alloc

Description

Allocates a global array of string. This array is readable and writable by any script in any thread.


Syntax

gh_utils.global_array_char_alloc(
 num_elements,
 max_string_len
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


num_elements = 256
max_string_len = 1024

gh_utils.global_array_char_alloc(num_elements, max_string_len)
			


global_array_char_get

Description

Reads a value from the global char array.


Syntax

value = gh_utils.global_array_char_get(
 index
)

Languages


Parameters


Return Values


Code sample


index = 2
value = gh_utils.global_array_char_get(index)
			


global_array_char_set

Description

Writes a value to the global char array.


Syntax

gh_utils.global_array_char_set(
 index,
 value
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


index = 2
value = "Hello"

gh_utils.global_array_char_set(index, value)
			


global_array_float_alloc

Description

Allocates a global array of floats. This array is readable and writable by any script in any thread.


Syntax

gh_utils.global_array_float_alloc(
 num_elements
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


num_elements = 256
gh_utils.global_array_float_alloc(num_elements)
			


global_array_float_get

Description

Reads a value from the global float array.


Syntax

value = gh_utils.global_array_float_get(
 index
)

Languages


Parameters


Return Values


Code sample


index = 2
value = gh_utils.global_array_float_get(index)
			


global_array_float_set

Description

Writes a value to the global float array.


Syntax

gh_utils.global_array_float_set(
 index,
 value
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


index = 2
value = 3.14

gh_utils.global_array_float_set(index, value)
			


global_array_int_alloc

Description

Allocates a global array of integers. This array is readable and writable by any script in any thread.


Syntax

gh_utils.global_array_int_alloc(
 num_elements
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


num_elements = 256
gh_utils.global_array_int_alloc(num_elements)
			


global_array_int_get

Description

Reads a value from the global int array.


Syntax

value = gh_utils.global_array_int_get(
 index
)

Languages


Parameters


Return Values


Code sample


index = 2
value = gh_utils.global_array_int_get(index)
			


global_array_int_set

Description

Writes a value to the global int array.


Syntax

gh_utils.global_array_int_set(
 index,
 value
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


index = 2
value = 10

gh_utils.global_array_int_set(index, value)
			


grid_create

Description

Creates a grid object.


Syntax

grid_id = gh_utils.grid_create()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


grid_id = gh_utils.grid_create()
			


grid_set_display_lines_options

Description

Sets various grid options for rendering.


Syntax

gh_utils.grid_set_display_lines_options(
 grid_id,
 display_main_lines,
 display_lines
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.grid_set_display_lines_options(grid_id, 1, 1)
			


grid_set_geometry_params

Description

Sets grid sizes and subdivisions.


Syntax

gh_utils.grid_set_geometry_params(
 grid_id,
 x_size, z_size,
 x_div, z_div
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.grid_set_geometry_params(grid_id, 20, 20, 10, 10)
			


grid_set_lines_color

Description

Sets grid color.


Syntax

gh_utils.grid_set_lines_color(
 grid_id,
 r, g, b, a
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.grid_set_lines_color(grid_id, 0.7, 0.7, 0.7, 1)
			


grid_set_main_lines_color

Description

Sets the color of main lines.


Syntax

gh_utils.grid_set_main_lines_color(
 grid_id,
 r, g, b, a
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.grid_set_main_lines_color(grid_id, 1.0, 1.0, 0.0, 1)
			


grid_set_main_x_axis_color

Description

Sets the color of the main X axis.


Syntax

gh_utils.grid_set_main_x_axis_color(
 grid_id,
 r, g, b, a
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.grid_set_main_x_axis_color(grid_id, 1.0, 0.0, 0.0, 1)
			


grid_set_main_z_axis_color

Description

Sets the color of the main Z axis.


Syntax

gh_utils.grid_set_main_z_axis_color(
 grid_id,
 r, g, b, a
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.grid_set_main_z_axis_color(grid_id, 0.0, 0.0, 1.0, 1)
			


hex_color_to_rgb

Description

Converts an HTML style color to three RGB components.


Syntax

r, g, b = gh_utils.hex_color_to_rgb(
 html_color
)

Languages


Parameters


Return Values


Code sample


r, g, b = gh_utils.hex_color_to_rgb("#ff0044")
			


is_64bit

Description

Checks if the host application is a 64-bit or a 32-bit application.


Syntax

state = gh_utils.is_64bit()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


app_64bit = gh_utils.is_64bit()
			


is_luajit

Description

Checks if the LuaJIT engine is used in place of the regular Lua engine (Windows only).


Syntax

state = gh_utils.is_luajit()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


is_luajit = gh_utils.is_luajit()
			


is_rpi

Description

Checks if the platform is Raspberry Pi (RPi).


Syntax

state = gh_utils.is_rpi()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


rpi = gh_utils.is_rpi()
			


line_create

Description

Creates a simple line.


Syntax

line_id = gh_utils.line_create()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


line_id = gh_utils.line_create()

gh_utils.line_set_start_position(line_id, -10, -10, 0.0)
gh_utils.line_set_start_color(line_id, 1, 1, 0, 1)
gh_utils.line_set_end_position(line_id, 10, 10, 0.0)
gh_utils.line_set_end_color(line_id, 1, 1, 1, 1)
			


line_set_end_color

Description

Sets the end color of a line.


Syntax

gh_utils.line_set_end_color(
 line_id,
 r, g, b, a
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.line_set_end_color(line_id, 1, 1, 0, 1)
			


line_set_end_position

Description

Sets the end position of a line.


Syntax

gh_utils.line_set_end_position(
 line_id,
 x, y, z
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.line_set_end_position(line_id, 10, 10, 0.0)
			


line_set_start_color

Description

Sets the start color of a line.


Syntax

gh_utils.line_set_start_color(
 line_id,
 r, g, b, a
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.line_set_start_color(line_id, 1, 1, 0, 1)
			


line_set_start_position

Description

Sets the start position of a line.


Syntax

gh_utils.line_set_start_position(
 line_id,
 x, y, z
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.line_set_start_position(line_id, -10, -10, 0.0)
			


math_length_vec3

Description

Gets the length of a vec3 vector.


Syntax

len = gh_utils.math_length_vec3(
 x, y, z
)

Languages


Parameters


Return Values


Code sample


len = gh_utils.math_length_vec3(x, y, z)
			


math_normalize_vec3

Description

Normalizes a vec3 vector.


Syntax

vx, vy, vz = gh_utils.math_normalize_vec3(
 x, y, z
)

Languages


Parameters


Return Values


Code sample


vx, vy, vz = gh_utils.math_normalize_vec3(x, y, z)
			


math_quat_from_lookat

Description

Creates a quaternion from vectors of a look-at matrix (position, target and up).


Syntax

qx, qy, qz, qw = gh_utils.math_quat_from_lookat(
 px, py, pz,
 tx, ty, tz,
 ux, uy, uz
)

Languages


Parameters


Return Values


Code sample


qx, qy, qz, qw = gh_utils.math_quat_from_lookat(px, py, pz,  tx, ty, tz,  ux, uy, uz)
			


math_quat_from_vectors_rotation

Description

Creates a quaternion from two vectors.


Syntax

qx, qy, qz, qw = gh_utils.math_quat_from_vectors_rotation(
 x0, y0, z0,
 x1, y1, z1
)

Languages


Parameters


Return Values


Code sample


qx, qy, qz, qw = gh_utils.math_quat_from_vectors_rotation(x0, y0, z0, x1, y1, z1)
			


math_quat_from_euler_angles

Description

Creates a quaternion from Euler's angles.


Syntax

qx, qy, qz, qw = gh_utils.math_quat_from_euler_angles(
 pitch, yaw, roll
)

Languages


Parameters


Return Values


Code sample


qx, qy, qz, qw = gh_utils.math_quat_from_euler_angles(pitch, yaw, roll)
			


nfd_open_dialog

Description

NativeFileDialog - opens a dialog box for opening a file. Works on Windows, Linux (GTK3+) and Raspberry Pi (Raspibian with GTK3+). Does not work on macOS because macOS UI functions must be called from application main thread only (sucks!).


Syntax

filename, ret = gh_utils.nfd_open_dialog(
 filters_list,
 default_path
)

Languages


Parameters


Return Values


Code sample


filename, ret = gh_utils.nfd_open_dialog("jgp,png", "")
			


nfd_pick_folder

Description

NativeFileDialog - opens a dialog box for selecting a folder. Works on Windows, Linux (GTK3+) and Raspberry Pi (Raspibian with GTK3+). Does not work on macOS because macOS UI functions must be called from application main thread only (sucks!).


Syntax

folder, ret = gh_utils.nfd_pick_folder(
 default_path
)

Languages


Parameters


Return Values


Code sample


filename, ret = gh_utils.nfd_pick_folder("")
			


nfd_save_dialog

Description

NativeFileDialog - opens a dialog box for saving a file. Works on Windows, Linux (GTK3+) and Raspberry Pi (Raspibian with GTK3+). Does not work on macOS because macOS UI functions must be called from application main thread only (sucks!).


Syntax

filename, ret = gh_utils.nfd_save_dialog(
 filters_list,
 default_path
)

Languages


Parameters


Return Values


Code sample


filename, ret = gh_utils.nfd_save_dialog("jgp,png", "")
			


open_url

Description

Open an URL in the default browser.


Syntax

gh_utils.open_url(
 str
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.open_url("https://geeks3d.com")
			


printc

Description

(zzz) Helper function to print text directly in the console.


Syntax

gh_utils.printc(
 text
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.printc(text)
			


progress_bar_inc

Description

Increments the progress bar size in percent of the current window width. This functions can be used in an INIT script to draw a progress bar while loading data. To enable the progress bar, the display_progress_bar=1 attribute must be used in the window XML node.


Syntax

gh_utils.progress_bar_inc(
 percent_inc,
 caption
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.progress_bar_set(20, "Initializing...")

...
... do some stuff
...

for i=1, 50 do
    ...
    gh_utils.progress_bar_inc(1)
end

...
... do some stuff
...

gh_utils.progress_bar_set(100, "Initialization complete.")
			


progress_bar_set

Description

Sets the progress bar size in percent of the current window width. This functions can be used in an INIT script to draw a progress bar while loading data. To enable the progress bar, the display_progress_bar=1 attribute must be used in the window XML node.


Syntax

gh_utils.progress_bar_set(
 percent,
 caption
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.progress_bar_set(20, "Initializing...")

...
... do some stuff
...

gh_utils.progress_bar_set(50, "Still initializing...")

...
... do some stuff
...

gh_utils.progress_bar_set(100, "Initialization complete.")
			


project_3d_to_2d_v1

Description

Projects a 3D point into the 2D screen space. Useful to know if a vertex is under the mouse for example.


Syntax

px, py = gh_utils.project_3d_to_2d_v1(
 cam_id,
 obj_id,
 x, y, z, w
)

Languages


Parameters


Return Values


Code sample


px, py = gh_utils.project_3d_to_2d_v1(cam_id, obj_id, x, y, z, 1.0)
			


project_3d_to_2d_v2

Description

Projects a 3D point into the 2D screen space. Useful to know if a vertex is under the mouse for example.


Syntax

px, py = gh_utils.project_3d_to_2d_v2(
 cam_id,
 x, y, z, w
)

Languages


Parameters


Return Values


Code sample


px, py = gh_utils.project_3d_to_2d_v2(cam_id, x, y, z, 1.0)
			


random

Description

Returns a random floating point number between 0.0 and 1.0.


Syntax

x = gh_utils.random()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


local x = gh_utils.random()
local y = gh_utils.random()
local z = gh_utils.random()
			


srandom

Description

Initializes the random number generator (random, random16 and random32).


Syntax

gh_utils.srandom(
 seed
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


local seed = 1234321
gh_utils.srandom(seed)
			


random16

Description

Returns a random floating point number between 0.0 and 1.0. random16() tries to mimic original C rand() function available on Windows / Visual Studio.


Syntax

x = gh_utils.random16(
 a, b
)

Languages


Parameters


Return Values


Code sample


a = 0
b = 2.0
local x = gh_utils.random16(a, b)
			


random32

Description

Returns a random floating point number between 0.0 and 1.0. random32() tries to mimic original C rand() function available in the GLIBC on Linux / gcc.


Syntax

x = gh_utils.random32(
 a, b
)

Languages


Parameters


Return Values


Code sample


a = 0
b = 2.0
local x = gh_utils.random32(a, b)
			


raycast_cast_ray

Description

Casts a ray in the 3D scene and returns collision information (with a mesh).


Syntax

coll_pos_x, coll_pos_y, coll_pos_z, coll_time, face_index = gh_utils.raycast_cast_ray(
 mesh_id,
 ro_x, ro_y, ro_z, rd_x, rd_y, rd_z
)

Languages


Parameters


Return Values


Code sample


face_index, coll_time, coll_pos_x, coll_pos_y, coll_pos_z = gh_utils.raycast_cast_ray(mesh_id, ro_x, ro_y, ro_z, rd_x, rd_y, rd_z)
			


raycast_cast_ray_v2

Description

Casts a ray in the 3D scene and returns collision information (with a mesh).


Syntax

coll_pos_x, coll_pos_y, coll_pos_z, coll_time, face_index = gh_utils.raycast_cast_ray_v2(
 mesh_id,
 ro_x, ro_y, ro_z, rd_x, rd_y, rd_z,
 do_bounding_volume_test
)

Languages


Parameters


Return Values


Code sample


do_bounding_volume_test = 1

face_index, coll_time, coll_pos_x, coll_pos_y, coll_pos_z = gh_utils.raycast_cast_ray_v2(mesh_id, ro_x, ro_y, ro_z, rd_x, rd_y, rd_z, do_bounding_volume_test)
			


raycast_get_ray

Description

Gets a 3D ray from a screen position (mouse for example) for a perspective camera.


Syntax

ro_x, ro_y, ro_z, rd_x, rd_y, rd_z = gh_utils.raycast_get_ray(
 screen_x, screen_y,
 cam_id
)

Languages


Parameters


Return Values


Code sample


ro_x, ro_y, ro_z, rd_x, rd_y, rd_z = gh_utils.raycast_get_ray(200, 100, cam_id)
			


raycast_get_ray_ortho_cam

Description

Gets a 3D ray from a screen position (mouse for example) for an orthographic camera.


Syntax

ro_x, ro_y, ro_z, rd_x, rd_y, rd_z = gh_utils.raycast_get_ray_ortho_cam(
 screen_x, screen_y,
 cam_id
)

Languages


Parameters


Return Values


Code sample


ro_x, ro_y, ro_z, rd_x, rd_y, rd_z = gh_utils.raycast_get_ray_ortho_cam(100, 200, cam_id)
			


sanitize_string

Description

Sanitize a string.


Syntax

gh_utils.sanitize_string(
 text,
 filter_type
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


sanitized_text = gh_utils.sanitize_string(text, 0)
			


shared_variable_create

Description

Creates a named shared variables. Shared variables allow to pass values between two windows or between Lua and Python scripts.


Syntax

sv_id = gh_utils.shared_variable_create(
 name
)

Languages


Parameters


Return Values


Code sample


sv_name = "sv1"
sv_id = gh_utils.shared_variable_create(sv_name)
			


shared_variable_create_array

Description

Creates a shared variable that holds an array of elements of same type.


Syntax

sv_id = gh_utils.shared_variable_create_array(
 sv_name,
 sv_type,
 num_elements
)

Languages


Parameters


Return Values


Code sample


num_textures = 16
sv_id = gh_utils.shared_variable_create_array("texture_ids", "integer", num_textures)
			


shared_variable_get_array_value_1f

Description

Gets the value of a particular element of an array.


Syntax

elem_value = gh_utils.shared_variable_get_array_value_1f(
 sv_name,
 elem_index
)

Languages


Parameters


Return Values


Code sample


elem_value = gh_utils.shared_variable_get_array_value_1f("texture_ids", 0)
			


shared_variable_get_array_value_1i

Description

Gets the value of a particular element of an array.


Syntax

elem_value = gh_utils.shared_variable_get_array_value_1i(
 sv_name,
 elem_index
)

Languages


Parameters


Return Values


Code sample


elem_value = gh_utils.shared_variable_get_array_value_1i("texture_ids", 0)
			


shared_variable_get_array_value_str

Description

Gets the value of a particular element of an array.


Syntax

elem_value = gh_utils.shared_variable_get_array_value_str(
 sv_name,
 elem_index
)

Languages


Parameters


Return Values


Code sample


elem_value = gh_utils.shared_variable_get_array_value_str("texture_ids", 0)
			


shared_variable_get_value_4f

Description

Gets a 4D value.


Syntax

x, y, z, w = gh_utils.shared_variable_get_value_4f(
 sv_name
)

Languages


Parameters


Return Values


Code sample


x, y, z, w = gh_utils.shared_variable_get_value_4f(sv_name)
			


shared_variable_get_value_str

Description

Gets a string value.


Syntax

str = gh_utils.shared_variable_get_value_str(
 sv_name
)

Languages


Parameters


Return Values


Code sample


str = gh_utils.shared_variable_get_value_str(sv_name)
			


shared_variable_is_exist

Description

Checks if a shared variable exists.


Syntax

is_exist = gh_utils.shared_variable_is_exist(
 sv_name
)

Languages


Parameters


Return Values


Code sample


state = gh_utils.shared_variable_is_exist(sv_name)
			


shared_variable_kill

Description

Destroys a shared variable.


Syntax

gh_utils.shared_variable_kill(
 sv_name
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.shared_variable_kill(sv1_name)
			


shared_variable_set_array_value_1f

Description

Sets the value of a particular element of an array.


Syntax

gh_utils.shared_variable_set_array_value_1f(
 sv_name,
 elem_index,
 elem_value
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.shared_variable_set_array_value_1f("texture_ids", 0, 16.0)
			


shared_variable_set_array_value_1i

Description

Sets the value of a particular element of an array.


Syntax

gh_utils.shared_variable_set_array_value_1i(
 sv_name,
 elem_index,
 elem_value
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.shared_variable_set_array_value_1i("texture_ids", 0, 2)
			


shared_variable_set_array_value_str

Description

Sets the value of a particular element of an array.


Syntax

gh_utils.shared_variable_set_array_value_str(
 sv_name,
 elem_index,
 elem_value
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.shared_variable_set_array_value_str("texture_ids", 0, "abcd")
			


shared_variable_set_value_4f

Description

Sets a 4D value.


Syntax

gh_utils.shared_variable_set_value_4f(
 sv_name,
 x, y, z, w
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.shared_variable_set_value_4f(sv_name, 0.2, 0.3, 0.4, 1.0)
			


shared_variable_set_value_str

Description

Sets a string value.


Syntax

gh_utils.shared_variable_set_value_str(
 sv_name,
 str
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.shared_variable_set_value_str(sv_name, str)
			


sphere_create

Description

Creates a simple sphere made up of several circles.


Syntax

sphere_id = gh_utils.sphere_create(
 radius,
 subdivisions,
 r, g, b, a
)

Languages


Parameters


Return Values


Code sample


sphere_id = gh_utils.sphere_create(10.0, 20, 1.0, 1.0, 0.0, 1.0)
			


sphere_update_radius

Description

Updates the radius of a sphere.


Syntax

gh_utils.sphere_update_radius(
 sphere_id,
 radius
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.sphere_update_radius(sphere_id, 12.0)
			


stop_demo

Description

Stops a demo and quits GeeXLab.


Syntax

gh_utils.stop_demo()

Languages


Parameters

This function has no input parameter(s).


Return Values

This function has no return value(s).


Code sample


gh_utils.stop_demo()
			


sys_exec

Description

Executes a system command.


Syntax

gh_utils.sys_exec(
 command,
 parameters,
 exe_dir
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


local demo_dir = gh_utils.getdemo_dir()

gh_utils.sys_exec("ffmpeg", "-i input.mp4 output.avi", demo_dir)
			


thread_sleep

Description

Allows to pause the current thread.


Syntax

gh_utils.thread_sleep(
 delay
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.thread_sleep(2000)
			


thread_lock_create

Description

Creates a thread lock (critical section / mutex). A thread lock object can be useful in threaded scripts (ZOMBIE scripts that have been launched with exe_script()).


Syntax

index = gh_utils.thread_lock_create()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


tl1 = gh_utils.thread_lock_create()
			


thread_lock_kill_all

Description

Kills all thread locks that have been created with thread_lock_create().


Syntax

gh_utils.thread_lock_kill_all()

Languages


Parameters

This function has no input parameter(s).


Return Values

This function has no return value(s).


Code sample


gh_utils.thread_lock_kill_all()
			


thread_lock_acquire

Description

Acquires the thread lock.


Syntax

gh_utils.thread_lock_acquire(
 index
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.thread_lock_acquire(tl)
...
gh_utils.thread_lock_release(tl)
			


thread_lock_release

Description

Releases the thread lock.


Syntax

gh_utils.thread_lock_release(
 index
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.thread_lock_acquire(tl)
...
gh_utils.thread_lock_release(tl)
			


trace

Description

Writes a trace in the log file and in the debug window.


Syntax

gh_utils.trace(
 str
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.trace("Hello world!")
			


trackball_get_orientation

Description

Returns the rotation quaternion of the trackball.


Syntax

x, y, z, w = gh_utils.trackball_get_orientation(
 x, y,
 prev_x, prev_y
)

Languages


Parameters


Return Values


Code sample


x, y, z, w = gh_utils.trackball_get_orientation(x, y, prev_x, prev_y)
			


trackball_init

Description

Inits the trackball engine. The trackball allows to naturally rotate an object as we rotate a sphere.


Syntax

gh_utils.trackball_init(
 radius,
 x, y
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.trackball_init(radius, w, h)
			


tripod_visualizer_camera_render

Description

Draws in a viewport the tripod of a camera. Useful to visualize the current orientation of the camera.


Syntax

gh_utils.tripod_visualizer_camera_render(
 cam_id,
 x_offset, y_offset, width, height
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.tripod_visualizer_camera_render(cam_id, 0, 0, 100, 100)
			


vendor_name_from_vendor_id

Description

Gets the vendor name from its vendor ID.


Syntax

date = gh_utils.vendor_name_from_vendor_id(
 vendorID
)

Languages


Parameters


Return Values


Code sample


name = gh_utils.vendor_name_from_vendor_id(4318)

if (name == "NVIDIA") then
    -- do something
end
			


webcam_create

Description

Creates a new webcam object. A max of 8 webcams can be created (Windows only).


Syntax

webcam_id = gh_utils.webcam_create()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


webcam_id = gh_utils.webcam_create()
			


webcam_get_frame_size

Description

Gets the size of a frame (Windows only).


Syntax

width, height = gh_utils.webcam_get_frame_size(
 webcam_id
)

Languages


Parameters


Return Values


Code sample


w, h = gh_utils.webcam_get_frame_size(webcam_id)
			


webcam_get_name

Description

Gets the webcam name, for example: 'Microsoft LifeCam Studio' (Windows only).


Syntax

gh_utils.webcam_get_name(
 webcam_id
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


name = gh_utils.webcam_get_name(webcam_id)
			


webcam_get_num

Description

Returns the number of webcams detected by GeeXLab (Windows only).


Syntax

num_webcams = gh_utils.webcam_get_num()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


num_webcam = gh_utils.webcam_get_num()
			


webcam_grab_frame

Description

Updates the webcam (Windows only).


Syntax

gh_utils.webcam_grab_frame(
 webcam_id
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.webcam_grab_frame(webcam_id)
			


webcam_kill

Description

Kills a webcam object (Windows only).


Syntax

gh_utils.webcam_kill(
 webcam_id
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.webcam_kill(webcam_id)
			


webcam_start

Description

Initializes a webcam (Windows only).


Syntax

ret = gh_utils.webcam_start(
 webcam_id,
 webcam_number
)

Languages


Parameters


Return Values


Code sample


ret = gh_utils.webcam_start(webcam_id, 1)

if (ret == 1) then
    -- Webcam started ok.
end
			


webcam_stop

Description

Stops a webcam (Windows only).


Syntax

gh_utils.webcam_stop(
 webcam_id
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.webcam_stop(webcam_id)
			


webcam_update_texture

Description

Updates a texture pixmap with the current webcam frame (Windows only).


Syntax

gh_utils.webcam_update_texture(
 webcam_id,
 tex_id
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.webcam_update_texture(webcam_id, tex_id)
			


zip_buffer_create

Description

Allocates a memory buffer of a file stored in a zip archive and returns the pointer to the memory buffer.


Syntax

buff_ptr, buff_size = gh_utils.zip_buffer_create(
 zip_filename,
 filename
)

Languages


Parameters


Return Values


Code sample


zip_filename = gh_utils.get_demo_dir() .. "demo.zip"
filename = "config.txt"

buffer_ptr, buffer_size = gh_utils.zip_buffer_create(zip_filename, filename)
...
gh_utils.buffer_kill(buffer_ptr)
			


zip_to_file

Description

Extracts a file from a zip and save it on the file system.


Syntax

ret = gh_utils.zip_to_file(
 zip_filename,
 src_filename,
 dst_filename
)

Languages


Parameters


Return Values


Code sample


zip_filename = gh_utils.get_demo_dir() .. "demo.zip"
src_filename = "assets/image01.jpg"
dst_filename = gh_utils.get_demo_dir() .. "image01.jpg"

if (gh_utils.file_size(zip_filename, src_filename, dst_filename) == 1) then
    -- OK!
end
			


win_registry_read_value_dword

Description

Read an integer (REG_DWORD) value from Windows registry (Windows only). WARNING: serious problems might occur if you modify the registry incorrectly.


Syntax

ret, x = gh_utils.win_registry_read_value_dword(
 key_name,
 subkey_name,
 value_name
)

Languages


Parameters


Return Values


Code sample


key_name = "HKEY_LOCAL_MACHINE"			
subkey_name = "HARDWARE\\DESCRIPTION\\System\\BIOS"
value_name = "BiosMajorRelease"
ret, x = gh_utils.win_registry_read_value_dword(key_name, subkey_name, value_name)
			


win_registry_write_value_dword

Description

Write an integer (REG_DWORD) value into Windows registry (Windows only). WARNING: serious problems might occur if you modify the registry incorrectly.


Syntax

ret = gh_utils.win_registry_write_value_dword(
 key_name,
 subkey_name,
 value_name,
 x
)

Languages


Parameters


Return Values


Code sample


key_name = "HKEY_LOCAL_MACHINE"			
subkey_name = "HARDWARE\\DESCRIPTION\\System\\BIOS"
value_name = "BiosMajorRelease"
ret = gh_utils.win_registry_write_value_dword(key_name, subkey_name, value_name, 5)
			


win_registry_read_value_string

Description

Read a string (REG_SZ) value from Windows registry (Windows only). WARNING: serious problems might occur if you modify the registry incorrectly.


Syntax

ret, str = gh_utils.win_registry_read_value_string(
 key_name,
 subkey_name,
 value_name
)

Languages


Parameters


Return Values


Code sample


key_name = "HKEY_LOCAL_MACHINE"			
subkey_name = "HARDWARE\\DESCRIPTION\\System\\BIOS"
value_name = "BIOSVendor"
ret, str = gh_utils.win_registry_read_value_string(key_name, subkey_name, value_name)
			


win_registry_write_value_string

Description

Write a string (REG_SZ) value into Windows registry (Windows only). WARNING: serious problems might occur if you modify the registry incorrectly.


Syntax

ret = gh_utils.win_registry_write_value_string(
 key_name,
 subkey_name,
 value_name,
 str
)

Languages


Parameters


Return Values


Code sample


key_name = "HKEY_LOCAL_MACHINE"			
subkey_name = "HARDWARE\\DESCRIPTION\\System\\BIOS"
value_name = "BIOSVendor"
ret = gh_utils.win_registry_write_value_string(key_name, subkey_name, value_name, "American Megatrends Inc.")
			


win_registry_create_key

Description

Create a subkey in Windows registry (Windows only). WARNING: serious problems might occur if you modify the registry incorrectly.


Syntax

ret = gh_utils.win_registry_create_key(
 key_name,
 subkey_name,
 options
)

Languages


Parameters


Return Values


Code sample


key_name = "HKEY_CURRENT_USER"			
subkey_name = "Software\\MyKoolUtility"
options = ""
ret = gh_utils.win_registry_create_key(key_name, subkey_name, options)
			


win_registry_delete_key

Description

Delete a subkey from Windows registry (Windows only). WARNING: serious problems might occur if you modify the registry incorrectly.


Syntax

ret = gh_utils.win_registry_delete_key(
 key_name,
 subkey_name
)

Languages


Parameters


Return Values


Code sample


key_name = "HKEY_CURRENT_USER"			
subkey_name = "Software\\MyKoolUtility"
ret = gh_utils.win_registry_delete_key(key_name, subkey_name)
			


pack_rgba_u8

Description

Pack four R, G, B and A channels into a single integer.


Syntax

rgba = gh_utils.pack_rgba_u8(
 r, g, b, a
)

Languages


Parameters


Return Values


Code sample


color = gh_utils.pack_rgba_u8(r, g, b, a)
			


unpack_rgba_u8

Description

Unpack a single integer inti four R, G, B and A channels.


Syntax

r, g, b, a = gh_utils.unpack_rgba_u8(
 rgba
)

Languages


Parameters


Return Values


Code sample


r, g, b, a = gh_utils.unpack_rgba_u8(color)
			


set_new_scene_data

Description

Stops and kills the current demo and launch a new demo.


Syntax

gh_utils.set_new_scene_data(
 filename,
 width, height,
 fullscreen,
 msaa
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.set_new_scene_data(filename, -1, -1, 0, "Off")
			


temp_directory_path

Description

Returns the path of user's temp folder - Windows only.


Syntax

temp_folder = gh_utils.temp_directory_path()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


temp_folder = gh_utils.temp_directory_path()
			


get_app_name

Description

Returns the name of the host application (here GeeXLab). GeeXLab scripts can be executed by another host app that embeds the GeeXLab SDK (like GPU Caps Viewer) and get_app_name() can return a name that is not GeeXLab.


Syntax

name = gh_utils.get_app_name()

Languages


Parameters

This function has no input parameter(s).


Return Values


Code sample


app_name = gh_utils.get_app_name()
			


spirv_to_smolv

Description

Converts a SPIR-V file to a SMOL-V file (compressed version of the SPIR-V file).


Syntax

ret = gh_utils.spirv_to_smolv(
 spirv_filename,
 smolv_filename,
 flags
)

Languages


Parameters


Return Values


Code sample


local kEncodeFlagStripDebugInfo = 1
local flags = kEncodeFlagStripDebugInfo			
ret = gh_utils.spirv_to_smolv(spirv_filename, smolv_filename, flags)
			


smolv_to_spirv

Description

Converts a SPIR-V file to a SMOL-V file (compressed version of the SPIR-V file).


Syntax

ret = gh_utils.smolv_to_spirv(
 smolv_filename,
 spirv_filename
)

Languages


Parameters


Return Values


Code sample


ret = gh_utils.smolv_to_spirv(smolv_filename, spirv_filename)
			


math_from_to_rotation_matrix3x3

Description

Creates a 3x3 rotation matrix from two vectors.


Syntax

m0,m1,m2,m3,m4,m5,m6,m7,m8 = gh_utils.math_from_to_rotation_matrix3x3(
 from_x, from_y, from_z,
 to_x, to_y, to_z
)

Languages


Parameters


Return Values


Code sample


m0,m1,m2,m3,m4,m5,m6,m7,m8 = gh_utils.math_from_to_rotation_matrix3x3(from_x, from_y, from_z, to_x, to_y, to_z)
			


file_read

Description

Returns the content of a file.


Syntax

data, data_size = gh_utils.file_read(
 zip_filename,
 filename
)

Languages


Parameters


Return Values


Code sample


data, data_size = gh_utils.file_read(zip_filename, filename)
			


file_write

Description

Writes data to a file.


Syntax

ret = gh_utils.file_write(
 filename,
 data
)

Languages


Parameters


Return Values


Code sample


ret = gh_utils.file_write(filename, data)
			


file_size

Description

Returns the size in bytes of a file.


Syntax

size = gh_utils.file_size(
 zip_filename,
 filename
)

Languages


Parameters


Return Values


Code sample


size = gh_utils.file_size(zip_filename, filename)
			


shmem_create

Description

Creates a shared memory. Shared memory is a memory that can be accessed by different processes or applications on the same machine.


Syntax

ret = gh_utils.shmem_create(
 shmem_name,
 shmem_size
)

Languages


Parameters


Return Values


Code sample


ret = gh_utils.shmem_create(shmem_name, shmem_size)
			


shmem_kill

Description

Destroys a shared memory.


Syntax

gh_utils.shmem_kill(
 shmem_name
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


gh_utils.shmem_kill(shmem_name)
			


shmem_is_available

Description

Checks if a shared memory is available.


Syntax

ret = gh_utils.shmem_is_available(
 shmem_name,
 shmem_size
)

Languages


Parameters


Return Values


Code sample


ret = gh_utils.shmem_is_available(shmem_name, shmem_size)
			


shmem_map

Description

Maps a shared memory. The pointer returned by this function can be used with memory buffer functions like gh_utils.buffer_read_u32().


Syntax

buffer_ptr = gh_utils.shmem_map(
 shmem_name,
 shmem_size
)

Languages


Parameters


Return Values


Code sample


buffer = gh_utils.shmem_map(shmem_name, shmem_size)
gh_utils.buffer_write_byte(buffer, index, 255)
gh_utils.shmem_unmap(shmem_name)
			


shmem_unmap

Description

Unmaps a shared memory. The pointer returned by shmem_map() is no longer valid after a call to shmem_unmap().


Syntax

gh_utils.shmem_unmap(
 shmem_name
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


buffer = gh_utils.shmem_map(shmem_name, shmem_size)
gh_utils.buffer_write_byte(buffer, index, 255)
gh_utils.shmem_unmap(shmem_name)
			


win32_audio_volume_control

Description

Sends commands to control the audio volume on Windows platform.


Syntax

gh_utils.win32_audio_volume_control(
 command
)

Languages


Parameters


Return Values

This function has no return value(s).


Code sample


local command0 = "mute"			
local command1 = "up"			
local command2 = "down"			
gh_utils.win32_audio_volume_control(command1)
			


qr_code_scan

Description

Scans a QR Code stored in a texture and return the payload information.


Syntax

payload, payload_len, corner0, corner1, corner2, ... corner7 = gh_utils.qr_code_scan(
 texture_id,
 bthreshold
)

Languages


Parameters


Return Values


Code sample


corners = {}			
local color_threshold = 50
payload, payload_size, corners[1], corners[2], corners[3], corners[4], corners[5], corners[6], corners[7], corners[8] = gh_utils.qr_code_scan(tex01, color_threshold)
			


qr_code_gen

Description

Generates a QR Code with a specific payload. The QR code is stored in a texture.


Syntax

texture_id = gh_utils.qr_code_gen(
 payload,
 err_correction_level
)

Languages


Parameters


Return Values


Code sample


ECC_LOW = 0
ECC_MEDIUM = 1
ECC_QUARTILE = 2
ECC_HIGH = 3
err_correction_level = ECC_LOW
tex0 = gh_utils.qr_code_gen(payload, err_correction_level)
			






GeeXLab Rootard Guide | Downloads | Contact | Newsletter