GiD - The personal pre and post processor

OpenGL

GiD_OpenGL register|unregister|registercondition|unregistercondition|draw|drawtext|project|unproject|get|doscrzoffset|drawentity|pgffont
This command is a Tcl wrapper of some OpenGL functions. It allows to use OpenGL commands directly from GiD-Tcl.
For example, for C/C++ is used:

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


For GiD-Tcl must use:


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 the command written in lowercase. Pass parameters as list, without using parentheses ()
Example:
glBegin(GL_LINES) -> glbegin lines
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:

GiD_OpenGL unregister $id


  • registercondition <tclfunc> <condition> Register a Tcl procedure to be invoked automatically when redrawing the specified condition.

The tcl funcion must have this prototype:

proc xxx { condition use entity_id values } {
    ...
    return 1
}


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:

GiD_OpenGL draw -rasterpos [list $x $y $z]
GiD_OpenGL drawtext "hello world"


  • drawentity ?-mode normal|filled? point|line|surface|volume|node|element|dimension <id list> To draw an internal GiD preprocess entity.


Example:

GiD_OpenGL drawentity -mode filled surface {1 5 6}


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:

GiD_OpenGL drawentity -mode filled element {{1 1} {5 1} {6 3}}




  • 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

return a list of values:
modelviewmatrix: 16 doubles
projectionmatrix: 16 doubles
viewport: 4 integers

  • doscrzoffset <boolean> Special trick to avoid the lines on surfaces hidden by the surfaces.
  • pgffont pushfont|popfont|print|dimensions|foreground|background

Command for PG fonts

  • pgffont pushfont <font_type>

    Push sets the current OpenGL font and add to stack.
    font types are categories of GiD, valid values: defaultfont | axisfont | legendfont | labelfont | graphfont | asianfont | tkdrawoglfont| pmfont

  • pgffont popfont

Restores the previous font and remove 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:

proc GetApproximateFactorPixelToWorld { } {
    lassign [GiD_Project view clip_planes_x] left_ortho right_ortho
    lassign [GidUtils::GetMainDrawAreaSize] w h
    set factor [expr double($right_ortho-$left_ortho)/$w]
    return $factor
}
  • pgffont foreground <red> <green> <blue> <alpha>
  • pgffont background <red> <green> <blue> <alpha>

Example:

GiD_OpenGL pgffont push labelfont
GiD_OpenGL drawtext "hello world"
GiD_OpenGL pgffont pop


List of supported OpenGL functions:


accum alphafunc begin bindtexture blendfunc call calllist clear clearaccum clearcolor cleardepth clearstencil clipplane color colormask colormaterial copypixels cullface deletelists deletetextures depthfunc depthmask dfactorBlendTable disable drawbuffer drawpixels edgeflag enable end endlist evalcoord1 evalcoord2 evalmesh1 evalmesh2 finish flush fog frontface frustum genlists gentextures getstring hint hintModeTable initnames light lightmodel linestipple linewidth loadidentity loadmatrix loadname lookat map1 map2 mapgrid1 mapgrid2 material matrixmode modeColorMatTable multmatrix newlist newListTable normal opStencilTable opStencilTable ortho perspective pickmatrix pixeltransfer pixelzoom pointsize polygonmode popattrib popmatrix popname pushattrib pushmatrix pushname rasterpos readbuffer readpixels rect rendermode rotate scale scissor selectbuffer shademodel stencilfunc stencilmask stencilop texcoord texenv texgen teximage1d teximage2d texparameter translate vertex viewport



List of special non OpenGL standard functions:

getselection



List of supported OpenGL constants:

accum accumbuffer accumbufferbit add alphatest always allattrib allattribbits ambient ambientanddiffuse autonormal aux0 aux1 aux2 aux3 back backleft backright blend bluebias bluescale ccw clamp clipplane0 clipplane1 clipplane2 clipplane3 clipplane4 clipplane5 colorbuffer colorbufferbit colorindex colormaterial compile compileandexecute constantattenuation cullface current currentbit cw decal decr depthbuffer depthbufferbit depthtest diffuse dither dstalpha dstcolor enable enablebit emission equal eval evalbit exp exp2 extensions eyelinear eyeplane feedback fill flat fog fogbit fogcolor fogdensity fogend fogmode fogstart front frontandback frontleft frontright gequal greater greenbias greenscale hint hintbit incr invert keep left lequal less light0 light1 light2 light3 light4 light5 light6 light7 lighting lightingbit lightmodelambient lightmodellocalviewer lightmodeltwoside line linebit linear linearattenuation lineloop lines linesmooth linestipple linestrip list listbit load map1color4 map1normal map1texturecoord1 map1texturecoord2 map1texturecoord3 map1texturecoord4 map1vertex3 map1vertex4 map2color4 map2normal map2texturecoord1 map2texturecoord2 map2texturecoord3 map2texturecoord4 map2vertex3 map2vertex4 modelview modulate mult nearest never none normalize notequal objectlinear objectplane one oneminusdstalpha oneminusdstcolor oneminussrcalpha oneminussrccolor packalignment packlsbfirst packrowlength packskippixels packskiprows packswapbytes pixelmode pixelmodebit point pointbit points polygon polygonbit polygonoffsetfill polygonstipple polygonstipplebit position projection q quadraticattenuation quads quadstrip r redbias redscale render renderer repeat replace return right s scissor scissorbit select shininess smooth specular spheremap spotcutoff spotdirecion spotexponent srcalpha srcalphasaturate srccolor stenciltest stencilbuffer stencilbufferbit t texture texture1d texture2d texturebit texturebordercolor textureenv textureenvcolor textureenvmode texturegenmode texturegens texturegent texturemagfilter textureminfilter texturewraps texturewrapt transform transformbit triangles trianglefan trianglestrip unpackalignment unpacklsbfirst unpackrowlength unpackskippixels unpackskiprows unpackswapbytes vendor version viewport viewportbit zero


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

COPYRIGHT © 2022 · GID · CIMNE