Quick Links
- Homepage
- Downloads
- Code Sample Pack
- Gallery
- Forum

Documentation
- Overview
- GLSL Programs
- Live Coding
- Hack your first
  GLSL program

- Reference guide

Follow GLSL Hacker

GLSL Hacker @ Twitter

GLSL Hacker

Reference Guide
Host-API Lua / Python



» Back to Homepage
» Back to Developer's Guide Index

gh_utils Library


Description
gh_utils is the module that provides various utility functions.

Number of functions: 22

gh_utils.renderer_getptr

Description
Gets the pointer to the renderer.

Languages: Lua - Python

Parameters
  • ID [INTEGER]: identifier of the current scene (core3d).

    Return Values
  • R_ptr [POINTER]: pointer to the underlying renderer.

    Code sample :

    R_ptr = gh_utils.renderer_getptr()


    gh_utils.render_window_getptr

    Description
    Gets the pointer to the render window. The render window is the object that makes the link between the renderer and the host application. In short, the renderer draw in the render window.

    Languages: Lua - Python

    Parameters
  • ID [INTEGER]: identifier of the current scene (core3d).

    Return Values
  • rw_ptr [POINTER]: pointer to the underlying render window.

    Code sample :

    R_ptr = gh_utils.renderer_getptr()
    rw_ptr = gh_utils.render_window_getptr()


    gh_utils.exe_script

    Description
    Executes a script.

    Languages: Lua - Python

    Parameters
  • name [STRING]: Name of the script.
  • threaded [INTEGER]: Runs (1) the script in a separate system thread or not (0).

    Code sample :

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


    gh_utils.get_elapsed_time

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

    Languages: Lua - Python

    Return Values
  • elapsed_time [REAL]: elapsed time in seconds.

    Code sample :

    elapsed_time = gh_utils.get_elapsed_time()


    gh_utils.trace

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

    Languages: Lua - Python

    Parameters
  • str [STRING]: Trace to write.

    Code sample :

    gh_utils.trace("Hello world!")


    gh_utils.font_getptr

    Description
    Returns the pointer to a font node.

    Languages: Lua - Python

    Parameters
  • ID [INTEGER]: identifier of the current scene (core3d).
  • font [INTEGER]: font identifier.

    Return Values
  • font_ptr [POINTER]: Pointer on the font node.

    Code sample :

    font_ptr = gh_utils.font_getptr(ID, font)


    gh_utils.font_create

    Description
    Creates a new font.

    Languages: Lua - Python

    Parameters
  • font_name [STRING]: True type font name, ex: Arial, Verdana.
  • height [INTEGER]: font height.

    Return Values
  • font [INTEGER]: font identifier.

    Code sample :

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


    gh_utils.font_set_viewport_info

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

    Languages: Lua - Python

    Parameters
  • font [INTEGER]: font identifier.
  • x, y [INTEGER]: viewport offsets.
  • width, height [INTEGER]: viewport size.

    Code sample :

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


    gh_utils.font_set_viewport_info_ptr

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

    Languages: Lua - Python

    Parameters
  • font_ptr [POINTER]: pointer on the font node.
  • x, y [INTEGER]: viewport offsets.
  • width, height [INTEGER]: viewport size.

    Code sample :

    gh_utils.font_set_viewport_info_ptr(font_ptr, 0, 0, width, height)


    gh_utils.font_render

    Description
    Renders (draws) a text.

    Languages: Lua - Python

    Parameters
  • font [INTEGER]: font identifier.
  • x, y [INTEGER]: X and Y start offsets in the current viewport.
  • r, g, b, a [REAL]: RGBA color of the text.
  • text [STRING]: text to render.

    Code sample :

    gh_utils.font_set_viewport_info(font, 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))


    gh_utils.font_render_ptr

    Description
    Renders (draws) a text.

    Languages: Lua - Python

    Parameters
  • R_ptr [POINTER]: pointer on the renderer.
  • rw_ptr [POINTER]: pointer on the render window.
  • font_ptr [POINTER]: pointer on the font node.
  • x, y [INTEGER]: X and Y start offsets in the current viewport.
  • r, g, b, a [REAL]: RGBA color of the text.
  • text [STRING]: text to render.

    Code sample :

    gh_utils.font_set_viewport_info_ptr(font_ptr, 0, 0, width, height)
    gh_utils.font_render_ptr(R_ptr, rw_ptr, font_ptr, 10, 40, 0.2, 1.0, 0.0, 1.0, string.format("Image filename: %s", texture_filename))


    gh_utils.font_render3d

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

    Languages: Lua - Python

    Parameters
  • font [INTEGER]: font identifier.
  • x, y, z [REAL]: 3D position of the beginning of the text.
  • r, g, b, a [REAL]: RGBA color of the text.
  • text [STRING]: text to render.

    Code sample :

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


    gh_utils.font_render3d_ptr

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

    Languages: Lua - Python

    Parameters
  • R_ptr [POINTER]: pointer on the renderer.
  • font_ptr [POINTER]: pointer on the font node.
  • x, y, z [REAL]: 3D position of the beginning of the text.
  • r, g, b, a [REAL]: RGBA color of the text.
  • text [STRING]: text to render.

    Code sample :

    gh_utils.font_render3d_ptr(R_ptr, font_ptr, 0, 20.0, -20.0, 0.2, 1.0, 0.0, 1.0, "V1")


    gh_utils.thread_sleep

    Description
    Allows to pause the current thread.

    Languages: Lua - Python

    Parameters
  • delay [INTEGER]: pause delay in milliseconds.

    Code sample :

    gh_utils.thread_sleep(2000)


    gh_utils.get_scenegraph_dir

    Description
    Gets the directory of the current scene file.

    Languages: Lua - Python

    Return Values
  • dir [STRING]: directory of the current scene file.

    Code sample :

    demo_dir = gh_utils.get_scenegraph_dir()


    gh_utils.is_64bit

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

    Languages: Lua - Python

    Return Values
  • state [INTEGER]: 1 for 64-bit and 0 otherwise.

    Code sample :

    app_64bit = gh_utils.is_64bit()


    gh_utils.random

    Description
    Returns a random floating point number between 0.0 and 1.0.

    Languages: Lua - Python

    Return Values
  • x [REAL]: randon number.

    Code sample :

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


    gh_utils.drop_files_get_num_files

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

    Languages: Lua - Python

    Return Values
  • num_files [INTEGER]: number of dropped files

    Code sample :

    num_files = gh_utils.drop_files_get_num_files()


    gh_utils.drop_files_get_file_by_index

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

    Languages: Lua - Python

    Parameters
  • index [INTEGER]: index of the file: from 0 to drop_files_get_num_files()-1.

    Return Values
  • filename [STRING]: name of a dropped file

    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


    gh_utils.set_progress_bar_percent

    Description
    Sets the progress bar size in percent of the current window width. Coupled with gh_renderer.display_progress_bar(), these functions can be used in an INIT script to draw a progress bar while loading data.

    Languages: Lua - Python

    Parameters
  • percent [REAL]: size of the progress bar: 100% means the window width.

    Code sample :

    gh_utils.set_progress_bar_percent(20)
    gh_renderer.display_progress_bar()
    ...
    ... do some stuff
    ...
    gh_utils.set_progress_bar_percent(60)
    gh_renderer.display_progress_bar()
    ...
    ... do some stuff
    ...
    gh_utils.set_progress_bar_percent(100)
    gh_renderer.display_progress_bar()


    gh_utils.set_progress_bar_caption

    Description
    Sets the caption (or title) of the progress bar.

    Languages: Lua - Python

    Parameters
  • caption [STRING]: title of the progress bar.

    Code sample :

    gh_utils.set_progress_bar_caption("Loading scene data...")
    gh_utils.set_progress_bar_percent(20)
    gh_renderer.display_progress_bar()


    gh_utils.do_screenshot

    Description
    Does a screenshot and write it to a file (JPEG file).

    Languages: Lua - Python

    Parameters
  • filename [STRING]: name of the screenshot file.
  • is_absolute_path [INTEGER]: specifies whether the filename is absolute or relative to the main demo XML script.

    Code sample :

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






  • (C)2012 Geeks3D