/
GiD_OpenGL

GiD - The personal pre and post processor

GiD_OpenGL

GiD_OpenGL register | unregister | registercondition | unregistercondition | draw | drawtext | project | unproject | get | doscrzoffset | drawentity | pgffont | gid_draw

This command is a Tcl wrapper of some OpenGL functions. It allows to use OpenGL commands directly from GiD-Tcl.
For example, the C/C++ to draw a line will be like this:

glBegin(GL_LINES); glVertex(x1,y1,z1); glVertex(x2,y2,z2); glEnd();


The GiD-Tcl version is:

GiD_OpenGL draw -begin lines GiD_OpenGL draw -vertex [list $x1 $y1 $z1] GiD_OpenGL draw -vertex [list $x2 $y2 $z2] GiD_OpenGL draw -end


The standard syntax must be changed according to these rules:

  • OpenGL constants: "GL" prefix and underscore character '_' must be removed; the command must be written in lowercase.
    Example: GL_COLOR_MATERIAL → colormaterial

  • OpenGL functions: "GL" prefix must be removed, and substituted by a '-'. Pass parameters as list, without using parentheses ()
    Example:
    glBegin(GL_LINES) → GiD_OpenGL draw -begin lines
    glVertex( x1, x2, x3) → GiD_OpenGL draw -vertex [ list $x1 $x2 $x3]


The subcommand GiD_OpenGL draw provides access to standard OpenGL commands, but other "GiD_OpenGL" special GiD subcommands also exists:

 

register <tclfunc>

Register a Tcl procedure to be invoked automatically when redrawing the scene. It returns a handle to unregister.


Example:

proc MyRedrawProcedure { } { ...body... } set id [GiD_OpenGL register MyRedrawProcedure]

 

unregister <handle>

Unregister a procedure previously registered with register.


Example:

 

registercondition <tclfunc> <condition>

Register a Tcl procedure to be invoked automatically when redrawing the specified condition.

The Tcl funcion must have this prototype:


The supplied parameters are:

  • condition :the condition name, defined in the .cnd file of the problemtype

  • use: GEOMETRYUSE, MESHUSE or POSTUSE

  • entity_id: the integer number that identity the entity where the condition is applied. The kind of entity is known because it is declared in the
    definition of the condition in the .cnd, depending if the current state is geometry or mesh

  • values: a list of the field's values applied to this entity. The amount of values must match the amount of fields of the condition definition.
    The return value of this procedure is important:
    return 0: then the standard representation of the condition is also invoked after the procedure
    return 1: the standard representation of the condition is avoided.

 

unregistercondition <condition>

Unregister a procedure previously registered with registercondition.

 

draw <-cmd args -cmd args>

This is the most important subcommand, it calls standard OpenGL commands. See the list of supported OpenGL functions.

 

drawtext <text> ?–check_non_latin?

Draw a text more easily than using standard OpenGL commands (draw in the current 2D location, see rasterpos OpenGL command).

If -check_non_latin flag is provided, then the text is checked to detect non-latin characters, like a Japanese string, to be drawn properly (otherwise it is considered as a latin string). The flag must be provided only if <text> could potentially be non-latin, like translated strings. In case of numbers for example it is unneeded (more efficient without the extra check)
Example:

 

drawentity ?-mode normal | filled? point | line | surface | volume | node | element | dimension <id list>

To draw an internal GiD preprocess entity.


Example:


For elements it is possible to draw only a face, specifying items of element_id and face_id, with face_id a number from 1 to the number of faces of the element.
Example:

 

project <x y z>

Given three world coordinates, this returns the corresponding three window coordinates.

 

unproject <x y z>

Given three window coordinates, this returns the corresponding three world coordinates.

 

get modelviewmatrix | projectionmatrix | viewport | highresolutionprinting | highresolutionscalefactor

return a list of values:

  • ModelviewMatrix : 16 doubles

  • ProjectionMatrix : 16 doubles

  • viewport : 4 integers

  • HighResolutionPrinting : returns true if registered Tcl procedure is called when a high-resolution capture is being done.

  • HighResolutionScaleFactor : returns the scale factor between the screen and the high resolution capture, used to scale point sizes, line widths, font sizes, etc…

  • LastError : returns the last generated OpenGL error code

  • LastErrorString : returns the error string corresponding to the last generated OpenGL error code

 

doscrzoffset <boolean>

Special trick to avoid the lines on surfaces hidden by the surfaces.

 

pgffont pushfont | popfont | print | dimensions | foreground | background

Command to use GiD fonts on OpenGL ( TrueType and Bitmap).

  • pgffont pushfont <font_type>

    Pushes current font category to stack and selects OpenGL font category to be used from now on.
    font_type are font categories used in GiD, valid values are: 
    defaultfont | axisfont | legendfont | labelfont | graphfont | asianfont | tkdrawoglfont | pmfont
    pmfont is a bitmap font, the other ones are TrueType / FreeType

  • pgffont popfont

Removes current used font category and restores the previous font from stack. Commands push/pop must be called always paired.

  • pgffont print <text>

To draw a <text> in the current 3D location (set by GiD_OpenGL draw -rasterpos [list $x $y $z]). It is similar to GiD_OpenGL drawtext

  • pgffont dimensions <text>

Return the width of <text> and <height> of current font. Sizes in pixels, but result are float, not int as could be expected.

To convert to 3D sizes must be multiplied by a factor, an approximate value of this factor could be calculated like this:

  • pgffont foreground <red> <green> <blue> <alpha>

  • pgffont background <red> <green> <blue> <alpha>

Example:

 

gid_draw <-cmd args>

Some draw <-cmd ards> OpenGL command modified to be used for high resolution printing.
High resolution printing is achieved by doing tile rendering. For instance, If GiD is running using a 3D OpenGL window of 1000 x 1000 pixels, in order to create a 10k by 10k image, GiD renders the 3D model 100 times on this window, but changing the 3D view. To be able to render each piece correctly, instead of using GiD_OpenGL draw -ortho [ list …] the command GiD_OpenGL gid_draw -ortho [ list …] should be used, so that the proper 3D view is set for the Tcl opengl code.

gid_draw subcommands are:

  • gid_draw -ortho [ list left right top bottom ?near far?] : similar to draw -ortho

  • gid_draw -viewport [ list x y width height] : similar to draw -viewport

  • gid_draw -scissor [ list x y width height] : similar to draw -scissor

  • gid_draw -rasterpos [ list x y ?z?] : similar to draw -rasterpos - to position the screen raster position for the next pixel / bitmap usage.

  • gid_draw -linewidth <width> : sets the width of the lines, scaled accordingly for high resolution capture. draw -linewidth does not scale line width for high resolution captures.

  • gid_draw -pointsize <size> : sets the size of the points, scaled accordingly for high resolution captures.


List of supported OpenGL functions:


List of special non OpenGL standard functions:


List of supported OpenGL constants:

 

You can find more information about standard OpenGL functions in a guide to OpenGL.

Related content

GiD_Info view
Read with this
GiD_Process function
GiD_Process function
More like this
view 
Read with this
Python's IDLE shell in GiD
Python's IDLE shell in GiD
More like this
First start
More like this

COPYRIGHT © 2022 · GID · CIMNE